2016-03-20 12 views
0
MsgBox ("Do you want to start the autoclicker?", vbOkOnly, "Autoclicker") 
CreateObject("WScript.Shell").Run("""C:\Users\Henry\Desktop\Fun.vbs""") 
MsgBox ("Do you want to stop the autoclicker?", vbOkOnly, "Autoclicker") 
+1

より良いコード形式:

はだから、試してみてください。コードの意図された使用についてのより長い説明が役に立つでしょう。 –

答えて

0
Set objWMIService = GetObject("winmgmts:{impersonationLevel=impersonate}!\\.\root\cimv2") 

Set colItems = objWMIService.ExecQuery("Select * From Win32_Process") 

For Each objItem in colItems 
    'msgbox objItem.ProcessID & " " & objItem.CommandLine 
    If objItem.name = "Calculator.exe" then objItem.terminate 
Next 

これはcalculator.exeを殺します。それをwscript.exeに変更します。 fun.vbsを殺すだけなら、コマンドラインをチェックしたいかもしれません。

+0

本当にありがとう – Jontzjr

0

次のルーチンは、コマンドラインに指定された文字列が含まれるすべてのプロセスを強制終了します。ルーチンの下の3行は、それをテストするための行です。メッセージボックスを表示してルーチンを一時停止し、メッセージボックスを閉じるとスクリプトインスタンスが終了するので、2番目のメッセージボックスは表示されません。あなたはそれを使用するときは、私はこれを使用して注意すると必ず、私は絶対に、積極的にプロセスだけを一致させることができるよう、コマンドラインの限りを指定したい

KillProcesses "Fun.vbs" 

で最後の3行を交換したいI終了したい。タスクマネージャを変更し、実行中のプロセスごとにコマンドラインを表示する列を追加することができます。以下のルーチンでは、コマンドラインでの検索で大文字と小文字を区別しません。

Option Explicit 

Sub KillProcesses(strPartOfCommandLine) 
    Dim colProcesses 
    Dim objProcess 
    Dim lReturn 


    ' Get list of running processes using WMI 
    Set colProcesses = GetObject("winmgmts:\\.\root\cimv2").ExecQuery("Select * From Win32_Process") 

    For Each objProcess in colProcesses 
     If (Instr(1, objProcess.Commandline, strPartOfCommandLine, vbTextCompare) <> 0) Then 
      lReturn = objProcess.Terminate(0) 
     End If 
    Next 
End Sub 

Msgbox "Before being killed" 
KillProcesses "KillProcesses.vbs" 
Msgbox "After being killed" 
0

私はあなたに何のvbscriptを殺して結果をファイルに記録するかを尋ねるスクリプトの前に作った。

Option Explicit 
Dim Titre,Copyright,fso,ws,NomFichierLog,temp,PathNomFichierLog,OutPut,Count,strComputer 
Copyright = "[© Hackoo © 2014 ]" 
Titre = " Process "& DblQuote("Wscript.exe") &" running " 
Set fso = CreateObject("Scripting.FileSystemObject") 
Set ws = CreateObject("Wscript.Shell") 
NomFichierLog="Process_WScript.txt" 
temp = ws.ExpandEnvironmentStrings("%temp%") 
PathNomFichierLog = temp & "\" & NomFichierLog 
Set OutPut = fso.CreateTextFile(temp & "\" & NomFichierLog,1) 
Count = 0 
strComputer = "." 
Call Find("wscript.exe") 
Call Explorer(PathNomFichierLog) 
'*************************************************************************************************** 
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 
    Set colItems = GetObject("winmgmts:").ExecQuery("Select * from Win32_Process " _ 
    & "Where Name like '%"& MyProcess &"%' AND NOT commandline like '%" & wsh.scriptname & "%'",,48) 
    For Each objItem in colItems 
     Count= Count + 1 
     Processus = Mid(objItem.CommandLine,InStr(objItem.CommandLine,""" """) + 2) 'Extraction of the commandline script path 
     Processus = Replace(Processus,chr(34),"") 
     Question = MsgBox ("Did you want to stop this script : "& DblQuote(Processus) &" ?" ,VBYesNO+VbQuestion,Titre+Copyright) 
     If Question = VbYes then 
      objItem.Terminate(0)'Kill this process 
      OutPut.WriteLine DblQuote(Processus) 
     else 
      Count= Count - 1 'decrement the counter -1 
     End if 
    Next 
OutPut.WriteLine String(100,"*") 
OutPut.WriteLine count & Titre & " were stopped !" 
End Sub 
'********************************************************************************************** 
Function DblQuote(Str) 
    DblQuote = Chr(34) & Str & Chr(34) 
End Function 
'********************************************************************************************** 
関連する問題