Help - Search - Members - Calendar
Full Version: How to close down a program with a script
Hydrogenaudio Forums > Misc. > Off-Topic
JEN
This is slightly off topic but is related to computer administration and automating tasts.

Does anyone know how to close a program using a bat file? Is it even possible?
TwoJ
@gwaihir - I tried O&O and it is ok - I think I remember it having a lot of different ways of defraggin the HD depending on what your purpose was, ie. server/storage/A/V, etc. However I think in some study they compared O&O to Diskeeper and for the majority of cases they were about equal - i don't think there is any big difference.

@Jen
I think it depends on which OS you run - Windows keeps knocking off certain commands (like CHOICE) and implementing new ones.
If you have WinXP you can use the Taskkill comand, run cmd and type in taskkill /?
If you have Win2k you can try the 'exit' command - not sure how your program will like it though - its not an elegant closure sometimes.
You also have the option of using the WSH (windows script hosting). Take the following code

[/CODE]dim shell

set shell=CreateObject("WScript.Shell")

shell.Run "C:\winnt\system32\notepad.exe"

do while(shell.AppActivate("Untitled - Notepad")=FALSE)
wscript.sleep 200
loop

shell.Sendkeys "HELLO WORLD" 'Write Hello world
wscript.sleep 1999 'wait

Shell.Sendkeys "{Enter}" 'new line

shell.Sendkeys "ANYONE THERE?" 'write anyone there?
wscript.sleep 1999 'wait

shell.Sendkeys "%{f4}" 'send alt-F4 to close the application
wscript.sleep 1999 'wait

shell.Sendkeys "%N" 'send Alt-N - select not to save file


wscript.sleep 1999 'sleep however long necessary to complete the run
'Again you will have to figure this one out
[CODE]

