Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to start a program on shutdown 2

Status
Not open for further replies.

azzurri

IS-IT--Management
Jun 2, 2000
193
CA
Hi all,

I would like to start a data synchronisation on an external HDU at a shutdown of my XP PC.
How can I do it ?

thanks
azzurri
 
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.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top