g00fy 0 Posted May 7, 2010 Hi, I just found out that on some machines this script fails due to the memory limitation, help would be appreciated My GV 1480 gets down once in a few days, so I had to keep watching it if it's running ok. Sometimes it took me few hours to notice that the app is down (I don't know why rly -> some exceptions). so I made a small vbs script that will keep my GV system running. here it is 'leave localhost if local computer, else you need to make shure you have sufficient rights ro run the process -> see runas strComputer = "localhost" 'the executable application withouth path strCommand = "notepad.exe" 'the path to executable - must end with backslash "\" strPath = "" 'creditentials for the remote user strUsername = "" strPassword = "" 'the time for app to execute in ms, leave 60 or more so you won't have two instances of the app running intIntTime = 60000 'the interval intLoopTime = 1000 'memory limit in MB intMemoryLimit = null 'verbose output boolVerbose = True On Error Resume Next Set objLocator = CreateObject("WbemScripting.SWbemLocator") Set objWMI = objLocator.ConnectServer(strComputer, "root", strUsername, strPassword) Set quota = objWMI.Get("__providerhostquotaconfiguration=@") If intMemoryLimit Then quota.MemoryPerHost = 1024*1024*intMemoryLimit quota.put_() End If Set objWMIService = objLocator.ConnectServer(strComputer, "root\cimv2", strUsername, strPassword) 'Set objWMIService = GetObject("winmgmts:" & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2") Set objProcess = objWMIService.Get("Win32_Process") Set objStartup = objWMIService.Get("Win32_ProcessStartup") Set objConfig = objStartup.SpawnInstance_ ' Object ref objConfig.ShowWindow = SW_NORMAL objConfig.CreateFlags = CREATE_BREAKAWAY_FROM_JOB objConfig.ErrorMode = No_Alignment_Fault_Except Do While True Set colProcesses = objWMIService.ExecQuery( "Select * from Win32_Process " & "Where Name = '" & strCommand &"'") If colProcesses.count = 0 Then errReturn = objProcess.Create(strPath & strCommand, strPath, objConfig, intProcessID) If errReturn = 0 AND not boolVerbose Then Wscript.Echo strCommand & " was started with a process ID: " & intProcessID ElseIf not boolVerbose Then Wscript.Echo strCommand &" could not be started due to error: " & errReturn End If WScript.Sleep(intIntTime) End If WScript.Sleep(intLoopTime) Loop save this as a *.vbs file and add to your autostart. this is an example with notepad app, you need to change proper settings. also you can youse this script ro run gv from a remote machine when it is down -> strComputer = "." strCommand = "notepad.exe" strPath = "C:\Windows\System32\" Set objWMIService = GetObject("winmgmts:" & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2") Set objProcess = objWMIService.Get("Win32_Process") errReturn = objProcess.Create(strPath & strCommand, null, null, intProcessID) If errReturn = 0 Then Wscript.Echo "App was started with a process ID: " & intProcessID Else Wscript.Echo "App could not be started due to error: " & errReturn End If you only need to have sufficient right, you can always use runas to obtain them. HTH Share this post Link to post Share on other sites
rory 0 Posted May 8, 2010 You might be better off using Scheduled Tasks to run the script .. like every hour or x amount of time. But I think the more important issue is to find out why the Geo server is crashing. Have you checked event logs, etc? Additionally, as to the script code itself, that could be done alot simpler. In the case of GeoVision there is no need to check whether it is running .. it only allows one instance: Dim shell On Error Resume Next Const interval = 60 'in minutes while err = 0 Set shell = CreateObject("WScript.Shell") shell.Run ""C:\GV800\GV800.exe"" Set shell = Nothing WScript.Sleep ((interval*60)*1000) Wend but if you really want to check ... Option Explicit Const app_exe = "GV800.exe" Const app_path = "C:\GV800\" Const interval = 60 'in minutes Dim shell On Error Resume Next while err = 0 Call CheckApp WScript.Sleep ((interval*60)*1000) Wend Sub CheckApp() If Not IsRunning Then Set shell = CreateObject("WScript.Shell") shell.Run """" & app_path & app_exe & """" Set shell = Nothing End If End Sub Function IsRunning() IsRunning = GetObject("winmgmts:").ExecQuery _ ("Select Name from Win32_Process Where Name = '" & app_exe & "'").Count > 0 End Function Share this post Link to post Share on other sites
rory 0 Posted May 8, 2010 additionally you could send an email to alert you when it has to reset the DVR: Const MAIL_FROM = "geo@dvr.com" Const MAIL_TO = "you@admin.com" Const MAIL_SUBJECT = "BOB'S GEO DVR RESET" Const MAIL_MESSAGE = "The Geovision DVR at Bob's business has been reset." Const SMTP_SERVER = "smtp.myserver.com" Const SMTP_PORT = 25 Call Send_Mail Sub Send_Mail() DIM objMessage, objConfig, Flds On Error Goto 0: On Error Resume Next SET objMessage = CreateObject("cdo.message") SET objConfig = CreateObject("cdo.configuration") SET Flds = objConfig.Fields Flds.Item("http://schemas.microsoft.com/cdo/configuration/sendusing") = 2 Flds.Item("http://schemas.microsoft.com/cdo/configuration/smtpserver") = SMTP_SERVER Flds.Item("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = SMTP_PORT Flds.Update SET objMessage.Configuration = objConfig objMessage.FROM = MAIL_FROM objMessage.To = MAIL_TO objMessage.Subject = MAIL_SUBJECT objMessage.TextBody = MAIL_MESSAGE objMessage.Fields.Update objMessage.Send SET objMessage = NOTHING SET objConfig = NOTHING If Err = 0 Then MsgBox "MAIL SENT OKAY" Else MsgBox "MAIL SEND ERROR:" & vbCrLf & Err.Description End If End Sub so could be something like: If Not IsRunning Then Set shell = CreateObject("WScript.Shell") shell.Run """" & app_path & app_exe & """" Set shell = Nothing Wscript.Sleep 10000 'wait 10 seconds for exe to load 'check if it is running now .. If IsRunning Then Call Send_Mail 'Send Email Reset Message Else 'Send Email Error Message instead End If End If Share this post Link to post Share on other sites
g00fy 0 Posted May 8, 2010 Where do I check the event logs? If you mean the event logs in Administrtative Tools, then there is nothing there. Share this post Link to post Share on other sites
g00fy 0 Posted May 8, 2010 thnx rory, but still I don't know what causes the system going down btw this is the code for gmail account: Const MAIL_FROM = "yourusername@gmail.com" Const MAIL_TO = "yourusername@gmail.com" Const MAIL_SUBJECT = "GEOVISION DVR RESET" Const MAIL_MESSAGE = "The Geovision DVR has been reset." Const SMTP_SERVER = "smtp.gmail.com" Const SMTP_PORT = 465 Const SMTP_USERNAME = "yourusername@gmail.com" Const SMTP_PASSWORD = "***************" Const SMTP_AUTH = True Const SMTP_SSL = True Const SMTP_TIMEOUT = 60 Const app_exe = "GV1480.exe" Const app_path = "C:\GV-1480\" Const interval = 60 'in minutes Call Send_Mail Sub Send_Mail() Const cdoSendUsingPickup = 1 'Send message using the local SMTP service pickup directory. Const cdoSendUsingPort = 2 'Send the message using the network (SMTP over the network). Const cdoAnonymous = 0 'Do not authenticate Const cdoBasic = 1 'basic (clear-text) authentication Const cdoNTLM = 2 'NTLM Set objMessage = CreateObject("CDO.Message") objMessage.Subject = MAIL_SUBJECT objMessage.From = MAIL_FROM objMessage.To = MAIL_TO objMessage.TextBody = MAIL_MESSAGE '==This section provides the configuration information for the remote SMTP server. objMessage.Configuration.Fields.Item _ ("http://schemas.microsoft.com/cdo/configuration/sendusing") = 2 'Name or IP of Remote SMTP Server objMessage.Configuration.Fields.Item _ ("http://schemas.microsoft.com/cdo/configuration/smtpserver") = SMTP_SERVER 'Type of authentication, NONE, Basic (Base64 encoded), NTLM objMessage.Configuration.Fields.Item _ ("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate") = cdoBasic 'Your UserID on the SMTP server objMessage.Configuration.Fields.Item _ ("http://schemas.microsoft.com/cdo/configuration/sendusername") = SMTP_USERNAME 'Your password on the SMTP server objMessage.Configuration.Fields.Item _ ("http://schemas.microsoft.com/cdo/configuration/sendpassword") = SMTP_PASSWORD 'Server port (typically 25) objMessage.Configuration.Fields.Item _ ("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = SMTP_PORT 'Use SSL for the connection (False or True) objMessage.Configuration.Fields.Item _ ("http://schemas.microsoft.com/cdo/configuration/smtpusessl") = SMTP_SSL 'Connection Timeout in seconds (the maximum time CDO will try to establish a connection to the SMTP server) objMessage.Configuration.Fields.Item _ ("http://schemas.microsoft.com/cdo/configuration/smtpconnectiontimeout") = 60 objMessage.Configuration.Fields.Update '==End remote SMTP server configuration section== objMessage.Send End Sub Dim shell On Error Resume Next while err = 0 Call CheckApp WScript.Sleep ((interval*60)*1000) Wend Sub CheckApp() If Not IsRunning Then Set shell = CreateObject("WScript.Shell") shell.Run """" & app_path & app_exe & """" Set shell = Nothing Wscript.Sleep 10000 'wait 10 seconds for exe to load 'check if it is running now .. If IsRunning Then Call Send_Mail 'Send Email Reset Message Else 'Send Email Error Message instead End If End If End Sub Function IsRunning() IsRunning = GetObject("winmgmts:").ExecQuery _ ("Select Name from Win32_Process Where Name = '" & app_exe & "'").Count > 0 End Function Share this post Link to post Share on other sites