Jump to content

Recommended Posts

Posted

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.

 

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.

Posted

Just doing it like this "should" work, but might want to test it

 

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

Posted

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.

Posted
You sure it copied right? No error here. And you don't even have a line 14 on my script :D Can you paste what you're using.

 

Steve

 

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")

Posted

You're missing the endif

 

If pFound = False then
WshShell.Run ("mstsc.exe C:\rdpfile\studentterminalserver.rdp /f /public")

 

Should be:

 

If pFound = False then
WshShell.Run ("mstsc.exe C:\rdpfile\studentterminalserver.rdp /f /public")
End If

 

Can you try that?

 

Steve

Posted
You're missing the endif

 

If pFound = False then
WshShell.Run ("mstsc.exe C:\rdpfile\studentterminalserver.rdp /f /public")

 

Should be:

 

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!

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now



×
×
  • Create New...