platforms.win32¶
Windows platform implementation: system information, command support, registry management, and service management.
Win32PlatformInfo¶
- class Win32PlatformInfo[source]¶
Bases:
objectWindows implementation of PlatformInfo.
Retrieves system information using Windows-specific commands: - PowerShell / wmic for serial numbers - os.getlogin() / environment variables for console user - net user / PowerShell for user full names
- get_serial_number() str | None[source]¶
Get serial number via PowerShell (Get-CimInstance).
Falls back to wmic if PowerShell is unavailable.
- Returns:
Hardware serial number, or None on failure
- Return type:
str | None
- get_console_user() tuple[str, int, Path] | None[source]¶
Get the currently logged-in user on Windows.
Uses os.getlogin() for the username, and Path.home() for the home directory. Windows does not use UIDs in the same way as Unix; we return 0 as a placeholder.
Win32CommandSupport¶
- class Win32CommandSupport[source]¶
Bases:
objectWindows implementation of PlatformCommandSupport.
Uses
runasfor running commands as another user. Note: Windowsrunasprompts for a password interactively, so automated run-as-user is limited. For Intune scripts running as SYSTEM, consider using scheduled tasks or PowerShell remoting.- property min_user_uid: int[source]¶
Minimum UID threshold on Windows.
Windows does not use numeric UIDs like Unix. This returns 0 since UID validation is not applicable on Windows.
- Returns:
0
- Return type:
- run_as_user_command(command: list[str], username: str, uid: int) list[str][source]¶
Wrap command with
runasfor Windows.Note:
runasrequires interactive password input. For non-interactive execution in MDM contexts, consider using PowerShellStart-Process -Credentialor scheduled tasks.
Win32Registry¶
- class Win32Registry[source]¶
Bases:
objectRead, write, and delete Windows registry values.
Wraps the
winregstdlib module for non-raising registry operations. Hive constants are exposed as class attributes for convenience.- Example:
>>> val = Win32Registry.read( ... Win32Registry.HKLM, ... r"SOFTWARE\Microsoft\Windows NT\CurrentVersion", ... "ProductName", ... )
- static read(hive: int, subkey: str, value_name: str) str | int | bytes | None[source]¶
Read a registry value.
- static write(hive: int, subkey: str, value_name: str, value: str | int, value_type: int | None = None) bool[source]¶
Write a registry value. Creates the subkey if it doesn’t exist.
- Parameters:
- Returns:
True if successful
- Return type:
Win32ServiceManager¶
- class Win32ServiceManager[source]¶
Bases:
objectManage Windows services via
sc.exe.- Example:
>>> if Win32ServiceManager.is_running("CrowdStrike Falcon"): ... Win32ServiceManager.stop("CrowdStrike Falcon")