【发布时间】:2019-04-24 01:52:54
【问题描述】:
当我在当地大学担任 IT 工作时,我已经编译了这个审计程序,但实际上我非常坚持实际抓取当前工作的驱动器并从 Programs 中提取所有文件strong> 和 Programs x86 以成功构建此应用程序,而不是使用注册表 (SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall),因为这不会只提取所有程序。
另外,我不确定如何获取脚本最初位于第二个粗体部分的当前活动目录驱动器,并创建一个文件夹,将文件作为 msinfo32.exe 系统名称保存到一个新文件夹中.
(不管叫什么名字)这是我一直在努力实现的一个长期目标,我完全迷失了。
' Sample VBScript to Export list of Installed Programs into CSV File.
' ------------------------------------------------------
const HKEY_LOCAL_MACHINE = &H80000002
Dim strComputer, strKeyPath
strComputer = "."
' Registry key path of Control panel items for installed programs
strKeyPath = "SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\"
Dim objReg, strSubkey, arrSubkeys
Set objReg=GetObject( _
"winmgmts:{impersonationLevel=impersonate}!\\" & _
strComputer & "\root\default:StdRegProv")
objReg.EnumKey HKEY_LOCAL_MACHINE, strKeyPath, arrSubkeys
Dim objFSO, objCSVFile
' Create CSV file
Const ForWriting = 2
Set objFSO = CreateObject("Scripting.FileSystemObject")
' Here, I have given CSV file path as "Installed-Softwares.csv", this will create Installed-Softwares.csv file
' where you placed and execute this VB Script file. You can give your own file path
' like "C:\Users\Administrator\Desktop\Installed-Softwares.csv"
Set objCSVFile = objFSO.CreateTextFile("F:\Custom\Installed-Softwares.csv", _
ForWriting, True)**
' Write Software property names as CSV columns(first line)
objCSVFile.Write "Name,Version,Publisher,Location,Size"
objCSVFile.Writeline ' New Line
Dim Name,Version,Publisher,Location,Size
'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
objReg.GetStringValue HKEY_LOCAL_MACHINE, strKeyPath & strSubkey, "Publisher",Publisher
objReg.GetStringValue HKEY_LOCAL_MACHINE, strKeyPath & strSubkey, "InstallLocation", Location
objReg.GetDWORDValue HKEY_LOCAL_MACHINE, strKeyPath & strSubkey, "EstimatedSize" , Size
If Size <> "" Then
Size= Round(Size/1024, 3) & " MB"
Else
Size= "0 MB"
End If
objCSVFile.Write Name &","&Version&","&Publisher&","&Location&","&Size
objCSVFile.Writeline ' New Line
End If
Next
WScript.Quit
注释:例如,从(例如C:\或当前主驱动器)程序文件和x86程序文件中拉取->放入列表->输出Currentdrive:\newfolder\msinfo32systemname。
此外,它显示的是 0 MB 而不是实际的 MB,我注意到输出文件正在执行此操作。这与其他文件结合使用,我实际上并没有完全从头开始编写代码。
【问题讨论】:
-
如果你使用的是 PSv5+,你能不能只使用
Get-Package | Sort Name | Export-Csv C:\temp\installedItems.csv -NoTypeInformation这样的东西? -
至于
Size问题:objReg.GetDWORDValue得到一个数值。您正在将其与带有If Size <> "" Then的字符串进行比较。将其更改为If Size <> 0 Then。
标签: powershell csv vbscript audit