Windows 7 Thread, Script to query if process is running in Technical; Need a script which can query if a process is running (in this case mstsc.exe) and if not then start ...
-
24th August 2011, 04:27 PM #1 Script to query if process is running
Need a script which can query if a process is running (in this case mstsc.exe) and if not then start it - i've used the filter on tasklist before but i can't qgrep on windows 7 as it doesn't work with it.
Code:
tasklist /FI "IMAGENAME eq mstsc.exe" | qgrep mstsc.exe
if ERRORLEVEL 1 (start mstsc.exe C:\rdpfile\studentterminalserver.RDP /f /public) ELSE (goto:EOF)
anybody got another script which will do the same? maybe powershell?
its going to be run on a windows thin pc.
-
-
IDG Tech News
-
24th August 2011, 04:36 PM #2 Just doing it like this "should" work, but might want to test it
Code:
Set WshShell = WScript.CreateObject ("WScript.Shell")
set service = GetObject ("winmgmts:")
pFound = False
for each Process in Service.InstancesOf ("Win32_Process")
If Process.Name = "mstsc.exe" then
pFound = True
End If
next
If pFound = False then
WshShell.Run ("pathblahblah")
end if Steve
-
-
24th August 2011, 04:44 PM #3 it doesn't work! just errors!
-
-
24th August 2011, 04:47 PM #4 
Originally Posted by
glennda
it doesn't work! just errors!
Care to expand? :P On what? Error message?
Steve
-
-
24th August 2011, 04:48 PM #5 the error is expected end on line 14 but if you put end on the end it then is expecting if
-
-
24th August 2011, 04:52 PM #6 You sure it copied right? No error here. And you don't even have a line 14 on my script
Can you paste what you're using.
Steve
-
-
24th August 2011, 04:54 PM #7 Autoit:
Code:
If ProcessExists("notepad.exe") Then
MsgBox(0, "Example", "Notepad is running.")
EndIf
-
-
24th August 2011, 04:57 PM #8 Assuming it exists, you can just use find for the same effect e.g.
tasklist /FI "IMAGENAME eq mstsc.exe" | find /I "mstsc.exe"
if ERRORLEVEL 1 (start mstsc.exe C:\rdpfile\studentterminalserver.RDP /f /public) ELSE (goto:EOF)
There's also findstr that would work, albeit with another switch in front of the search string to say it's a literal.
-
-
24th August 2011, 04:58 PM #9 
Originally Posted by
Steve21
You sure it copied right? No error here. And you don't even have a line 14 on my script

Can you paste what you're using.
Steve
Code:
Set WshShell = WScript.CreateObject ("WScript.Shell")
set service = GetObject ("winmgmts:")
pFound = False
for each Process in Service.InstancesOf ("Win32_Process")
If Process.Name = "mstsc.exe" then
pFound = True
End If
next
If pFound = False then
WshShell.Run ("mstsc.exe C:\rdpfile\studentterminalserver.rdp /f /public")
-
-
24th August 2011, 05:00 PM #10 You're missing the endif
Code:
If pFound = False then
WshShell.Run ("mstsc.exe C:\rdpfile\studentterminalserver.rdp /f /public") Should be:
Code:
If pFound = False then
WshShell.Run ("mstsc.exe C:\rdpfile\studentterminalserver.rdp /f /public")
End If Can you try that?
Steve
-
-
24th August 2011, 05:02 PM #11 
Originally Posted by
Steve21
You're missing the endif
Code:
If pFound = False then
WshShell.Run ("mstsc.exe C:\rdpfile\studentterminalserver.rdp /f /public") Should be:
Code:
If pFound = False then
WshShell.Run ("mstsc.exe C:\rdpfile\studentterminalserver.rdp /f /public")
End If Can you try that?
Steve
may bad - that works!
-
-
24th August 2011, 05:06 PM #12 Shiny shinies 
Steve
-
SHARE: 
Similar Threads
-
By RabbieBurns in forum Scripts
Replies: 4
Last Post: 21st January 2010, 10:49 PM
-
By ful56_uk in forum Scripts
Replies: 7
Last Post: 25th July 2009, 11:45 AM
-
By burgemaster in forum Scripts
Replies: 8
Last Post: 12th June 2009, 02:06 PM
-
By pooley in forum Windows
Replies: 4
Last Post: 5th January 2009, 11:31 AM
-
By tosca925 in forum Scripts
Replies: 3
Last Post: 1st March 2006, 12:08 PM
Thread Information
Users Browsing this Thread
There are currently 1 users browsing this thread. (0 members and 1 guests)
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules