Main example
List instances
# All instances of Win32_StartupCommand, with the main properties
Get-CimInstance -ClassName Win32_StartupCommand |
Select-Object -Property Name, Command, Location, UserExamples
Filter with WQL
# WQL filter evaluated by the provider: startup entries defined under HKLM
Get-CimInstance -ClassName Win32_StartupCommand -Filter "Location LIKE 'HKLM%'" |
Select-Object -Property Name, Command, Location, UserThe filter is evaluated by the WMI provider: less data is transferred than with Where-Object.
Query a remote computer (CIM session)
review before running# Name of the remote computer
$computerName = 'SERVER01'
# The CIM session (WSMan by default) can be reused for several queries
$cimSession = New-CimSession -ComputerName $computerName
try {
Get-CimInstance -CimSession $cimSession -ClassName Win32_StartupCommand |
Select-Object -Property Name, Command, Location, User
} finally {
Remove-CimSession -CimSession $cimSession
}WSMan (WinRM) is used by default. For a host without WinRM, create the session with -SessionOption (New-CimSessionOption -Protocol Dcom). Add -Credential to use another account.
Show the class structure
# Class structure: properties, types and flags (Key, ReadOnly…)
$cimClass = Get-CimClass -ClassName Win32_StartupCommand
$cimClass.CimClassProperties |
Select-Object -Property Name, CimType, FlagsProperties
| Name | Type | Access | Description | |||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| Caption# | string | read | Short textual description of the current object. Code | |||||||||||||||
| Command# key | string | read | Command run by the startup command. WMI obtains this data from the registry key HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Run Example: "C:\Windows\notepad.exe myfile.txt" Code | |||||||||||||||
| Description# | string | read | Textual description of the current object. Code | |||||||||||||||
| Location# key | string | read | Path where the startup command resides on the disk file system. For example: HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Run Values (4)
Code | |||||||||||||||
| Name# key | string | read | File name of the startup command. Example: "FindFast" Code | |||||||||||||||
| SettingID# | string | read | Identifier by which the current object is known. Code | |||||||||||||||
| User# key | string | read | User name for whom this startup command will run. Example: "mydomain\myname" Code | |||||||||||||||
| UserSID# | string | read | The UserSID property indicates the SID of the user for whom this startup command will run. That User property may be empty but UserSID still has a value if the user name can't be resolved (like in the case of a deleted user). The property is helpful to distinguish between commands associated w/ two different users with unresolved names. It may be NULL when the command is associated with items not actually identifying a user like All Users. Example:S-1-5-21-1579938362-1064596589-3161144252-1006 Code |
Remarks
The Win32_StartupCommand class is derived from CIM_Setting.
Computer startup does not end after the operating system has been loaded. Instead, the Windows operating system can be configured so that startup commands are run each time Windows starts. Startup commands are stored in the registry or as part of the user profile and are used to automatically start specified scripts or applications each time Windows is loaded.
In most cases, autostart programs are useful; they ensure that certain applications, such as antivirus tools, are automatically started and run each time Windows is loaded. However, autostart programs also can be responsible for problems such as:
- Computers that take an exceptionally long time to start. This might be the result of a large number of applications that must be started each time Windows starts.
- Applications that are represented in the Taskbar or in Task Manager, even though the user did not start them. Although these applications do not necessarily cause problems, they can result in help desk calls from users who are confused as to where these programs came from and why they are running.
- Computers experiencing problems even when they seem idle. These problems are often traced to startup commands that are running when no one is aware that they are running.
Identifying the applications and scripts that automatically run at startup is an important but difficult administrative task, because startup commands can be stored in many different locations:
- HKLM\Software\Microsoft\Windows\CurrentVersion\Run
- HKLM\Software\Microsoft\Windows\CurrentVersion\RunOnce
- HKCU\Software\Microsoft\Windows\CurrentVersion\Run
- HKCU\Software\Microsoft\Windows\CurrentVersion\RunOnce
- HKU\ProgID\Software\Microsoft\Windows\CurrentVersion\Run
- systemdrive\Documents and Settings\All Users\Start Menu\Programs\Startup
- systemdrive\Documents and Settings\username\Start Menu\Programs\Startup
You can use the WMI Win32_StartupCommand class to enumerate autostart programs regardless of where the information is stored.
The calling process that uses this class must have the SE_RESTORE_NAME privilege on the computer in which the registry resides. For example, if you enumerate this class on the local computer, the account under which your application runs must have this privilege. For more information, see Executing Privileged Operations.
You can change the registry values where Win32_StartupCommand obtains data by calling the WMI System Registry Provider methods in script or in C++. For more information, see Modifying the System Registry.
Inheritance
Superclass chain
- CIM_Setting
- Win32_StartupCommand
Known subclasses
No known subclass.
Requirements
- Namespace
- root/cimv2
- Minimum client
- Windows Vista
- Minimum server
- Windows Server 2008
- Provider
- CIMWin32
- MOF file
- CIMWin32.mof
- DLL
- CIMWin32.dll
Class qualifiers
Dynamic Provider("CIMWin32") Privileges("SeRestorePrivilege") UUID("{8502C50A-5FBB-11D2-AAC1-006008C78BC7}") AMENDMENT
Microsoft source
Descriptions, properties and methods come from the Microsoft documentation (MicrosoftDocs/win32 repository), published under the CC BY 4.0 licence. Formatting and translations are specific to this site; the PowerShell examples are written for it.