Win32_StartupCommand lists only the First alphabetical entry of Startup Folders.

 Preview Message
Win32_StartupCommand lists only the First alphabetical entry of Startup Folders.

Hi All

I am trying to list all the Startup Commands of a computer using Win32_StartupCommand class. The code is:

strComputer = "."
Set objWMIService = GetObject("winmgmts:" _
    & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
Set colStartupCommands = objWMIService.ExecQuery _
    ("SELECT * FROM Win32_StartupCommand")

dim strOut
For Each objStartupCommand in colStartupCommands
    strOut = strOut & "Command: " & objStartupCommand.Command
    strOut = strOut & "Description: " & objStartupCommand.Description
    strOut = strOut & vbcrlf
Next

Wscript.Echo strOut

 

This program is supposed to fetch all the entries from following 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

However, the program is getting only first Alphabetical entry from the following folders:

systemdrive\Documents and Settings\All Users\Start Menu\Programs\Startup
systemdrive\Documents and Settings\username\Start Menu\Programs\Startup

For example if the Startup folder contains three links :

m.lnk , a.lnk , and k.lnk ..then the above program only lists the a.lnk..and not the others.

Is this a bug or is there something wrong with the usage. Kind;y point how can i find all the StartupCommands listed under these folders. I only wish to use inbulit classes for this purpose. And I dont wish to iterate through these folders to get these details..

 

Thanks and Regards

Sumit Chawla

 


Answer this question

Win32_StartupCommand lists only the First alphabetical entry of Startup Folders.

  • raaman


     Win32_StartupCommand lists only the First alphabetical entry of Startup Folders. 
    Hi All

    I am trying to list all the Startup Commands of a computer using Win32_StartupCommand class. The code is:

    strComputer = "."
    Set objWMIService = GetObject("winmgmts:" _
        & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
    Set colStartupCommands = objWMIService.ExecQuery _
        ("SELECT * FROM Win32_StartupCommand")

    dim strOut
    For Each objStartupCommand in colStartupCommands
        strOut = strOut & "Command: " & objStartupCommand.Command
        strOut = strOut & "Description: " & objStartupCommand.Description
        strOut = strOut & vbcrlf
    Next

    Wscript.Echo strOut

     

    This program is supposed to fetch all the entries from following 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


    However, the program is getting only first Alphabetical entry from the following folders:

    systemdrive\Documents and Settings\All Users\Start Menu\Programs\Startup
    systemdrive\Documents and Settings\username\Start Menu\Programs\Startup


    For example if the Startup folder contains three links :

    m.lnk , a.lnk , and k.lnk ..then the above program only lists the a.lnk..and not the others.

    Is this a bug or is there something wrong with the usage. Kind;y point how can i find all the StartupCommands listed under these folders. I only wish to use inbulit classes for this purpose. And I dont wish to iterate through these folders to get these details..

     

    Thanks and Regards

    Sumit Chawla

     
      
     
     


  • Rob Lemmens

    What Platform are you seeing this on Be specific.

    This works fine on CTP build of Vista that I own currently.


  • javapilot

    Hi Sumit,

    Any reason why you're using late bound objects for this You can query the WMI using the classes available in the System.Management namespace (you'll need to add a reference to the System.Management.dll). This code worked for me:

    Private Function GetAllCommands() As String
            Dim str As String = ""
            Dim query As New System.Management.ObjectQuery("SELECT * FROM WIN32_STARTUPCOMMAND")
            Dim searcher As New ManagementObjectSearcher
            searcher.Query = query
     
            For Each obj As ManagementObject In searcher.Get()
                str = str & obj.Item("Caption") & vbTab & obj.Item("name") & vbTab & obj.Item("Command") & vbTab & obj.Item("Description") & vbTab & obj.Item("Location")
                str = str & vbCrLf
            Next
     
            Return str
        End Function

    hope that helps,
    Imran.

  • nimi

    Hi Imran

    Thanks for the help.But i am not using .NET.

    Any help otherwise will be highly beneficial...


  • Mahendras

    I have tested this command on Win 2k Server and few other versions like 2k3 server also. Here it does not work..

    I have not used Vista...

    Thanks for the help

     


  • Win32_StartupCommand lists only the First alphabetical entry of Startup Folders.