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, UserExemples
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, UserLe 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, FlagsPropriétés
| Nom | Type | Accès | Description | |||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| Caption# | string | lecture | Brève description textuelle de l'objet actuel. Code | |||||||||||||||
| Command# clé | string | lecture | 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 | |||||||||||||||
| Description# | string | lecture | Description textuelle de l'objet actuel. Code | |||||||||||||||
| Location# clé | string | lecture | 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)
Code | |||||||||||||||
| Name# clé | string | lecture | Nom de fichier de la commande de démarrage. Exemple : "FindFast" Code | |||||||||||||||
| SettingID# | string | lecture | Identifiant par lequel l'objet actuel est connu. Code | |||||||||||||||
| User# clé | string | lecture | Nom d'utilisateur pour lequel cette commande de démarrage s'exécutera. Exemple : "mydomain\myname" Code | |||||||||||||||
| UserSID# | string | lecture | 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 |
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
- CIM_Setting
- 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
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.