【发布时间】:2013-12-13 20:33:46
【问题描述】:
我希望将单个计算机脚本变成大众使用的脚本。它的作用是允许我通过从文本文件中提取来选择要卸载的 Windows Essentials 的哪些部分。然而,它只是提示输入一个单一的计算机名称......我希望它从我创建的 Computer_Names.txt 的单独文本文件中提取,并在该列表中的所有计算机上运行卸载。我似乎无法正确理解。
Const ForReading = 1
strComputer = InputBox("Enter the Computer Name:- ")
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objTextFile = objFSO.OpenTextFile ("C:\Windows_Live_Components.txt", ForReading)
Set objWMIService = GetObject("winmgmts:" & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
StrOutput = "Uninstalled the following Software:- "
Do Until objTextFile.AtEndOfStream
strNextLine = objTextFile.Readline
arrSoftwareList = Split(strNextLine , ",")
Set colSoftware = objWMIService.ExecQuery ("Select * from Win32_Product Where Name = " & Chr(34) & arrSoftwareList(0) & Chr(34) )
For Each objSoftware in colSoftware
objSoftware.Uninstall()
strOutput = stroutput & vbCrLf & objsoftware.Name
Next
Loop
WScript.Echo strOutput
Computer_Names.txt 文件的内容就是这样。每台计算机上单独一行文本。
LAPD2712
LAPD2812
我们所有的计算机名称都是 4 个大写字母,4 个数字。
【问题讨论】:
-
请发布文本文件的内容。
-
刚刚编辑要显示的主要帖子。
标签: vbscript wmi uninstallation wmi-query