Open up a new text document in Notepad and save it as something like 'Test1.vbs' - you need the vbs ending for visual basic script
then just run the script - if you have an antivirus you might get a warning - just allow the whole script - (then I'll have all your bank information - ha-ha-ha tongue.gif )
You don't have to touch or click anything - the script will open notepad and close it - very simple. This is set for Windows 2000 - for XP just change 'winnt' to 'windows' assuming your OS is on the C: drive
As you'll see the wsh is a bit more powerful than just the command line batch files. Hope it helps
JEN
TwoJ - You are the best !!! biggrin.gif

This is exactly what I wanted. Can you please tell me how to change this script so it opens VCool for about 2 seconds and then closes it again (without changing any of VCools settings). I have the VCool program in c:\program files\vcool\vcool.exe

Thank you so much smile.gif

I modded the script and came up with this!

CODE
dim shell

set shell=CreateObject("WScript.Shell")

shell.Run "C:\progra~1\vcool\vcool.exe"

do while(shell.AppActivate("VCool 1.8 BETA Options (b10a)")=FALSE)
wscript.sleep 200
loop

shell.Sendkeys "%{f4}" 'send alt-F4 to close the application
wscript.sleep 1999 'wait

shell.Sendkeys "%N" 'send Alt-N - select not to save file


wscript.sleep 1999 'sleep however long necessary to complete the run
'Again you will have to figure this one out


This script will open VCool, but because VCool opens minimised in the system tray, it does not close. What can be done here?

Thanks for the help smile.gif
TwoJ
We'll see what you think of me when I have drained your bank account (Ha-ha-ha) ph34r.gif

Glad to help Jen wink.gif

Since I don't have it installed I can't say for sure but I just took a quick look on their site. It seems they have a hotkey for getting the main window

<ctrl>+<alt>+v
says it should bring up the main window
I guess the script would look like this
CODE

dim shell

set shell=CreateObject("WScript.Shell")

shell.Run "C:\progra~1\vcool\vcool.exe"

do while(shell.AppActivate("VCool 1.8 BETA Options (b10a)")=FALSE)
wscript.sleep 200
loop

wscript.sleep 1999  'wait

shell.Sendkeys "^%v"  'send Ctrl+Alt+v - select to bring up main window
shell.Sendkeys "%x" 'send Alt-x to exit program

The timing you'll have to figure out just change the value in the "wscript.sleep 1999 'wait" line
Not too sure about the combination ^%v - i think it should work

Edit: the thing is case sensitive so V -> v
checked in Word and that combination should work ok
let me know
JEN
Hi

Thanks for the updated script. However, if does not work sad.gif

It does the same as the script I modded, only opens VCool ???
TwoJ
If it opens vcool then you just have to determine the actual keystrokes needed to close the program.
It is pretty hard to determin that without installing the program which I can't do at the moment
It may be necessary to open the file menu and then hit the Alt-x to exit.

if shell.Sendkeys "^%v" can open the program to being the active window
then maybe you need next;

shell.Sendkeys "%" 'activate toolbar
shell.Sendkeys "fx" 'file menu -> eXit

and you can take out the shell.Sendkeys "%x" 'send Alt-x to exit program
line since it will be achompished with the 2 lines above

hope that works

Edit - added descriptions
JEN
When it loads up, it loads up minimised in the system tray.

Thanks for the help smile.gif
tigre
JEN, I don't know what exactly you want to do (my guess: switch VCool on/of to get a decent cooling and good performance for some folding@home like application as well), but maybe this helps (from VCool helpfile):
QUOTE
Command Line Switches
/bx x = 0 or 1  switches NB Cool Bit off/on
/lx x = 0 or 1  switches idle loop off/on
/hx  x = 0 or 1  hides/shows the icon
/tx  x = 0 or 1  disable/enable temperature readout
/Tx x = 0 or 1  disable/enable throttling
/px  x = 0 or 1  special poweroff option off/on
/cx  x = 0 or 1  disable/enable "clear Cool Bit on Exit"
  
/Cxx  xx=01-03  Select CPUSensor (e.g. /C01 that is 'C' zero one)
/Sxx  xx=01-03  Select SYSSensor (e.g /S03)
/Bxx  xx=00-03  Select Sensor type (0=Auto, 1=SB , 2=ISA, 3=SMB)
  
/fxx  xx=00-99  Select readout interval
/0xx  xx=00-99  Select shutdown temperature (e.g. /080)
/1xx  xx=00-99  Select T10 temperature (e.g. /180)
/5xx  xx=00-99  Select T50 temperature (e.g. /580)

Most of these parameters (except for /Bxx) can be used even if one instance of VCool is already running. The running instance will be updated with the new options. However they will not be stored unless you open the Options dialog and click on OK or Apply.
JEN
I seem to have a problem with my VCool, I have tried different versions, tried re-installing and everything, but the problem still persists.

The problem is that VCool's "driver ldle loop" only works when I start the program and then exit it ???

This means, each time I start my computer, I have to manually start VCool and then manually exit it, to get it to work properly. (This is why I posted in this thread - e.g. automating a tast smile.gif)

This is why I original asked about a batch file, but TwoJ came up with a much better solution, which I think just needs to be fine tuned.

If anyone has anyother suggestions on how to get VCool to work properly, please let me know.

Thanks smile.gif
tigre
What happens if you don't start VCool with autostart but later manually - do you still have to close and re-start it to make it work?
JEN
Yes sad.gif
tigre
I see.
QUOTE
The problem is that VCool's "driver ldle loop" only works when I start the program and then exit it ?
And probably disabling and re-enabling Idle loop as it could be done using commandline switches doesn't help either?
Have you asked at VCool Board?
TwoJ
Well tried to run it on my computer Jen but it keeps giving the error that the vcool.sys service cannot start. So I can't really try it on my computer.

You should try running it (as I understand when you run it, it will be in the system tray), and then try to open it with the Hot Key combination. On their webpage it looks as it might be a capitol V and not lower case v.
Try both and determine if you can open it with that hotkey combination (not sure but you might have to disable the icon for it)
If you can open it with the hotkey combination then just plug that sequence into the script.

Hope it works better for you then it did for me dry.gif
tigre
Split from Automating Tasks thread.
________________________________

Here (VCool 1.7) Ctrl-Alt-v just removes the ikon from the task bar, but the process is still running (Ctrl-Alt-V doesn't do anything), so I think this hotkey doesn't do what's needed here.
_Shorty
.\pskill.exe <whatever>
http://www.sysinternals.com/ntw2k/freeware...e/pstools.shtml
TwoJ
Ack - thread split ohmy.gif

Sounds like that program still has some bugs in it, on their webpage it said that Ctrl-Alt-V is suppose to bring up the main window.

Anyhow _Shorty's contribution I think should work.

I suppose ultimately you could go full automation and install AutoMate since it is more robust in controlling programs, but it seems a little overkill.
JEN
Looks like I will have to try pskill.exe, thanks shorty!

@ TwoJ - you seem to be the scripting expert here biggrin.gif I don't supposed you could modify it so it used pskill.exe to kill VCool, could ya!!! smile.gif

Yes I could install automate, but I want to keep it as simple as possible smile.gif
This is a "lo-fi" version of our main content. To view the full version with more information, formatting and images, please click here.
Invision Power Board © 2001-2008 Invision Power Services, Inc.