Skip to content

Instantly share code, notes, and snippets.

@askvictor
Created July 22, 2013 00:02
Show Gist options
  • Save askvictor/6050477 to your computer and use it in GitHub Desktop.
Save askvictor/6050477 to your computer and use it in GitHub Desktop.
Due to the Papercut client crashing on some network conditions, the script can be triggered off Windows event ID 10000 to check if the client is connected to the work network. If so, and the papercut client isn't running, this will re-launch it.
'Trigger off event ID 10000 (Network Connected) to check if we're on the papercut network, and if
'PaperCut client is running. If it's not, try to start it.
strSearchSuffix = "REPLACE_WITH_DOMAIN_SUFFIX_TO_CHECK"
strFindProcessName = "pc-client.exe"
wscript.sleep 5000 'sleep 5 seconds to allow network to configure
Set objWMIService = GetObject("winmgmts:{impersonationLevel=impersonate}!\\.\root\cimv2")
Set objShell = CreateObject("WScript.Shell")
Set colNetCards = objWMIService.ExecQuery _
("Select DNSDomainSuffixSearchOrder From Win32_NetworkAdapterConfiguration")
boolInNetwork = false
For Each objNetCard in colNetCards
arrDNSDomainSuffixSearchOrder = objNetCard.DNSDomainSuffixSearchOrder
If Not IsNull(arrDNSDomainSuffixSearchOrder) Then
for each strDNSSuffix in arrDNSDomainSuffixSearchOrder
if instr(strDNSSuffix, strSearchSuffix) then
boolInNetwork = true
end if
next
End If
Next
if boolInNetwork then
for each Process in objWMIService.InstancesOf ("Win32_Process")
If Process.Name = strFindProcessName then
'wscript.echo "PaperCut running"
wscript.quit
end if
next
'wscript.echo "Papercut not running"
objShell.Run "\\REPLACE_WITH_PRINT_SERVER\PCClient\win\pc-client-local-cache.exe", 2, false
end if
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment