• 售前

  • 售后

热门帖子
入门百科

如何用VBS脚本网络长途盘算机或本土地算机安装的软件

[复制链接]
dxf17 显示全部楼层 发表于 2021-8-19 19:40:03 |阅读模式 打印 上一主题 下一主题
目次


  • 目的
  • 制作VBS脚本
  • 修改效果文件保存路径。
  • 修改过滤条件(设置不想表现的步调名)
  • 测试

    • 测试方法1
    • 测试方法2

      • 测试方法2的留意事项



目的

用VBS脚本网络域中长途盘算机或当地盘算机安装的软件,Windows版本。并将网络的效果保存到盘算机名为文件名的文本文件中。文本文件可以保存到网络路径中或当前VBS文件所在目次。同时支持32位和64位体系。
并过滤到一些补丁包、Office组件、NVIDIA、Intel®的驱动等。

制作VBS脚本

保存下面的VBS步调代码到vbs文件中
  1. On Error Resume Next  
  2. Const HKCU   = &h80000001
  3. Const HKLM   = &H80000002
  4. Const strKeyPath = "Software\Microsoft\Windows\CurrentVersion\Uninstall"
  5. Const str64KeyPath = "SOFTWARE\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall"
  6. Const ForReading = 1
  7. Const ForWriting = 2
  8. Const ForAppending = 8
  9. 'FilePath  = "\\Server-File\PCSoftList"
  10. FilePath  = CreateObject("Scripting.FileSystemObject").GetFolder(".").Path & ""
  11. Set Wshell   = CreateObject("Wscript.Shell")
  12. Set objFSO   = CreateObject("Scripting.FileSystemobject")
  13. 'Set collected computers Name
  14. set argus=wscript.arguments
  15. if argus.count=0 then
  16. strComputerName = Wshell.RegRead("HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\Tcpip\Parameters\Hostname")
  17. else
  18. strComputerName = argus(0)
  19. end if
  20. Set textWriteFile = objFSO.OpenTextFile(FilePath & ucase(strComputerName) &".txt",ForWriting,True,True)
  21. Set objReg = GetObject("winmgmts://" & strComputerName & "/root/default:StdRegProv")
  22. 'Get OS Version
  23. intRet = objReg.GetStringValue(HKLM, "SOFTWARE\Microsoft\Windows NT\CurrentVersion","ProductName",strOSVersion)
  24. If intRet = 0 Then
  25. intRet = objReg.GetStringValue(HKLM, "SOFTWARE\Microsoft\Windows NT\CurrentVersion","CSDVersion",strOSServicePack)
  26. intRet = objReg.GetStringValue(HKLM, "SOFTWARE\Wow6432Node\Microsoft\Windows NT\CurrentVersion","ProductName",str64BitOSVersion)
  27. if intRet = 0 then
  28.   strOSVersion = strOSVersion & " 64bit"
  29. end if
  30. intRet = objReg.GetStringValue(HKLM, "SYSTEM\CurrentControlSet\Control\Nls\Language","InstallLanguage",OSLanguageCode)
  31. if intRet = 0 then
  32.   select case OSLanguageCode
  33.   case "0804" '中文
  34.    strOSVersion = strOSVersion & " Chinese Version"
  35.   case "0411" '日文
  36.    strOSVersion = strOSVersion & " Japanese Version"
  37.   case "0409" '英文
  38.    strOSVersion = strOSVersion & " English Version"
  39.   case else '未知语言
  40.    strOSVersion = strOSVersion & " UnknownLanguage Version"
  41.   end select
  42. end if
  43. Else
  44. strOSVersion = "OS Get Failed"
  45. strOSServicePack = "NoFind"
  46. End If
  47. if InStr(LCase(strOSVersion),"windows")>0 then
  48. textWriteFile.WriteLine("""" & ucase(strComputerName) & """" & vbTab & """" & strOSVersion & """" & vbTab & """" & strOSServicePack & """")
  49. end if
  50. 'Display User Software.
  51. objReg.EnumKey HKCU, strKeyPath,arrSubKeys
  52. For Each strSubKey In arrSubKeys
  53. intGet = objReg.GetDWORDValue(HKCU, strKeyPath & strSubKey,"SystemComponent",intSystemComponent)
  54. If IsNull(intSystemComponent) then
  55.   intSystemComponent = 0
  56. End If
  57. intRet = objReg.GetStringValue(HKCU, strKeyPath & strSubKey,"ParentDisplayName",strName)
  58. If intSystemComponent = 0 and intRet > 0 then
  59.   intRet = objReg.GetStringValue(HKCU, strKeyPath & strSubKey,"DisplayName",strName)
  60.   If strName <> "" And intRet = 0 And ignorePgm(strName) Then
  61.    strName = replace(replace(strName,vbCrLf,""),vbTab,"")
  62.    intRet = objReg.GetStringValue(HKCU, strKeyPath & strSubKey,"DisplayVersion",strVersion)
  63.    textWriteFile.WriteLine("""" & ucase(strComputerName) & """" & vbTab & """" & strName & """" & vbTab & """" & strVersion & """")
  64.   End If
  65. End If
  66. Next
  67. 'Display Machine 32bit Software.
  68. objReg.EnumKey HKLM, strKeyPath,arrSubKeys
  69. For Each strSubKey In arrSubKeys
  70. intGet = objReg.GetDWORDValue(HKLM, strKeyPath & strSubKey,"SystemComponent",intSystemComponent)
  71. If IsNull(intSystemComponent) then
  72.   intSystemComponent = 0
  73. End If
  74. intRet = objReg.GetStringValue(HKLM, strKeyPath & strSubKey,"ParentDisplayName",strName)
  75. If intSystemComponent = 0 and intRet > 0 then
  76.   intRet = objReg.GetStringValue(HKLM, strKeyPath & strSubKey,"DisplayName",strName)
  77.   If strName <> "" And intRet = 0 And ignorePgm(strName) Then '
  78.    strName = replace(replace(strName,vbCrLf,""),vbTab,"")
  79.    intRet = objReg.GetStringValue(HKLM, strKeyPath & strSubKey,"DisplayVersion",strVersion)
  80.    textWriteFile.WriteLine("""" & ucase(strComputerName) & """" & vbTab & """" & strName & """" & vbTab & """" & strVersion & """")
  81.   End If
  82. End If
  83. Next
  84. 'Display Machine 64bit Software.
  85. objReg.EnumKey HKLM, str64KeyPath,arrSubKeys
  86. For Each strSubKey In arrSubKeys
  87. intGet = objReg.GetDWORDValue(HKLM, str64KeyPath & strSubKey,"SystemComponent",intSystemComponent)
  88. If IsNull(intSystemComponent) then
  89.   intSystemComponent = 0
  90. End If
  91. intRet = objReg.GetStringValue(HKLM, str64KeyPath & strSubKey,"ParentDisplayName",strName)
  92. If intSystemComponent = 0 and intRet > 0 then
  93.   intRet = objReg.GetStringValue(HKLM, str64KeyPath & strSubKey,"DisplayName",strName)
  94.   If strName <> "" And intRet = 0 And ignorePgm(strName) Then
  95.    strName = replace(replace(strName,vbCrLf,""),vbTab,"")
  96.    intRet = objReg.GetStringValue(HKLM, str64KeyPath & strSubKey,"DisplayVersion",strVersion)
  97.    textWriteFile.WriteLine("""" & ucase(strComputerName) & """" & vbTab & """" & strName & """" & vbTab & """" & strVersion & """")
  98.   End If
  99. End If
  100. Next
  101. textWriteFile.Close
  102. function ignorePgm(strPgm)
  103. If inStr(1,strPgm,"Microsoft Office ",1)<=0 then
  104.   '不输出Security Update、.NET Framework、Microsoft Visual C++、NVIDIA、Intel(R)的程序
  105.   ignorePgm = inStr(1,strPgm,"Security Update",1)<=0 _
  106.    And inStr(1,strPgm,".NET Framework",1)<=0 _
  107.    And inStr(1,strPgm,"Microsoft Visual C++",1)<=0 _
  108.    And inStr(1,strPgm,"NVIDIA",1)<=0 _
  109.    And inStr(1,strPgm,"Intel(R)",1)<=0
  110. Else
  111.   '让个版本的Office能正常输出
  112.   ignorePgm = inStr(1,strPgm,"Microsoft Office ",1)>0 _
  113.      And (inStr(1,strPgm," 2000 ",1)>0 _
  114.       Or inStr(1,strPgm," 2003 ",1)>0 _
  115.       Or (inStr(1,strPgm,"Microsoft Office Access ",1)=1 And inStr(1,strPgm," MUI",1)<=0) _
  116.       Or strPgm="Microsoft Office Professional Plus 2007" _
  117.       Or strPgm="Microsoft Office Professional Plus 2010" _
  118.       Or strPgm="Microsoft Office Professional Plus 2016" _
  119.       Or strPgm="Microsoft Office Standard 2007" _
  120.       Or strPgm="Microsoft Office Standard 2010" _
  121.       Or strPgm="Microsoft Office Standard 2016" _
  122.       Or strPgm="Microsoft Office Standard 2019")
  123. End If
  124. end function
复制代码
假设保存的文件名为InstalledSoftList.vbs。保存在D:\

修改效果文件保存路径。

请修改下列代码
  1. 'FilePath  = "\\Server-File\PCSoftList"
  2. FilePath  = CreateObject("Scripting.FileSystemObject").GetFolder(".").Path & ""
复制代码
当前默认是保存到InstalledSoftList.vbs文件所在目次。可以不修改。

修改过滤条件(设置不想表现的步调名)

请修改下列代码
  1. '不输出Security Update、.NET Framework、Microsoft Visual C++、NVIDIA、Intel(R)的程序
  2.   ignorePgm = inStr(1,strPgm,"Security Update",1)<=0 _
  3.    And inStr(1,strPgm,".NET Framework",1)<=0 _
  4.    And inStr(1,strPgm,"Microsoft Visual C++",1)<=0 _
  5.    And inStr(1,strPgm,"NVIDIA",1)<=0 _
  6.    And inStr(1,strPgm,"Intel(R)",1)<=0
复制代码
默认不表现Security Update、.NET Framework、Microsoft Visual C++、NVIDIA、Intel®的步调
测试前可以不修改

测试


测试方法1

网络当前盘算机安装的软件
  1. 直接双击InstalledSoftList.vbs
复制代码
假计划算机名为PC-Name01,会在D:\或指定目次下天生一个名为PC-Name01.txt的文件。

测试方法2

网络长途盘算机上安装的软件。
在CMD窗口中运行下列命令。(假计划算机名为PC-Name02)
  1. cscript d:\InstalledSoftList.vbs PC-Name02
复制代码
会在D:\或指定目次下天生一个名为PC-Name02.txt的文件。

测试方法2的留意事项

假如运行后得到的PC-Name02.txt文件为空文件。请确认下列两项内容。
      
  • 长途盘算机必须于运行脚本的盘算机是同一个域的成员盘算机  
  • 长途盘算机的防火墙为关闭状态,或设置了【入站规则】【Windows Management Instrumentation(WMI)】允许
到此这篇关于怎样用VBS脚本网络长途盘算机或当地盘算机安装的软件的文章就先容到这了,更多相关VBS脚本网络盘算机安装的软内容请搜刮草根技术分享以前的文章或继承浏览下面的相关文章盼望大家以后多多支持草根技术分享!

帖子地址: 

回复

使用道具 举报

分享
推广
火星云矿 | 预约S19Pro,享500抵1000!
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

草根技术分享(草根吧)是全球知名中文IT技术交流平台,创建于2021年,包含原创博客、精品问答、职业培训、技术社区、资源下载等产品服务,提供原创、优质、完整内容的专业IT技术开发社区。
  • 官方手机版

  • 微信公众号

  • 商务合作