I can't find a definite solution to this problem. In short, what I want to do is gather a list of applications installed on the computer, and write it to a file. Here was my first attempt:
Set objShell = WScript.CreateObject("Wscript.Shell")
randTrashVar = objShell.Run("cmd /c wmic product get Name,Version > " & strAppListPath, 0, true)
But it must be run as an admin to work in all my cases. So I tried wrapping it in runas, but don't know too much about it so I could be wrong there.
randTrashVar = objShell.Run("runas /user:Administrator ""cmd /c wmic product get Name,Version > " & strAppListPath & "", 0, true)
Or doing something with objShell.Exec too
Set getAppsProcess = objShell.Exec("runas /user:Administrator ""cmd /c wmic product get Name,Version > " & strAppListPath & "")
Do While getAppsProcess.Status = 0
WScript.Sleep 100
Loop
The first one gets me somewhere, and they all wait for the command to finish before moving on, but didn't run as admin/run at all (as far as I know).
This runs as Admin now, but no wait
CreateObject("Shell.Application").ShellExecute "cmd", "/c wmic product get Name,Version > " & strAppListPath, "", "runas", 1
What can I do to get the best of these?
Set objWMIService = GetObject("winmgmts:{impersonationLevel=impersonate}!\\.\root\cimv2") Set colItems = objWMIService.ExecQuery("Select * From Win32_Product") For Each objItem in colItems msgbox objItem.Name & " " & objItem.Version Next- phd443322