检查脚本是否已在特定计算机上运行过?

时间:2011-08-08 18:04:55

标签: vbscript

所以我在用户使用组策略中的注销脚本部分注销时运行以下scipt(我想运行检查以查看它是否已在特定计算机上运行过。如果已运行在我希望脚本退出之前。如果没有,那么我希望它运行脚本并将自己标记为“已经运行”。我该怎么做?):

strComputer = "." Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")

Set colInstalledPrinters =  objWMIService.ExecQuery _
    ("Select * from Win32_Printer Where Network = TRUE")

For Each objPrinter in colInstalledPrinters
    objPrinter.Delete_ Next

1 个答案:

答案 0 :(得分:1)

我明白了。这是经过修改的脚本:

Option Explicit

Dim oShell,strComputer,objWMIService,colInstalledPrinters,objPPrinter

Private Function KeyExists (keyName)
    Dim bKey

    On Error Resume Next

    bKey = oShell.RegRead(keyName)

    If TypeName (bKey) = "Empty" Then
        KeyExists = False
    Else
        KeyExists = True
    End If
End Function



Set oShell = CreateObject("Wscript.Shell")

If keyExists("HKEY_LOCAL_MACHINE\Software\CRusse\RemovePrinters") Then
    wscript.quit
Else 

strComputer = "."
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")

Set colInstalledPrinters =  objWMIService.ExecQuery _
    ("Select * from Win32_Printer Where Network = TRUE")

For Each objPrinter in colInstalledPrinters
    objPrinter.Delete_
Next
    oshell.RegWrite "HKEY_LOCAL_MACHINE\Software\CRusse\RemovePrinters", 1, "REG_SZ"
End If

Set oShell = Nothing