我正在尝试检查iTunes是否已安装在我网络上的计算机上。我正在使用vbscript来做到这一点,但我没有得到任何结果。我知道脚本正在扫描PC,因为它需要几分钟才能终止。我也知道有几台PC上安装了iTunes。这是我编写的内容。
Dim inputFile
Dim objFSO
Dim fil
Dim line
Dim logFile
Set shl = WScript.CreateObject("WScript.Shell")
Set objFSO = CreateObject("Scripting.FileSystemObject")
Const ForReading = 1
Set inputFile = objFSO.OpenTextFile("pcList.txt", ForReading)
WScript.Echo "Computers will be checked for iTunes.exe. Check log file for resuluts."
' If log file exists, append to it and do not over write.
if(objFSO.FileExists("LogFiles\iTunesCheck.txt")) Then
Const ForAppending = 8
set logFile = objFSO.OpenTextFile("LogFiles\iTunesCheck.txt", ForAppending)
Else
' If log file does not exist, create one.
Const ForWriting = 8
set logFile = objFSO.CreateTextFile("LogFiles\iTunesCheck.txt", True)
End If
logFile.WriteLine "Scan date and time: " & Now
logFile.WriteLine "Scan has detected iTunes in the PCs listed below."
While Not inputFile.AtEndOfStream
line = inputFile.ReadLine
Set objWMIService = GetObject("winmgmts:\\" & line & "\root\cimv2")
On Error Resume Next
Set colItems = objWMIService.ExecQuery("Select * from Win32_NetworkAdapterConfiguration Where IPEnabled = True")
For Each objItem in colItems
If objFSO.FileExists(line & "\C$\Program Files\iTunes\iTunes.exe") Then
logFile.WriteLine line
End If
Next
Wend
logFile.WriteLine
logFile.WriteLine
logFile.Close
Wscript.Echo "All done."
答案 0 :(得分:1)
寻找C:\Program Files\iTunes\iTunes.exe
是一个坏主意:
C:
,Program Files (x86)
而不是Program Files
,C$
),而不是这样,对每台计算机运行Select * From Win32_Product Where Name='iTunes'
查询,看看结果集是否为空。
答案 1 :(得分:1)
@Helen的反对意见(因为您可能拥有一个只有C驱动器并且是域管理员的全32位环境)...
从这一行看
Set objWMIService = GetObject("winmgmts:\\" & line & "\root\cimv2")
您的文本文件只包含PC名称,每行一个。我看到你自己正在添加“\\”。 在这种情况下,我建议你也应该在UNC字符串中包含“\\”,如下所示:
If objFSO.FileExists("\\" & line & "\C$\Program Files\iTunes\iTunes.exe") Then
我也不确定你为什么要枚举网卡。如果目标机器关闭,这是否优雅地运行零次?