Detecting the number of processors

System.Environment.ProcessorCount returns the number of logical processors http://msdn.microsoft.com/en-us/library/system.environment.processorcount.aspx For physical processor count you’d probably need to use WMI – the following metadata is supported in XP/Win2k3 upwards (Functionality enabled in SP’s prior to Vista/Win2k8). Win32_ComputerSystem.NumberOfProcessors returns physical count Win32_ComputerSystem.NumberOfLogicalProcessors returns logical (duh!) Be cautious that HyperThreaded CPUs appear identical to multicore’d CPU’s yet the performance … Read more

Get Screen resolution using WMI/powershell in Windows 7

For the record, the PowerShell code is: Get-WmiObject -Class Win32_DesktopMonitor | Select-Object ScreenWidth,ScreenHeight I get the same values in Landscape or in Portrait mode. UPDATE: In a multi monitor environment you can get the info for all monitors with: PS> Add-Type -AssemblyName System.Windows.Forms PS> [System.Windows.Forms.Screen]::AllScreens BitsPerPixel : 32 Bounds : {X=0,Y=0,Width=1280,Height=800} DeviceName : \\.\DISPLAY1 Primary … Read more

How to connect to a remote Windows machine to execute commands using python?

You can use pywinrm library instead which is cross-platform compatible. Here is a simple code example: #!/usr/bin/env python import winrm # Create winrm connection. sess = winrm.Session(‘https://10.0.0.1’, auth=(‘username’, ‘password’), transport=”kerberos”) result = sess.run_cmd(‘ipconfig’, [‘/all’]) Install library via: pip install pywinrm requests_kerberos. Here is another example from this page to run Powershell script on a remote … Read more

How do I get information about recently connected USB device?

The Win32_DeviceChangeEvent reports just the type of event that occurred and the Time of the event (uint64, representing 100-nanosecond intervals after January 1, 1601, UTC). No that much useful if you also want to know what arrived or was removed. I suggest to use instead the WqlEventQuery class, setting its EventClassName to __InstanceOperationEvent. This system … Read more

Trying to copy file from one XP PC to another using WMI, since RPC and UNC are not available

I learned that WMI cannot create files on a remote host, and it cannot copy files over a network connection: http://msdn.microsoft.com/en-us/library/windows/desktop/aa389288%28v=vs.85%29.aspx However, it can run a cmd process. Here’s Frank White’s code in C sharp, followed by his example: https://stackoverflow.com/a/8913231/1569434 InputParameters(“CommandLine”) = “cmd /c echo myFTPCommands > c:\ftpscript.txt” You will need four things to use … Read more

How can I get the CPU temperature?

For others who may come by here, maybe take a look at : http://openhardwaremonitor.org/ Follow that link and at first you might think, “Hey, that’s an application, and that is why it was removed. The question was how to do this from C# code, not to find an application that can tell me the temperature…” … Read more

Get the serial number of USB storage devices in .Net Core 2.1

This Class performs a series of queries on the WMI Win32_DiskDrive class and its associators: Win32_DiskDriveToDiskPartition and CIM_LogicalDiskBasedOnPartition, to retrieve informations on the active USB Drives on a System (local or remote). It might seem redundant (probably because it is), since you just asked for the USB Drives Serial Number. But, you never know what … Read more