Jump to content

Need help with VBScript

dushtin

Hello!

 

I have a 2 scripts that I use to make Splashtop (remote support software) do a few things that I require.  First, my batch file checks to see if the program is running.  If it is running, it does nothing.

tasklist /nh /fi "imagename eq srserver.exe" | find /i "srserver.exe" > nul ||start cls.vbs

If it isn't running, it launches a vbscript (cls.vbs) which opens Splashtop and closes the main window that pops up (essentially minimizing it to the system tray).

Dim WshShell,oExecSet WshShell = wscript.createobject("wscript.shell")Set oExec = WshShell.Exec("C:\Program Files (x86)\Splashtop\Splashtop Remote\Server\SRServer.exe")While WshShell.AppActivate("splashtop") = FALSE   Wscript.sleep 500WendWshShell.SendKeys "%{F4}"

My plan was to run these scripts as a scheduled task so that I can ensure that splashtop is running on user computers should they exit out of it (Splashtop has no way of requiring a PW to exit the program).  The sendkeys command is simply to close the main splashtop streamer window that appears after the program is launched so users don't mess with it.

The scripts work perfectly on my computer but not on a test computer I have setup.

Both computers are win 7 pro 64-bit.  The problem seems to be with the vbscript.  If splashtop is not currently running, the vbs launches the program but fails to close the main window.  

When I open taskmanager, wscript.exe is running.  If I navigate to the Splashtop folder in Program Files (x86) the folder immediately closes.

It looks like my computer recognizes the program as simply "splashtop" but the test machine does not.  It's thinking that the Splashtop folder is the window I am trying to close.  I tried every variation I could think of for the application name but this still does not work.

 

Any ideas?

 

Any help is VERY MUCH appreciated.  Thanks.

 

Link to comment
Share on other sites

Link to post
Share on other sites

Just clarifying that I got this right @dushtin

 

Your script is still running because your non-test computer isn't picking up the title correctly (thus doing the infinite sleep loop).

 

I'll admit I have used the title of a window before to detect an application, but admittedly it isn't the best option (especially when you get to launch the application yourself).  I think the best option would be to target the processId.  I will tell you where I am getting my information from, because I only pieced this solution together by what I have seen (I cannot run VBScripts and haven't dealt with VB since version 6 so excuse any syntax problems in where I changed).

Dim WshShell,oExecSet WshShell = wscript.createobject("wscript.shell")Set oExec = WshShell.Exec("C:\Program Files (x86)\Splashtop\Splashtop Remote\Server\SRServer.exe") 'You now have oExec, from which you can extract the process id'I got the return type from this http://msdn.microsoft.com/en-us/library/ateytk4a%28v=vs.84%29.aspx'From the return type I figured out what information I could get out of the oExec from this http://msdn.microsoft.com/en-us/library/af9z0a1t%28v=vs.84%29.aspx'When realizing I had the process Id, I was lucky enough that the MSDN documentation on the process ID gave an example of'using ProccessID to tell if the app was activated.  Using that information I changed your while loop...I also looked at AppActivate to ensure that it does'accept the processId, the two links http://msdn.microsoft.com/en-us/library/x78640t0%28v=vs.84%29.aspx'http://msdn.microsoft.com/en-us/library/wzcddbek%28v=vs.84%29.aspxWhile WshShell.AppActivate(oExec.ProcessID) = FALSE 'This should only ever be triggered by the actual application you just started   Wscript.sleep 500WendWshShell.SendKeys "%{F4}"

Anyways hope this helps

0b10111010 10101101 11110000 00001101

Link to comment
Share on other sites

Link to post
Share on other sites

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

×