0

我正在使用组策略在我们的客户端上运行各种 VBS 脚本。在大多数客户端上,这工作正常。但是在我的计算机(我创建脚本的那个)上,我总是在启动我的计算机后运行多个 MSE7 实例——一个用于我通过组策略部署的每个 VBS 脚本。

谁能帮我理解为什么会发生这种情况和/或如何阻止它!

谢谢。

安德鲁

4

1 回答 1

1

使用此脚本,您可以通过其命令行找到任何进程并选择终止它们。试一试!

Option Explicit
Dim Titre,Copyright,fso,ws,NomFichierLog,temp,PathNomFichierLog,OutPut,Count
If AppPrevInstance() Then 
    MsgBox "There is an existing proceeding !" & VbCrLF & CommandLineLike(WScript.ScriptName),VbExclamation,"There is an existing proceeding !"    
    WScript.Quit   
Else 
Copyright = "[© Hackoo © 2015 ]"
Set fso = CreateObject("Scripting.FileSystemObject")
Set ws = CreateObject( "Wscript.Shell" )
NomFichierLog="Killed_Process.txt"
temp = ws.ExpandEnvironmentStrings("%temp%")
PathNomFichierLog = temp & "\" & NomFichierLog
Set OutPut = fso.CreateTextFile(temp & "\" & NomFichierLog,1)
    Call Find("wscript.exe")
    Call Explorer(PathNomFichierLog)
End If
'***************************************************************************************************
Function Explorer(File)
    Dim ws
    Set ws = CreateObject("wscript.shell")
    ws.run "Explorer "& File & "\",1,True
end Function
'***************************************************************************************************
Sub Find(MyProcess)
    Dim colItems,objItem,Processus,Question
    Titre = " Process "& DblQuote(MyProcess) &" running "
    Set colItems = GetObject("winmgmts:").ExecQuery("Select * from Win32_Process " _
    & "Where Name like '%"& MyProcess &"%' AND NOT commandline like " & CommandLineLike(WScript.ScriptFullName) & "",,48)
    Count = 0 
    For Each objItem in colItems
        Count= Count + 1
        Processus = objItem.CommandLine
        Question = MsgBox ("Would do you like to kill this script : " & DblQuote(Processus) & " ?" ,VBYesNO+VbQuestion,Titre+Copyright)
        If Question = VbYes then
            objItem.Terminate(0)'To kill the process
            OutPut.WriteLine Processus
        else
            Count= Count - 1 'decrementing the count of -1
        End if
    Next
OutPut.WriteLine String(100,"*")
OutPut.WriteLine count & Titre & "were killed"
OutPut.WriteLine String(100,"*") & VbCrLF 
End Sub
'**************************************************************************
Function DblQuote(Str)
    DblQuote = Chr(34) & Str & Chr(34)
End Function
'**************************************************************************
Function AppPrevInstance()   
    With GetObject("winmgmts:" & "{impersonationLevel=impersonate}!\\.\root\cimv2")   
        With .ExecQuery("SELECT * FROM Win32_Process WHERE CommandLine LIKE " & CommandLineLike(WScript.ScriptFullName) & _
            " AND CommandLine LIKE '%WScript%' OR CommandLine LIKE '%cscript%'")   
            AppPrevInstance = (.Count > 1)   
        End With   
    End With   
End Function    
'**************************************************************************
Function CommandLineLike(ProcessPath)   
    ProcessPath = Replace(ProcessPath, "\", "\\")   
    CommandLineLike = "'%" & ProcessPath & "%'"   
End Function
'**************************************************************************
于 2015-02-24T13:41:26.260 回答