How can I get a list Local Windows Users (Only the Users that appear in the windows Logon Screen)

Just add a reference to System.Management in a Console Application and try this code: using System; using System.Management; using System.Linq; namespace ConsoleApplication5 { class Program { static void Main(string[] args) { ManagementObjectSearcher usersSearcher = new ManagementObjectSearcher(@”SELECT * FROM Win32_UserAccount”); ManagementObjectCollection users = usersSearcher.Get(); var localUsers = users.Cast<ManagementObject>().Where( u => (bool)u[“LocalAccount”] == true && (bool)u[“Disabled”] == … Read more

How to construct WMI query

Try this: string wmiQuery = string.Format(“SELECT CommandLine FROM Win32_Process WHERE Name LIKE ‘{0}%{1}'”, param1, param2); Adding some test info: string wmiQuery = string.Format ( “SELECT Name, ProcessID FROM Win32_Process WHERE Name LIKE ‘{0}%{1}'”, “wpf”, “.exe” ); Console.WriteLine ( “Query: {0}”, wmiQuery ); ManagementObjectSearcher searcher = new ManagementObjectSearcher ( wmiQuery ); ManagementObjectCollection retObjectCollection = searcher.Get ( … Read more

Bootstrapping SQL Express from WiX?

This is what I have, hope it helps: <?define ServerInstall=”SomeCondition” ?> <?define InstanceName = “YOUR_INSTANCE” ?> <?define SqlWebLink = http://download.microsoft.com/download/5/2/9/529FEF7B-2EFB-439E-A2D1-A1533227CD69/SQLEXPR_x86_ENU.exe ?> <Variable Name=”SqlVariable” Type=”string” Value=”/SAPWD=some_password” Hidden=”yes” /> <!– Read SQL Server keys to find current instance and version –> <util:RegistrySearch Id=”SqlInstanceKeyFound” Root=”HKLM” Key=”SOFTWARE\Microsoft\Microsoft SQL Server\Instance Names\SQL” Value=”$(var.InstanceName)” Result=”exists” Variable=”SqlInstanceKeyFound” /> <util:RegistrySearch Id=”SqlInstanceKey” Root=”HKLM” Key=”SOFTWARE\Microsoft\Microsoft SQL … Read more

Finding information about all serial devices connected through USB in C#

How to list all serial ports: There are several System-Defined Device Setup Classes available to hardware vendors. Properly written drivers for COM-Ports should use the Ports (COM & LPT ports)-class (guid: 4d36e978-e325-11ce-bfc1-08002be10318). Probably this class is used by the device manager as well. So you can use the following query to list every serial port … Read more

EnumDisplayDevices vs WMI Win32_DesktopMonitor, how to detect active monitors?

This is my current work-in-progress code for detecting the monitor device id, reliably. CString DeviceID; DISPLAY_DEVICE dd; dd.cb = sizeof(dd); DWORD dev = 0; // device index int id = 1; // monitor number, as used by Display Properties > Settings while (EnumDisplayDevices(0, dev, &dd, 0)) { DISPLAY_DEVICE ddMon; ZeroMemory(&ddMon, sizeof(ddMon)); ddMon.cb = sizeof(ddMon); DWORD … Read more

Get the drive letter of USB drive in PowerShell

Try: gwmi win32_diskdrive | ?{$_.interfacetype -eq “USB”} | %{gwmi -Query “ASSOCIATORS OF {Win32_DiskDrive.DeviceID=`”$($_.DeviceID.replace(‘\’,’\\’))`”} WHERE AssocClass = Win32_DiskDriveToDiskPartition”} | %{gwmi -Query “ASSOCIATORS OF {Win32_DiskPartition.DeviceID=`”$($_.DeviceID)`”} WHERE AssocClass = Win32_LogicalDiskToPartition”} | %{$_.deviceid} Tested with one and more than one USB device plugged-in.

WMI “installed” query different from add/remove programs list?

I believe your syntax is using the Win32_Product Class in WMI. One cause is that this class only displays products installed using Windows Installer (See Here). The Uninstall Registry Key is your best bet. HKEY_LOCAL_MACHINE\Software\Microsoft\Windows\CurrentVersion\Uninstall HKEY_LOCAL_MACHINE\SOFTWARE\WOW6432Node\Microsoft\Windows\CurrentVersion\Uninstall UPDATE FOR COMMENTS: The Uninstall Registry Key is the standard place to list what is installed and what isn’t … Read more