Home > service-is-programming, sourcecode > How to force-stop Sanako Student using VbScript and WMI

How to force-stop Sanako Student using VbScript and WMI

We have been experiencing issues with the Sanako student becoming unresponsive in the Language Lab. This utility resets the student on the student computer:

'on error resume next
Const HKEY_LOCAL_MACHINE = &H80000002
arrComputers = Array("LSS-NWX13PC06") 'update this thru scriptomatic.hta strComputer = "LSS-NWX13PC06" '01<-fails, 03<- works,
'Service Name
SrvName = "Sanako Helper" 'which format? example imapiservice is not in win xp services.msc
'Process Name
'ProcessName ="Student.exe" 'überflüssig

For Each strComputer  In arrComputers
'restart helper.exe
For Each strService In GetObject("winmgmts:{impersonationLevel=impersonate}!\\" & strComputer).InstancesOf ("win32_service")
'   Set objWMIService = GetObject("winmgmts:{impersonationLevel=Impersonate}!\\" & strComputer & "\root\CIMV2")
'   Set colItems = objWMIService.ExecQuery("SELECT * FROM Win32_Service", "WQL", wbemFlagReturnImmediately + wbemFlagForwardOnly)

If strService.Name = SrvName Then
If strService.State = "Running" Then
WScript.echo "Shutting down '" & strService.Name & "' Service"
wscript.sleep 5000
WScript.echo "ReStarting '" & strService.Name & "' Service"
wscript.echo "Starting '" & strService.Name & "' Service"
End If
End If
Next 'service

'restart student.exe
'find path for starting
Set objRegistry = GetObject("winmgmts:{impersonationLevel=impersonate}!\\" & strComputer & "\root\default:StdRegProv")

'tutor [HKEY_LOCAL_MACHINE\SOFTWARE\Sanako\Setup]   "RootDir" "C:\\Program Files\\Sanako"
'student: HKEY_LOCAL_MACHINE\SOFTWARE\Sanako\Shared Components\CMC ClientModuleLocation C:\Program Files\Sanako\Study\Student
'student: HKEY_LOCAL_MACHINE\SOFTWARE\Sanako\Study\Student\Settings InstallPath C:\Program Files\Sanako\Study\Student
strKeyPath = "HKEY_LOCAL_MACHINE\SOFTWARE\Sanako\Study\Student\Settings"
strValueName = "InstallPath"
objRegistry.GetStringValue HKEY_LOCAL_MACHINE,strKeyPath,strValueName,strValue 'GetDWORDValue method is not needed
WScript.echo "Registry BaseDir is '" & strValue & "'"

If IsNull(strValue) Then 'Empty means that the registry value exists, but is blank; Null means that the registry value doesn’t exist.
strStudentCommandline = "C:\Program Files\Sanako\Study\Student\Student.exe" 'todo: notbehelf
strStudentCommandline = strValue & "\Study\Student\Student.exe"
End If
WScript.echo "strStudentCommandline is '" & strStudentCommandline & "'"

'do you have to do the same for vieostreamer window?

For Each strProcess In GetObject("winmgmts:{impersonationLevel=impersonate}!\\" & strComputer).InstancesOf ("win32_process")
'   Set objWMIProcess = GetObject("winmgmts:{impersonationLevel=Impersonate}!\\" & strComputer & "\root\CIMV2")
'   Set colItems = objWMIProcess.ExecQuery("SELECT * FROM Win32_Process", "WQL", wbemFlagReturnImmediately + wbemFlagForwardOnly)

If strProcess.CommandLine = strStudentCommandline Then
WScript.echo "Terminating '" & strProcess.CommandLine & "'"
wscript.sleep 5000
End If

'todo: remote
' you shoule be able to do this without a shell using .Create(CommandLine)
'todo: Processes launched by WMI can NEVER be visible. They run in their own windowstation, the same as window services.
'It make it visible you have to have a System Tray application or similar hidden application which is launched when each desktop starts. Then you have to setup some kind of IPC/RPC between the system tray app and your
'the problem is that i restart the student.exe under my credentials, but would have to do it under the logged in student credentials
set WshShell = WScript.CreateObject("WScript.Shell")
Ret = WshShell.Run(strStudentCommandline, 3, True) 'bWaitOnReturn Optional. Boolean value indicating whether the script should wait for the program to finish executing before continuing to the next statement in your script. If set to true, script execution halts until the program finishes, and Run returns any error code returned by the program. If set to false (the default), the Run method returns immediately after starting the program, automatically returning 0 (not to be interpreted as an error code
'error checking
If ret <> 0 then
wscript.echo "error starting "&  strStudentCommandline
WScript.echo "Starting '" & strStudentCommandline & "' Process"
End if
Next 'process running
Next 'strComputer

UPDATE: I haven now also coded  a similar utility in AutoIt, hopefully easier to use.

  1. No comments yet.
  1. No trackbacks yet.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.

%d bloggers like this: