2015-06-10 29 views
1

順便說一句,我有一個消息框,當你點擊ok-這是唯一的選項時,它會重複自己。
我的代碼:VBS-我可以退出無需轉至任務管理器或cmd而自行重複的VBS消息框嗎?

'Very Annoying script' 
Set objShell = CreateObject("Wscript.Shell") 

intMessage = Msgbox("Click ok to say yes",16, "Is this messagebox annoying?") 

If intMessage = vbOK Then 
    RETRY 
Else 
Wscript.Quit 
End If 
SUB RETRY 
'Very Annoying script' 
Set objShell = CreateObject("Wscript.Shell") 

intMessage = Msgbox("Click ok to say yes",16, "Is this messagebox annoying?") 

If intMessage = vbOK Then 
    RETRY 
Else 
Wscript.Quit 
End If 
End sub 

我可以結束不結束基於腳本宿主「標記Micorosft的Windows的過程中下面的腳本? 包括沒有運行CMD線(它不會工作)

taskkill /im wscript.exe 

OR

將任務管理器。

+0

這真的很煩人,必須進入任務管理器並刪除每一個進程。 – RookieTEC9

+0

另外,我完全不理解你。 '你是什麼意思'爲什麼告訴我們你真正想要什麼,作爲一個用戶' – RookieTEC9

+0

抱歉,爲什麼不告訴我們你想要什麼,作爲一個用戶 –

回答

1

如果您使用此命令taskkill /IM wscript.exe /F;你殺死了所有正在運行的vbscript,但是 如果你有很多循環中有不同路徑的正在運行的腳本,你可以使用這個vbscript來選擇哪一個被殺死或不是。所以這個腳本的目的是選擇和聚焦到您想要殺死的進程,並且您還可以將其保存在日誌文件中。 只是試一試;)

Option Explicit 
Dim Titre,Copyright,fso,ws,NomFichierLog,temp,PathNomFichierLog,OutPut,Count,strComputer 
If AppPrevInstance() Then 
    MsgBox "Il y a une instance déjà en cours" & VbCrLF & CommandLineLike(WScript.ScriptName),VbExclamation,"Il y a une instance déjà en cours"  
    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) 
strComputer = "." 
    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 = " Processus "& DblQuote(MyProcess) &" en cours d'exécution " 
    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 = Mid(objItem.CommandLine,InStr(objItem.CommandLine,""" """) + 2) 'Extraction du chemin du script en ligne de commande 
     Processus = objItem.CommandLine 'Replace(Processus,chr(34),"") 
     Question = MsgBox ("Voulez-vous arrêter ce script : " & DblQuote(Processus) & " ?" ,VBYesNO+VbQuestion,Titre+Copyright) 
     If Question = VbYes then 
      objItem.Terminate(0)'Tuer ce processus 
      OutPut.WriteLine Processus 
     else 
      Count= Count - 1 'décrementer le compteur de -1 
     End if 
    Next 
OutPut.WriteLine String(100,"*") 
OutPut.WriteLine count & Titre & "ont été arrêtés" 
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 
'************************************************************************** 
Sub Pause(Minutes)  
    Wscript.Sleep(Minutes*1000*60)  
End Sub 
'************************************************************************** 
Function StripProcPath(ProcessPath) 
    Dim arrStr : arrStr = Split(ProcessPath, "\") 
    StripProcPath = arrStr(UBound(arrStr)) 
End Function 
'************************************************************************** 
Function CommandLineLike(ProcessPath) 
    ProcessPath = Replace(ProcessPath, "\", "\\") 
    CommandLineLike = "'%" & ProcessPath & "%'" 
End Function 
'************************************************************************** 
+0

這真的很酷。謝謝。你知道一個互聯網的來源,我可以學習更多的VBS嗎? – RookieTEC9

2

只有這樣,才能做最終的腳本是用

taskkill /f /im wscript.exe 


其他然後,它會簡單地重新運行腳本(如當你只是簡單地點擊OK效果相同)

謝謝蔣YD回答