How to check vbs script on windows works or not?

I created a vbs script in windows .... I ran this script to get the file size.

I made it run forever. (even this is my requirement).

But should I know that it is running or stopped?

But I need to check if it works or not?

How can I check this out?

------ Exact Script starts here ----- 
Set FSO = CreateObject("Scripting.FileSystemObject") 
Set FSO_check=CreateObject("Scripting.FileSystemObject") 
do while infiniteLoop=0     
----- This code is lasting for ever ----
Loop

How can I answer my questions?

+5
source share
4 answers

How about using a command line property? I think this requires Windows XP and above.

For instance:

Set objSWbemServices = GetObject ("WinMgmts:Root\Cimv2") 
Set colProcess = objSWbemServices.ExecQuery _ 
("Select * From Win32_Process where name = 'wscript.exe'") 
For Each objProcess In colProcess 
    WScript.Echo objProcess.Name, _ 
    objProcess.ProcessId, _ 
    objProcess.CommandLine 
Next
+3
source
Answer to

@nimizen is incorrect. If you have another wscript run, it will return that your script is already running.

@h pic , "a" . .

Set objWMIService = GetObject("winmgmts:{impersonationLevel=impersonate}!\\.\root\cimv2")
Set colProcesses = objWMIService.ExecQuery("select * from win32_process where name = 'wscript.exe'")

i = 0
For Each objProcess in colProcesses
    if not (IsNull(objProcess.CommandLine )) then
            strScriptName = Trim(Right(objProcess.CommandLine,Len(objProcess.CommandLine) - InstrRev(objProcess.CommandLine,"\")))
            strScriptName = Left(strScriptName, Len(strScriptName) - 1)                             
            if strScriptName = Wscript.ScriptName then
                i=i+1
            end if
            if i > 1 then 'if > 1 wscript instance
                    'Wscript.Echo "Duplicate :"&strScriptName&" ."
                    Wscript.Quit
            end if  
    end if  
Next

'Wscript.Echo "Pause 2 have 2 scripts running ."
+1

Hmm, , script, , , , . , , , , WMI . , . , WScript , .

MS Sysinternals Process Explorer http://technet.microsoft.com/en-us/sysinternals/bb896653 . , script , script.

script script. , script. , , , . script , , script .

, , script . , , , , script .

, script script Exec(), ProcessID script, , ProcessID , .

Set oExec = WshShell.Exec( "infinite.vbs" )
MyProcessID = oExec.ProcessID ' procID of shell'd program. 
set oExec = Nothing

and do something with MyProcessID

VBScript

Exec() HTA script, ProcessID WMI, WMI "ProcessID", script, Exec() WMI. - HTA , WMI .

Dim iMyPID : iMyPID = GetObject("winmgmts:root\cimv2").Get("Win32_Process.Handle='" & CreateObject("WScript.Shell").Exec("mshta.exe").ProcessID & "'").ParentProcessId 

, , - , , script. , ", ", . , , , , . TheFolderSpy http://venussoftcorporation.blogspot.com/2010/05/thefolderspy.html, , .

sleep , . . FSO, , script .

, , , . , WScript.Sleep 200 , , . , , , 10 .

0

script, / . , , , .
. wxcripts - .

... , , wscript script, , .

function duplicate_check        

'if two scripts get here at the same time - stagger when the generate _
    'the list of running processes _
    'ie - give 1 of them time to close
    'else they can both quit leaving no more scripts running
call random_script_sleep(2500,500)

dim myfilename
myfilename = Wscript.ScriptName 

strComputer = "." 
Set objWMIService = GetObject("winmgmts:{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
Set colProcesses = objWMIService.ExecQuery("select * from win32_process")

'fill arrary w/ all running script names
i = 0
For Each objProcess in colProcesses 
    If objProcess.Name = "wscript.exe" Then
        strScriptName = Trim(Right(objProcess.CommandLine,Len(objProcess.CommandLine) - InstrRev(objProcess.CommandLine,"\")))
        strScriptName = Left(strScriptName, Len(strScriptName) - 1)                             
        a(i)= strScriptName         '           
        i=i+1   
    end if          
Next

'kill script if already running w/ same name
if i > 1 then 'if > 1 wscript instance
    for s = 0 to i
        if a(s) = myfilename then
            wscript.quit
        end if
    next
end if

'sometimes duplicate check fails, if so, write to error log
If Err.Number = 1 Then
    error_notes = " @duplicate check, firstdupcheck(0/1):" & firstdupcheck
    call error_log
    error_notes = "error undefined" 
end if

' if debugmsg = 1 then CreateObject("WScript.Shell").Popup _
    ' "found this many scripts: " & i & vbCrlf & _
    ' "<>" & i & vbCrlf & _
    ' ", 1, "debug popup"   

end function  
0

All Articles