我有一个脚本,它将使用C驱动器下“程序文件”文件夹中的所有程序,并将它们列出在文本文件中。我还需要它也能够将安装的程序放在“程序文件(x86)”文件夹下。我从几个不同的来源将这段代码报废了,所以我在使用它时遇到了一些困难。
代码如下:
Const HKEY_LOCAL_MACHINE = &H80000002
Dim strComputer, strKeyPath
Dim objReg, strSubkey, arrSubkeys
Dim Name, Version
'Gets ready for the part where it makes the text file
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set WshShell = WScript.CreateObject("WScript.Shell")
strDirectory = "InstalledPrograms.txt"
strDirectory = objFSO.BuildPath(WshShell.SpecialFolders("Desktop"), strDirectory)
Set objFSO=CreateObject("Scripting.FileSystemObject")
outFile= strDirectory
Set objFile = objFSO.CreateTextFile(outFile, True)
strComputer = "."
'Registry key path of Control panel items for installed programs
strKeyPath = "SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\"
Set objReg=GetObject( _
"winmgmts:{impersonationLevel=impersonate}!\\" & _
strComputer & "\root\default:StdRegProv")
objReg.EnumKey HKEY_LOCAL_MACHINE, strKeyPath, arrSubkeys
'Enumerate registry keys.
For Each strSubkey In arrSubkeys
objReg.GetStringValue HKEY_LOCAL_MACHINE, strKeyPath & strSubkey, "DisplayName", Name
If Name <> "" Then
objReg.GetStringValue HKEY_LOCAL_MACHINE, strKeyPath & strSubkey, "DisplayVersion", Version
objFile.Write vbCrLf & Name & " | " & Version
objFile.Write " "
End If
Next
WScript.Echo "Installed Programs listed successfully in the InstalledPrograms.txt file on your desktop."
WScript.Quit