Vbs help

Associate
Joined
26 Apr 2006
Posts
706
Hi all,

Hopefully someone can help as I am a complete vbs noob.

We have an issue at the moment with Skype for business (Lync.exe) crashing. As a "work around" (until we find the solution) we need a vbs script that:

1 checks if Lync.exe is running.
2 if Lync is running wait 30 seconds and check again.
3 if Lync.exe is not running wait 15 seconds and check if explorer.exe is running.
4 if explorer.exe is running - restart Lync and loop to beginning
5 if explorer.exe isn't running quit script

The check for explorer running is invade the user is shutting down.

Hopefully that makes sense and someone can help.

Thanks
 
You need to at least try, look up vba or vbscript and wmi.

You can check a process using a wmi query which is sql like:

So something like Set x = getobject("WMIsomethingsomething").ExecQuery("SELECT * FROM Win32_Process WHERE Name = '" & lync.exe & "'")

If x.count >0 then return something a boolean probably

You will have to think about how to implement a timer.
 
well after quite a bit of trial and error,

this is what i came up with :

Set WshShell = CreateObject("WScript.Shell")
WScript.Sleep 13000
strComputer = "."
Set objWMIService = GetObject("winmgmts:" _
& "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
Set colProcesses2 = objWMIService.ExecQuery _
("Select * from Win32_Process Where Name = 'notepad.exe'")

Do While colProcesses2.Count>0
WScript.Sleep 3000
Set objWMIService = GetObject("winmgmts:" _
& "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
Set colProcesses2 = objWMIService.ExecQuery _
("Select * from Win32_Process Where Name = 'notepad.exe'")



Set objWMIService = GetObject("winmgmts:" _
& "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
Set colProcesses = objWMIService.ExecQuery _
("Select * from Win32_Process Where Name = 'lync.exe'")


If colProcesses.Count = 1 Then
Wscript.Echo "Lync is running."

Else
Wscript.Echo "Lync is not running."
WshShell.Run chr(34) & "launchlync.bat" & Chr(34), 0
End If
LOOP

I certain it will not be the best bit of coding, but it does seem to work
 
Back
Top Bottom