Win32_StartupCommand

Win32 Startup Command
root/cimv2dynamiqueclé : Commandclé : Locationclé : Nameclé : User

La classe WMI Win32_StartupCommand représente une commande exécutée automatiquement lorsqu'un utilisateur ouvre une session sur le système informatique.

Sur cette page

Exemple principal

Lister les instances

# Toutes les instances de Win32_StartupCommand, avec les propriétés principales
Get-CimInstance -ClassName Win32_StartupCommand |
    Select-Object -Property Name, Command, Location, User

Exemples

Filtrer avec WQL

# Filtre WQL évalué par le fournisseur : démarrages définis dans HKLM
Get-CimInstance -ClassName Win32_StartupCommand -Filter "Location LIKE 'HKLM%'" |
    Select-Object -Property Name, Command, Location, User

Le filtre est évalué par le fournisseur WMI : moins de données transitent qu'avec Where-Object.

Interroger un ordinateur distant (session CIM)

à vérifier avant exécution
# Nom de l'ordinateur distant
$computerName = 'SERVER01'
# La session CIM (WSMan par défaut) est réutilisable pour plusieurs requêtes
$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) est utilisé par défaut. Pour un hôte sans WinRM, créez la session avec -SessionOption (New-CimSessionOption -Protocol Dcom). Ajoutez -Credential pour un autre compte.

Afficher la structure de la classe

# Structure de la classe : propriétés, types et indicateurs (Key, ReadOnly…)
$cimClass = Get-CimClass -ClassName Win32_StartupCommand
$cimClass.CimClassProperties |
    Select-Object -Property Name, CimType, Flags

Propriétés

8 sur 8 propriétés
NomTypeAccèsDescription
Captionstringlecture

Brève description textuelle de l'objet actuel.

Code
# Valeur de Caption pour chaque instance
Get-CimInstance -ClassName Win32_StartupCommand -Property Command, Location, Caption |
    Select-Object -Property Command, Location, Caption
Command cléstringlecture

Commande exécutée par la commande de démarrage.

WMI obtient ces données à partir de la clé de registre

HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Run

Exemple : "C:\Windows\notepad.exe myfile.txt"

Code
# Valeur de Command pour chaque instance
Get-CimInstance -ClassName Win32_StartupCommand -Property Location, Command |
    Select-Object -Property Location, Command
Descriptionstringlecture

Description textuelle de l'objet actuel.

Code
# Valeur de Description pour chaque instance
Get-CimInstance -ClassName Win32_StartupCommand -Property Command, Location, Description |
    Select-Object -Property Command, Location, Description
Location cléstringlecture

Chemin d'accès à l'emplacement de la commande de démarrage sur le système de fichiers du disque.

Par exemple : HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Run

Valeurs (4)
ValeurLibelléDescription
StartupStartup
Common StartupCommon Startup
HKLM\\\\SOFTWARE\\\\Microsoft\\\\Windows\\\\CurrentVersion\\\\RunHKLM\\SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Run
HKLM\\\\SOFTWARE\\\\Microsoft\\\\Windows\\\\CurrentVersion\\\\RunServicesHKLM\\SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\RunServices
Code
# Valeur de Location pour chaque instance
Get-CimInstance -ClassName Win32_StartupCommand -Property Command, Location |
    Select-Object -Property Command, Location
Name cléstringlecture

Nom de fichier de la commande de démarrage.

Exemple : "FindFast"

Code
# Valeur de Name pour chaque instance
Get-CimInstance -ClassName Win32_StartupCommand -Property Command, Location, Name |
    Select-Object -Property Command, Location, Name
SettingIDstringlecture

Identifiant par lequel l'objet actuel est connu.

Code
# Valeur de SettingID pour chaque instance
Get-CimInstance -ClassName Win32_StartupCommand -Property Command, Location, SettingID |
    Select-Object -Property Command, Location, SettingID
User cléstringlecture

Nom d'utilisateur pour lequel cette commande de démarrage s'exécutera.

Exemple : "mydomain\myname"

Code
# Valeur de User pour chaque instance
Get-CimInstance -ClassName Win32_StartupCommand -Property Command, Location, User |
    Select-Object -Property Command, Location, User
UserSIDstringlecture

La propriété UserSID indique le SID de l'utilisateur pour lequel cette commande de démarrage s'exécutera. La propriété User peut être vide, mais UserSID conserve une valeur si le nom d'utilisateur ne peut pas être résolu (par exemple, dans le cas d'un utilisateur supprimé). Cette propriété permet de distinguer les commandes associées à deux utilisateurs différents dont les noms ne peuvent pas être résolus. Elle peut avoir la valeur NULL lorsque la commande est associée à des éléments qui n'identifient pas réellement un utilisateur, comme Tous les utilisateurs.

Exemple : S-1-5-21-1579938362-1064596589-3161144252-1006

Code
# Valeur de UserSID pour chaque instance
Get-CimInstance -ClassName Win32_StartupCommand -Property Command, Location, UserSID |
    Select-Object -Property Command, Location, UserSID

Remarques

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.

Héritage

Chaîne des superclasses

  1. CIM_Setting
  2. Win32_StartupCommand

Sous-classes connues

Aucune sous-classe connue.

Prérequis

Espace de noms
root/cimv2
Client minimum
Windows Vista
Serveur minimum
Windows Server 2008
Fournisseur
CIMWin32
Fichier MOF
CIMWin32.mof
DLL
CIMWin32.dll
Qualificateurs de classe

Dynamic Provider("CIMWin32") Privileges("SeRestorePrivilege") UUID("{8502C50A-5FBB-11D2-AAC1-006008C78BC7}") AMENDMENT

Source Microsoft

Source : Microsoft Learn

Les descriptions, propriétés et méthodes proviennent de la documentation Microsoft (dépôt MicrosoftDocs/win32), publiée sous licence CC BY 4.0. La mise en forme et les traductions sont propres à ce site ; les exemples PowerShell y sont rédigés.