VBS脚本在文本文件中运行agais not systems - McAfee序列号

时间:2014-08-29 13:01:38

标签: vbscript mcafee

现在,此VBS向WMI查询特定详细信息,例如MAke,型号,序列号。然后将它们放入特定的注册表项位置。

现在它运行它运行的本地计算机。如何更新以循环通过文本文件并针对远程计算机运行。如果我想从活动目录中获取大约1000台机器,请将它们放在一个文本文件中,并让以下脚本一次运行

'**************************************************************
'* VBScript to create custom registry key for ePO
'* Author: 
'* Company: XXXXX
'* Usage: wscript ePO_customkeys.vbs 
'*
'* Date:        Comments
'*============================================================= 
'* 07/14/2014   Created
'* 07/15/2014   Updated variables - Stretch
'**************************************************************

On error resume next

'**************************************************************
'* Global Variables
'**************************************************************
const HOSTNAME_NAME = "."  'declar rmote computer name; use . for local PC
const HKEY_LOCAL_MACHINE = &H80000002
const REG_KEY_PATH = "SOFTWARE\Network Associates\ePolicy Orchestrator\Agent\CustomProps"



Dim objManufacturer, objModel, objSerial

'retrieve model
Set objWMIService = GetObject("winmgmts:\\" & HOSTNAME_NAME & "\root\CIMV2") 
Set colItems = objWMIService.ExecQuery( "SELECT * FROM Win32_ComputerSystem",,48) 

For Each objItem in colItems 
    objModel = Trim(objItem.Model)

Next

'retrieve computer manufacturer, serial
Set objWMIService = GetObject("winmgmts:\\" & HOSTNAME_NAME & "\root\CIMV2") 
Set colItems = objWMIService.ExecQuery( "SELECT * FROM Win32_BIOS",,48) 
For Each objItem in colItems 
objManufacturer = Trim(objItem.Manufacturer)
objSerial = Trim(objItem.SerialNumber)

Next


'add registry
'Set StdOut = WScript.StdOut
Set oReg=GetObject("winmgmts:{impersonationLevel=impersonate}!\\" & HOSTNAME_NAME & "\root\default:StdRegProv")

'create registry key
oReg.CreateKey HKEY_LOCAL_MACHINE,REG_KEY_PATH

oReg.SetStringValue HKEY_LOCAL_MACHINE,REG_KEY_PATH,"CustomProps1",objManufacturer
oReg.SetStringValue HKEY_LOCAL_MACHINE,REG_KEY_PATH,"CustomProps2",objModel
oReg.SetStringValue HKEY_LOCAL_MACHINE,REG_KEY_PATH,"CustomProps3",objSerial



'**************************************************************
'* Additional debugging scripts 
'* COMMENT THEM OUT ON PRODUCTION
'**************************************************************
'WScript.Echo "Manufacturer: " & objManufacturer & ", Model: " & objModel & ", Serial: " & objSerial
'delete key
'oReg.DeleteKey HKEY_LOCAL_MACHINE, REG_KEY_PATH

WScript.Quit 

1 个答案:

答案 0 :(得分:0)

在SO中进行简单搜索将为您提供所需的部分。首先,您需要读取一个文件并循环遍历它。

strFilename = "C:\Temp\servers.txt"
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objFile = objFSO .OpenTextFile(strFilename)

Do Until objFile.AtEndOfStream
  ' Read a single line from the file. 
  singleHostname = objFile.ReadLine
  ProcessServer(singleHostname )
Loop

' Close the file and clean up memory
objFile.Close

将脚本的大部分内容转换为名为Sub

ProcessServer
Function ProcessServer(pSingleServer)
   ' Comments and proccessing....
   Set objWMIService = GetObject("winmgmts:\\" & pSingleServer& "\root\CIMV2")
   ' More comments and proccessing....
   Set oReg=GetObject("winmgmts:{impersonationLevel=impersonate}!\\" & pSingleServer& "\root\default:StdRegProv")
   ' Still more comments and proccessing....
End Function

警告

为了简洁起见,我没有努力声明我的变量或执行简单的错误检查,就像文件存在一样。同样,一些简单的搜索可以帮助您解决我强烈建议您解决的问题。