Reputation: 188
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?
Upvotes: 3
Views: 3896
Reputation: 503
One or the other. WMIC does not require admin necessarly - •
wmic
The first time you run Wmic after system installation, it must be run from an elevated command prompt. The elevated mode may not be required for subsequent executions of Wmic unless the WMI operations require administrator privilege. See http://msdn.microsoft.com/en-au/library/aa826699(v=vs.85).aspx
Start - All Programs - Accessories - Right click Command Prompt and choose Run As Administrator. Type (or copy and paste by right clicking in the Command Prompt window and choosing Paste). Type for table format
wmic /output:"%userprofile%\desktop\WindowsInstaller.html" product get /format:htable
or in a form format
wmic /output:"%userprofile%\desktop\WindowsInstaller.html" product get /format:hform
It will create a html file on the desktop.
Note
This is not a full list. This is only products installed with Windows Installer. There is no feature for everything.
However as I said in my previous post nearly everything is listed in the registry.
So to see it in a command prompt
reg query HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall /s
or in a file
reg query HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall /s>"%userprofile%\desktop\WindowsUninstall.txt"
To see it in notepad in a different format
Click Start - All Programs - Accessories - Right click Command Prompt and choose Run As Administrator. Type Regedit and navigate to
HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall
Right click the Uninstall key and choose Export. If you save as a reg file (there is also text file, they are slightly different text formats) you need to right click the file and choose Edit to view it.
To view Windows Updates
wmic /output:"%userprofile%\desktop\WindowsUpdate.html" qfe get /format:htable
Upvotes: 0