Rediger

Del via


Win32_StartupCommand class

The Win32_StartupCommandWMI class represents a command that runs automatically when a user logs onto the computer system.

The following syntax is simplified from Managed Object Format (MOF) code and includes all of the inherited properties. Properties and methods are in alphabetic order, not MOF order.

Syntax

[Dynamic, Provider("CIMWin32"), Privileges("SeRestorePrivilege"), UUID("{8502C50A-5FBB-11D2-AAC1-006008C78BC7}"), AMENDMENT]
class Win32_StartupCommand : CIM_Setting
{
  string Caption;
  string Description;
  string SettingID;
  string Command;
  string Location;
  string Name;
  string User;
  string UserSID;
};

Members

The Win32_StartupCommand class has these types of members:

Properties

The Win32_StartupCommand class has these properties.

Caption

Data type: string

Access type: Read-only

Qualifiers: MaxLen (64)

Short textual description of the current object.

This property is inherited from CIM_Setting.

Command

Data type: string

Access type: Read-only

Qualifiers: key, MappingStrings ("Win32Registry|SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Run")

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"

Description

Data type: string

Access type: Read-only

Textual description of the current object.

This property is inherited from CIM_Setting.

Location

Data type: string

Access type: Read-only

Qualifiers: key, MappingStrings ("Win32Registry|\\SOFTWARE\\MICROSOFT\\WINDOWS\\CURRENTVERSION\\Windows")

Path where the startup command resides on the disk file system.

For example: HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Run

Startup ("Startup")

Common Startup ("Common Startup")

HKLM\\SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Run ("HKLM\\SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Run")

HKLM\\SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\RunServices ("HKLM\\SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\RunServices")

Name

Data type: string

Access type: Read-only

Qualifiers: key, MappingStrings ("Win32API|File Structures|WIN32_FIND_DATA|cFileName")

File name of the startup command.

Example: "FindFast"

SettingID

Data type: string

Access type: Read-only

Qualifiers: MaxLen (256)

Identifier by which the current object is known.

This property is inherited from CIM_Setting.

User

Data type: string

Access type: Read-only

Qualifiers: key, MappingStrings ("WMI")

User name for whom this startup command will run.

Example: "mydomain\myname"

UserSID

Data type: string

Access type: Read-only

Qualifiers: MappingStrings ("WMI")

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

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.

Examples

The following VBScript enumerates the startup commands on a computer.

strComputer = "."
Set objWMIService = GetObject("winmgmts:" _
 & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
Set colStartupCommands = objWMIService.ExecQuery _
 ("SELECT * FROM Win32_StartupCommand")
For Each objStartupCommand in colStartupCommands
 Wscript.Echo "Command: " & objStartupCommand.Command
 Wscript.Echo "Description: " & objStartupCommand.Description
 Wscript.Echo "Location: " & objStartupCommand.Location
 Wscript.Echo "Name: " & objStartupCommand.Name
 Wscript.Echo "SettingID: " & objStartupCommand.SettingID
 Wscript.Echo "User: " & objStartupCommand.User
Next

Requirements

Requirement Value
Minimum supported client
Windows Vista
Minimum supported server
Windows Server 2008
Namespace
Root\CIMV2
MOF
CIMWin32.mof
DLL
CIMWin32.dll

See also

CIM_Setting

Operating System Classes