Photo Gallery Member List Search Calendars FAQ Ticket List Log Out


Check to see if program is running, if not...start program

 
Logged in as: Guest
arrSession:exec spGetSession 2,2,41487
 Active Users: There are 0 members and 0 guests.
 Users viewing this topic: none
 

 

 
  
  Printable Version
All Forums >> [Scripting] >> WSH & Client Side VBScript >> Check to see if program is running, if not...start program
  Do you like VisualBasicScript.com? Link to us and help spread the word about our forum. Thanks!
Page: [1]
Login
Message << Older Topic   Newer Topic >>
 Check to see if program is running, if not...start program - 12/28/2006 4:13:14 AM   
  skifiend

 

Posts: 5
Score: 0
Joined: 12/28/2006
Status: offline
New to VBS and this forum so bear with me....

I'm trying to write a script that will run on a thin client.  I want the script to check to see if a terminal server session is running, and if it isn't, to initiate a new one.  Basically I want to make this thin client a station that goes to one website and one website only.  If you close down the TS session, the thin client sees that and fires it back up again.  Any help would be greatly, GREATLY appreciated!
 
 
Post #: 1
 
 RE: Check to see if program is running, if not...start ... - 12/28/2006 4:59:50 AM   
  dm_4ever


Posts: 2721
Score: 46
Joined: 6/29/2006
From: Orange County, California
Status: offline
You should be able to check and start a process using WMI and the Win32_Process class (http://msdn2.microsoft.com/en-us/library/aa394372.aspx).  You should be able to find examples available on that page and by searching this forum for Win32_Process.

_____________________________

dm_4ever

My philosophy: K.I.S.S - Keep It Simple Stupid
Read Me: http://www.visualbasicscript.com/m_24727/tm.htm
Frequently Asked Stuff: http://www.visualbasicscript.com/m_47117/tm.htm

(in reply to skifiend)
 
 
Post #: 2
 
 RE: Check to see if program is running, if not...start ... - 12/28/2006 5:30:20 AM   
  ziminski

 

Posts: 79
Score: 2
Joined: 1/8/2006
Status: offline
I use this to see how long and if it's running, you can change it to restart the process easy enough:
Const OpenFileForReading = 1
Rem *** Variable Initialization ***
Dim strBuffer
intReturnCode = 0
strBuffer = ""
objLogFile = "D:\APPS\SAS\" & Split(WScript.ScriptName, ".")(0) & ".log"
strProcess  = "yourapp.exe"
j = 0
k = 0
Set objFileSystem = CreateObject("Scripting.FileSystemObject")
Set objLogFile = objFileSystem.CreateTextFile(objLogFile, TRUE)
objLogFile.writeline(Now &"********Mon_Process()************SAS*********************" & vbCr )
Call Mon_Process()
Sub new_instance()
strComputer = "."
Set objWMIService = GetObject("winmgmts:" _
   & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
Set colMonitoredProcesses = objWMIService. _       
   ExecNotificationQuery("select * from __instancecreationevent " _
       & " within 1 where TargetInstance isa 'Win32_Process'")
i = 0
Do While i = 0
   Set objLatestProcess = colMonitoredProcesses.NextEvent
   If objLatestProcess.TargetInstance.Name = strProcess Then
    objLogFile.Writeline(strProcess & " Running "  & NOW  & vbCr )
    strBuffer = (strProcess & " started   "  & NOW & vbCr  )
     Mon_Process()
     End If
Loop
End Sub
Sub Mon_Process()

strComputer = "."
Set objWMIService = GetObject("winmgmts:" _
   & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")

Set colProcesses = objWMIService.ExecQuery _
   ("Select * from Win32_Process Where Name =" & strProcess )
   If colProcesses.Count = 0 Then
    j=0
    new_instance()
    Else
For Each objProcess in colProcesses
  sngProcessTime = (CSng(objProcess.KernelModeTime) + CSng(objProcess.UserModeTime)) /10000000
 
   If  objProcess.Name  =  strProcess   Then
    k= k + (sngProcessTime/60)
    'strOut = FormatTime(sngProcessTime)
 objLogFile.Writeline(Now & VBTab & objProcess.Name & " Running " & "With PID " & objProcess.ProcessID  & VbTab & "Kernal CPU TIME" & " " & k & " in Minutes" & VbTab & "j= " & j & vbCr )
 j = j + 1
 
 Else
 objLogFile.Writeline(Now & VBTab & strProcess & " NOT Running " & " "  & j ) 
  End If
  If j <> 15 Then
   'objLogFile.Writeline(Now & VBTab & strProcess & " Sleep " & " "  & j )
   Call Sleep()
   Else
   j = 0
   strBuffer = strBuffer +(objProcess.name & " With PID" & objProcess.ProcessID & VbTab & "CPU Time" & " " & k & "  in Minutes" & vbCr  )
   objLogFile.Writeline("mailing " & strBuffer & vbCr )
    End If
Next
End If
End Sub

(in reply to skifiend)
 
 
Post #: 3
 
 
 
  

If you found our site useful please link to us <a href="http://www.visualbasicscript.com">VisualBasicScript.com</a>.
All Forums >> [Scripting] >> WSH & Client Side VBScript >> Check to see if program is running, if not...start program Page: [1]
Jump to:





New Messages No New Messages
Hot Topic w/ New Messages Hot Topic w/o New Messages
Locked w/ New Messages Locked w/o New Messages
 Post New Thread
 Reply to Message
 Post New Poll
 Submit Vote
 Delete My Own Post
 Delete My Own Thread
 Rate Posts