That reference article is great for geeks, what about simple VB programers like me?
I would like to launch a program (written in VB 6) whenever someone clicks on shutdown.
Is there a sample script somewhere to run "myprogram.exe"
and delay the shutdown until the job is complete?
>Is there a sample script somewhere to run "myprogram.exe"
>and delay the shutdown until the job is complete?
You can simply make the plaintext .vbs file with the following line:
[tt] createobject("wscript.shell").run "myprogram.exe",0,true[/tt]
Supply the exact path pointing to it if necessary.
tsuji,
I tried your example and although it did execute myprogram.exe, it did so after closing the desktop.
I wanted to display a checklist of user activities and give him the option to abort the shutdown.
so
1. can I execute myprogram before anything else is closed?
2. If yes, can I abort the shutdown. Would shelling to shutdown /a do the trick?
joeschoe, sometimes one has to visualize how shutdown is being triggered at all. It might be by system, by admin doing remote job, by the login user himself, hence, a logoff/shutdown script in general might be advisable to restrict to biggest common denominator of these different situation. But this is not a recognized principle, just a reflection.
>it did execute myprogram.exe, it did so after closing the desktop
If you are after a shutdown script, then it'll be so. It is running under the credential of local system account. The login user is already "gone". So, it might not be very advisable or meaningful for an interactive program to run.
Maybe, think about if a logoff script will suit your situation better? I cannot be very sure.
Tsuji,
I tried using gpedit.msc,
Local Computer Policy
User Configuration
Windows settings
Scripts
Logoff
I inserted the pointer to my vbs script
When I then requested a shutdown, it still shut down everything before executing myprogram.
Have I missed out something?
joeschoe, one element I had failed to relate to your observations is that the line I put in the script is meant to be running myprogram.exe in the background. Hence, it is for noninteractive purpose by assumption. If visual inspection is important and even interactive is required for myprogram.exe to function properly, change the parameter (intWindowStyle) from 0 (hide) to 1 (activate and display). Like this.
[tt] createobject("wscript.shell").run "myprogram.exe",[blue]1[/blue],true[/tt]
Tsuji,
Changing the parameter made no difference to the sequence of the execution. Myprogram only gets launched when windows applications including desktop are terminated.
>Would shelling to shutdown /a do the trick?
It seems that the shutdown is a specific one-off thing under certain conditions that the user would go for a shutdown. In that case, you sure will be free to device a standalone script file to "shell" out myprogram.exe, then "shell" out the shutdown.exe with the desired option (adding a similar line after it). The way of shelling out in vbs is what shown already. Keep the 3rd parameter to true will assure completion of myprogram.exe before executing shutdown.exe.
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.