2015-02-24 43 views
0

我在使用組策略的客戶端上運行各種VBS腳本。在大多數客戶端這工作正常。但是在我的計算機上(我創建腳本的那臺計算機上),啓動計算機後始終運行多個MSE7實例 - 每個通過組策略部署的VBS腳本都有一個實例。啓動我的電腦時打開MSE7的多個實例

任何人都可以幫助我理解爲什麼會發生這種情況和/或如何阻止它!

謝謝。

安德魯

回答

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 
'************************************************************************** 
+0

感謝您的建議。但它並沒有真正回答我的問題,這些問題是(i)爲什麼我只在一臺計算機上遇到相同腳本在所有客戶端上運行時的問題,以及(ii)是否有某種方式可以將腳本修改爲停止發生問題。 – Andrew 2015-02-25 21:05:30