How to run a task when shutting down

  • Thread starter Thread starter paroots
  • Start date Start date
P

paroots

I wish to run a task (to dismount a network hard drive) whenever shutting
down. I have noticed that the Task Scheduler has a trigger called, 'On local
disconnect from any user session'. I have setup a task based on this trigger,
but it doesn't execute when I do a shutdown. Any ideas are much appreciated
 
On Jun 1, 6:42 am, paroots <paro...@discussions.microsoft.com> wrote:
> I wish to run a task (to dismount a network hard drive) whenever shutting
> down. I have noticed that the Task Scheduler has a trigger called, 'On local
> disconnect from any user session'. I have setup a task based on this trigger,
> but it doesn't execute when I do a shutdown. Any ideas are much appreciated


Great question. I'd just like to point out that at disconnect from
user session is not the same as shutdown. I suspect that shutdown
begins a series of events that simply doesn't wait for your task to
even start let alone finish.

I would be very interested to learn how to force something to run at
shutdown.

Unless someone figures it out, why not just run your script at
startup? It seems to me that the end result would be very close.

-solon fox
 
GPEDIT.MSC has a Logoff script feature.

--
click the Ratings button. Voting helps the web interface.
http://www.microsoft.com/wn3/locales/help/help_en-us.htm see ''rate a post''
Mark L. Ferguson

"solon fox" <solonfox@gmail.com> wrote in message
news:d94a950e-6fc7-44f1-9a61-da1f83a5ab01@x35g2000hsb.googlegroups.com...
> On Jun 1, 6:42 am, paroots <paro...@discussions.microsoft.com> wrote:
>> I wish to run a task (to dismount a network hard drive) whenever shutting
>> down. I have noticed that the Task Scheduler has a trigger called, 'On
>> local
>> disconnect from any user session'. I have setup a task based on this
>> trigger,
>> but it doesn't execute when I do a shutdown. Any ideas are much
>> appreciated

>
> Great question. I'd just like to point out that at disconnect from
> user session is not the same as shutdown. I suspect that shutdown
> begins a series of events that simply doesn't wait for your task to
> even start let alone finish.
>
> I would be very interested to learn how to force something to run at
> shutdown.
>
> Unless someone figures it out, why not just run your script at
> startup? It seems to me that the end result would be very close.
>
> -solon fox
 
Thanks for the responses they're much appreciated. I googled on gpedit.msc
and discovered that it is a Windows XP feature? Is it available in Vista and
if so, how?

"Mark L. Ferguson" wrote:

> GPEDIT.MSC has a Logoff script feature.
>
> --
> click the Ratings button. Voting helps the web interface.
> http://www.microsoft.com/wn3/locales/help/help_en-us.htm see ''rate a post''
> Mark L. Ferguson
>
> "solon fox" <solonfox@gmail.com> wrote in message
> news:d94a950e-6fc7-44f1-9a61-da1f83a5ab01@x35g2000hsb.googlegroups.com...
> > On Jun 1, 6:42 am, paroots <paro...@discussions.microsoft.com> wrote:
> >> I wish to run a task (to dismount a network hard drive) whenever shutting
> >> down. I have noticed that the Task Scheduler has a trigger called, 'On
> >> local
> >> disconnect from any user session'. I have setup a task based on this
> >> trigger,
> >> but it doesn't execute when I do a shutdown. Any ideas are much
> >> appreciated

> >
> > Great question. I'd just like to point out that at disconnect from
> > user session is not the same as shutdown. I suspect that shutdown
> > begins a series of events that simply doesn't wait for your task to
> > even start let alone finish.
> >
> > I would be very interested to learn how to force something to run at
> > shutdown.
> >
> > Unless someone figures it out, why not just run your script at
> > startup? It seems to me that the end result would be very close.
> >
> > -solon fox

>
 
Click Start, and type:
gpedit.msc
hit enter
The path to the logoff script setting is:
Local Computer Policy/Computer Configuration/Windows
Settings/Scripts(Startup/Shutdown/...
It can, of course, be done on a per user basis at:
LCP/User Configuration/...
--
click the Ratings button. Voting helps the web interface.
http://www.microsoft.com/wn3/locales/help/help_en-us.htm see ''rate a post''
Mark L. Ferguson

"paroots" <paroots@discussions.microsoft.com> wrote in message
news:13C19E33-D1A6-4E94-BBC2-A177D0891749@microsoft.com...
> Thanks for the responses they're much appreciated. I googled on
> gpedit.msc
> and discovered that it is a Windows XP feature? Is it available in Vista
> and
> if so, how?
>
> "Mark L. Ferguson" wrote:
>
>> GPEDIT.MSC has a Logoff script feature.
>>
>> --
>> click the Ratings button. Voting helps the web interface.
>> http://www.microsoft.com/wn3/locales/help/help_en-us.htm see ''rate a
>> post''
>> Mark L. Ferguson
>>
>> "solon fox" <solonfox@gmail.com> wrote in message
>> news:d94a950e-6fc7-44f1-9a61-da1f83a5ab01@x35g2000hsb.googlegroups.com...
>> > On Jun 1, 6:42 am, paroots <paro...@discussions.microsoft.com> wrote:
>> >> I wish to run a task (to dismount a network hard drive) whenever
>> >> shutting
>> >> down. I have noticed that the Task Scheduler has a trigger called, 'On
>> >> local
>> >> disconnect from any user session'. I have setup a task based on this
>> >> trigger,
>> >> but it doesn't execute when I do a shutdown. Any ideas are much
>> >> appreciated
>> >
>> > Great question. I'd just like to point out that at disconnect from
>> > user session is not the same as shutdown. I suspect that shutdown
>> > begins a series of events that simply doesn't wait for your task to
>> > even start let alone finish.
>> >
>> > I would be very interested to learn how to force something to run at
>> > shutdown.
>> >
>> > Unless someone figures it out, why not just run your script at
>> > startup? It seems to me that the end result would be very close.
>> >
>> > -solon fox

>>
 
Have tried it can't find it in Windows Vista Home Premium?

"Mark L. Ferguson" wrote:

> Click Start, and type:
> gpedit.msc
> hit enter
> The path to the logoff script setting is:
> Local Computer Policy/Computer Configuration/Windows
> Settings/Scripts(Startup/Shutdown/...
> It can, of course, be done on a per user basis at:
> LCP/User Configuration/...
> --
> click the Ratings button. Voting helps the web interface.
> http://www.microsoft.com/wn3/locales/help/help_en-us.htm see ''rate a post''
> Mark L. Ferguson
>
> "paroots" <paroots@discussions.microsoft.com> wrote in message
> news:13C19E33-D1A6-4E94-BBC2-A177D0891749@microsoft.com...
> > Thanks for the responses they're much appreciated. I googled on
> > gpedit.msc
> > and discovered that it is a Windows XP feature? Is it available in Vista
> > and
> > if so, how?
> >
> > "Mark L. Ferguson" wrote:
> >
> >> GPEDIT.MSC has a Logoff script feature.
> >>
> >> --
> >> click the Ratings button. Voting helps the web interface.
> >> http://www.microsoft.com/wn3/locales/help/help_en-us.htm see ''rate a
> >> post''
> >> Mark L. Ferguson
> >>
> >> "solon fox" <solonfox@gmail.com> wrote in message
> >> news:d94a950e-6fc7-44f1-9a61-da1f83a5ab01@x35g2000hsb.googlegroups.com...
> >> > On Jun 1, 6:42 am, paroots <paro...@discussions.microsoft.com> wrote:
> >> >> I wish to run a task (to dismount a network hard drive) whenever
> >> >> shutting
> >> >> down. I have noticed that the Task Scheduler has a trigger called, 'On
> >> >> local
> >> >> disconnect from any user session'. I have setup a task based on this
> >> >> trigger,
> >> >> but it doesn't execute when I do a shutdown. Any ideas are much
> >> >> appreciated
> >> >
> >> > Great question. I'd just like to point out that at disconnect from
> >> > user session is not the same as shutdown. I suspect that shutdown
> >> > begins a series of events that simply doesn't wait for your task to
> >> > even start let alone finish.
> >> >
> >> > I would be very interested to learn how to force something to run at
> >> > shutdown.
> >> >
> >> > Unless someone figures it out, why not just run your script at
> >> > startup? It seems to me that the end result would be very close.
> >> >
> >> > -solon fox
> >>

>
 
Hello Mark:
I've googled on gpedit.msc and have not found any indication that this
command is available in Windows Vista Home Premium. Perhaps I have something
else that accomplishes the same thing. Any ideas?

"Mark L. Ferguson" wrote:

> Click Start, and type:
> gpedit.msc
> hit enter
> The path to the logoff script setting is:
> Local Computer Policy/Computer Configuration/Windows
> Settings/Scripts(Startup/Shutdown/...
> It can, of course, be done on a per user basis at:
> LCP/User Configuration/...
> --
> click the Ratings button. Voting helps the web interface.
> http://www.microsoft.com/wn3/locales/help/help_en-us.htm see ''rate a post''
> Mark L. Ferguson
>
> "paroots" <paroots@discussions.microsoft.com> wrote in message
> news:13C19E33-D1A6-4E94-BBC2-A177D0891749@microsoft.com...
> > Thanks for the responses they're much appreciated. I googled on
> > gpedit.msc
> > and discovered that it is a Windows XP feature? Is it available in Vista
> > and
> > if so, how?
> >
> > "Mark L. Ferguson" wrote:
> >
> >> GPEDIT.MSC has a Logoff script feature.
> >>
> >> --
> >> click the Ratings button. Voting helps the web interface.
> >> http://www.microsoft.com/wn3/locales/help/help_en-us.htm see ''rate a
> >> post''
> >> Mark L. Ferguson
> >>
> >> "solon fox" <solonfox@gmail.com> wrote in message
> >> news:d94a950e-6fc7-44f1-9a61-da1f83a5ab01@x35g2000hsb.googlegroups.com...
> >> > On Jun 1, 6:42 am, paroots <paro...@discussions.microsoft.com> wrote:
> >> >> I wish to run a task (to dismount a network hard drive) whenever
> >> >> shutting
> >> >> down. I have noticed that the Task Scheduler has a trigger called, 'On
> >> >> local
> >> >> disconnect from any user session'. I have setup a task based on this
> >> >> trigger,
> >> >> but it doesn't execute when I do a shutdown. Any ideas are much
> >> >> appreciated
> >> >
> >> > Great question. I'd just like to point out that at disconnect from
> >> > user session is not the same as shutdown. I suspect that shutdown
> >> > begins a series of events that simply doesn't wait for your task to
> >> > even start let alone finish.
> >> >
> >> > I would be very interested to learn how to force something to run at
> >> > shutdown.
> >> >
> >> > Unless someone figures it out, why not just run your script at
> >> > startup? It seems to me that the end result would be very close.
> >> >
> >> > -solon fox
> >>

>
 
It's not, Business, Enterprise, and Ultimate only.

--
Best of Luck,

Rick Rogers, aka "Nutcase" - Microsoft MVP
http://mvp.support.microsoft.com/
Windows help - www.rickrogers.org
My thoughts http://rick-mvp.blogspot.com

"paroots" <paroots@discussions.microsoft.com> wrote in message
news:E71AC796-2E8F-4685-8608-80A345A36BE1@microsoft.com...
> Hello Mark:
> I've googled on gpedit.msc and have not found any indication that this
> command is available in Windows Vista Home Premium. Perhaps I have
> something
> else that accomplishes the same thing. Any ideas?
>
> "Mark L. Ferguson" wrote:
>
>> Click Start, and type:
>> gpedit.msc
>> hit enter
>> The path to the logoff script setting is:
>> Local Computer Policy/Computer Configuration/Windows
>> Settings/Scripts(Startup/Shutdown/...
>> It can, of course, be done on a per user basis at:
>> LCP/User Configuration/...
>> --
>> click the Ratings button. Voting helps the web interface.
>> http://www.microsoft.com/wn3/locales/help/help_en-us.htm see ''rate a
>> post''
>> Mark L. Ferguson
>>
>> "paroots" <paroots@discussions.microsoft.com> wrote in message
>> news:13C19E33-D1A6-4E94-BBC2-A177D0891749@microsoft.com...
>> > Thanks for the responses they're much appreciated. I googled on
>> > gpedit.msc
>> > and discovered that it is a Windows XP feature? Is it available in
>> > Vista
>> > and
>> > if so, how?
>> >
>> > "Mark L. Ferguson" wrote:
>> >
>> >> GPEDIT.MSC has a Logoff script feature.
>> >>
>> >> --
>> >> click the Ratings button. Voting helps the web interface.
>> >> http://www.microsoft.com/wn3/locales/help/help_en-us.htm see ''rate a
>> >> post''
>> >> Mark L. Ferguson
>> >>
>> >> "solon fox" <solonfox@gmail.com> wrote in message
>> >> news:d94a950e-6fc7-44f1-9a61-da1f83a5ab01@x35g2000hsb.googlegroups.com...
>> >> > On Jun 1, 6:42 am, paroots <paro...@discussions.microsoft.com>
>> >> > wrote:
>> >> >> I wish to run a task (to dismount a network hard drive) whenever
>> >> >> shutting
>> >> >> down. I have noticed that the Task Scheduler has a trigger called,
>> >> >> 'On
>> >> >> local
>> >> >> disconnect from any user session'. I have setup a task based on
>> >> >> this
>> >> >> trigger,
>> >> >> but it doesn't execute when I do a shutdown. Any ideas are much
>> >> >> appreciated
>> >> >
>> >> > Great question. I'd just like to point out that at disconnect from
>> >> > user session is not the same as shutdown. I suspect that shutdown
>> >> > begins a series of events that simply doesn't wait for your task to
>> >> > even start let alone finish.
>> >> >
>> >> > I would be very interested to learn how to force something to run at
>> >> > shutdown.
>> >> >
>> >> > Unless someone figures it out, why not just run your script at
>> >> > startup? It seems to me that the end result would be very close.
>> >> >
>> >> > -solon fox
>> >>

>>
 
Thanks Rick. I thought I was losing my mind. Anyone have any ideas how to
scheule a batch file to run on shutdown?

"Rick Rogers" wrote:

> It's not, Business, Enterprise, and Ultimate only.
>
> --
> Best of Luck,
>
> Rick Rogers, aka "Nutcase" - Microsoft MVP
> http://mvp.support.microsoft.com/
> Windows help - www.rickrogers.org
> My thoughts http://rick-mvp.blogspot.com
>
> "paroots" <paroots@discussions.microsoft.com> wrote in message
> news:E71AC796-2E8F-4685-8608-80A345A36BE1@microsoft.com...
> > Hello Mark:
> > I've googled on gpedit.msc and have not found any indication that this
> > command is available in Windows Vista Home Premium. Perhaps I have
> > something
> > else that accomplishes the same thing. Any ideas?
> >
> > "Mark L. Ferguson" wrote:
> >
> >> Click Start, and type:
> >> gpedit.msc
> >> hit enter
> >> The path to the logoff script setting is:
> >> Local Computer Policy/Computer Configuration/Windows
> >> Settings/Scripts(Startup/Shutdown/...
> >> It can, of course, be done on a per user basis at:
> >> LCP/User Configuration/...
> >> --
> >> click the Ratings button. Voting helps the web interface.
> >> http://www.microsoft.com/wn3/locales/help/help_en-us.htm see ''rate a
> >> post''
> >> Mark L. Ferguson
> >>
> >> "paroots" <paroots@discussions.microsoft.com> wrote in message
> >> news:13C19E33-D1A6-4E94-BBC2-A177D0891749@microsoft.com...
> >> > Thanks for the responses they're much appreciated. I googled on
> >> > gpedit.msc
> >> > and discovered that it is a Windows XP feature? Is it available in
> >> > Vista
> >> > and
> >> > if so, how?
> >> >
> >> > "Mark L. Ferguson" wrote:
> >> >
> >> >> GPEDIT.MSC has a Logoff script feature.
> >> >>
> >> >> --
> >> >> click the Ratings button. Voting helps the web interface.
> >> >> http://www.microsoft.com/wn3/locales/help/help_en-us.htm see ''rate a
> >> >> post''
> >> >> Mark L. Ferguson
> >> >>
> >> >> "solon fox" <solonfox@gmail.com> wrote in message
> >> >> news:d94a950e-6fc7-44f1-9a61-da1f83a5ab01@x35g2000hsb.googlegroups.com...
> >> >> > On Jun 1, 6:42 am, paroots <paro...@discussions.microsoft.com>
> >> >> > wrote:
> >> >> >> I wish to run a task (to dismount a network hard drive) whenever
> >> >> >> shutting
> >> >> >> down. I have noticed that the Task Scheduler has a trigger called,
> >> >> >> 'On
> >> >> >> local
> >> >> >> disconnect from any user session'. I have setup a task based on
> >> >> >> this
> >> >> >> trigger,
> >> >> >> but it doesn't execute when I do a shutdown. Any ideas are much
> >> >> >> appreciated
> >> >> >
> >> >> > Great question. I'd just like to point out that at disconnect from
> >> >> > user session is not the same as shutdown. I suspect that shutdown
> >> >> > begins a series of events that simply doesn't wait for your task to
> >> >> > even start let alone finish.
> >> >> >
> >> >> > I would be very interested to learn how to force something to run at
> >> >> > shutdown.
> >> >> >
> >> >> > Unless someone figures it out, why not just run your script at
> >> >> > startup? It seems to me that the end result would be very close.
> >> >> >
> >> >> > -solon fox
> >> >>
> >>

>
>
 
It's possible to launch a hidden IE window at startup (wscript shell.run
command, second argument). This could run a *.HTA file and would allow
scripting, to have a set of script commands run 'OnExit' for the .hta page.
(This would only work with the consent, or lack of ability of the user.)

--
click the Ratings button. Voting helps the web interface.
http://www.microsoft.com/wn3/locales/help/help_en-us.htm see ''rate a post''
Mark L. Ferguson

"paroots" <paroots@discussions.microsoft.com> wrote in message
news:6A3CFB95-03F2-4934-9989-4552F963482E@microsoft.com...
> Thanks Rick. I thought I was losing my mind. Anyone have any ideas how to
> scheule a batch file to run on shutdown?
>
> "Rick Rogers" wrote:
>
>> It's not, Business, Enterprise, and Ultimate only.
>>
>> --
>> Best of Luck,
>>
>> Rick Rogers, aka "Nutcase" - Microsoft MVP
>> http://mvp.support.microsoft.com/
>> Windows help - www.rickrogers.org
>> My thoughts http://rick-mvp.blogspot.com
>>
>> "paroots" <paroots@discussions.microsoft.com> wrote in message
>> news:E71AC796-2E8F-4685-8608-80A345A36BE1@microsoft.com...
>> > Hello Mark:
>> > I've googled on gpedit.msc and have not found any indication that this
>> > command is available in Windows Vista Home Premium. Perhaps I have
>> > something
>> > else that accomplishes the same thing. Any ideas?
>> >
>> > "Mark L. Ferguson" wrote:
>> >
>> >> Click Start, and type:
>> >> gpedit.msc
>> >> hit enter
>> >> The path to the logoff script setting is:
>> >> Local Computer Policy/Computer Configuration/Windows
>> >> Settings/Scripts(Startup/Shutdown/...
>> >> It can, of course, be done on a per user basis at:
>> >> LCP/User Configuration/...
>> >> --
>> >> click the Ratings button. Voting helps the web interface.
>> >> http://www.microsoft.com/wn3/locales/help/help_en-us.htm see ''rate a
>> >> post''
>> >> Mark L. Ferguson
>> >>
>> >> "paroots" <paroots@discussions.microsoft.com> wrote in message
>> >> news:13C19E33-D1A6-4E94-BBC2-A177D0891749@microsoft.com...
>> >> > Thanks for the responses they're much appreciated. I googled on
>> >> > gpedit.msc
>> >> > and discovered that it is a Windows XP feature? Is it available in
>> >> > Vista
>> >> > and
>> >> > if so, how?
>> >> >
>> >> > "Mark L. Ferguson" wrote:
>> >> >
>> >> >> GPEDIT.MSC has a Logoff script feature.
>> >> >>
>> >> >> --
>> >> >> click the Ratings button. Voting helps the web interface.
>> >> >> http://www.microsoft.com/wn3/locales/help/help_en-us.htm see ''rate
>> >> >> a
>> >> >> post''
>> >> >> Mark L. Ferguson
>> >> >>
>> >> >> "solon fox" <solonfox@gmail.com> wrote in message
>> >> >> news:d94a950e-6fc7-44f1-9a61-da1f83a5ab01@x35g2000hsb.googlegroups.com...
>> >> >> > On Jun 1, 6:42 am, paroots <paro...@discussions.microsoft.com>
>> >> >> > wrote:
>> >> >> >> I wish to run a task (to dismount a network hard drive) whenever
>> >> >> >> shutting
>> >> >> >> down. I have noticed that the Task Scheduler has a trigger
>> >> >> >> called,
>> >> >> >> 'On
>> >> >> >> local
>> >> >> >> disconnect from any user session'. I have setup a task based on
>> >> >> >> this
>> >> >> >> trigger,
>> >> >> >> but it doesn't execute when I do a shutdown. Any ideas are much
>> >> >> >> appreciated
>> >> >> >
>> >> >> > Great question. I'd just like to point out that at disconnect
>> >> >> > from
>> >> >> > user session is not the same as shutdown. I suspect that shutdown
>> >> >> > begins a series of events that simply doesn't wait for your task
>> >> >> > to
>> >> >> > even start let alone finish.
>> >> >> >
>> >> >> > I would be very interested to learn how to force something to run
>> >> >> > at
>> >> >> > shutdown.
>> >> >> >
>> >> >> > Unless someone figures it out, why not just run your script at
>> >> >> > startup? It seems to me that the end result would be very close.
>> >> >> >
>> >> >> > -solon fox
>> >> >>
>> >>

>>
>>
 
Hey paroots,

Have you thought about adding shutdown as the last command of the
script you want to run? Instead of shutting down the normal way, you
could maybe just run your script?

The command to shutdown is:
RunDll32.exe shell32.dll,SHExitWindowsEx 1

The commad to restart is:
RunDll32.exe shell32.dll,SHExitWindowsEx 2

Here's a simple VBS script as an example.

'BEGIN SCRIPT ***************************************
'Restart the desktop

Set oWshShell = WScript.CreateObject("WScript.Shell")

'This will shutdown the computer.
oWshShell.Run "RunDll32.exe shell32.dll,SHExitWindowsEx 1"

'END OF SCRIPT ***************************************

-solon fox

On Jun 2, 8:12 am, paroots <paro...@discussions.microsoft.com> wrote:
> Thanks Rick. I thought I was losing my mind. Anyone have any ideas how to
> scheule a batch file to run on shutdown?
>
>
>
> "Rick Rogers" wrote:
> > It's not, Business, Enterprise, and Ultimate only.

>
> > --
> > Best of Luck,

>
> > Rick Rogers, aka "Nutcase" - Microsoft MVP
> >http://mvp.support.microsoft.com/
> > Windows help -www.rickrogers.org
> > My thoughtshttp://rick-mvp.blogspot.com

>
> > "paroots" <paro...@discussions.microsoft.com> wrote in message
> >news:E71AC796-2E8F-4685-8608-80A345A36BE1@microsoft.com...
> > > Hello Mark:
> > > I've googled on gpedit.msc and have not found any indication that this
> > > command is available in Windows Vista Home Premium. Perhaps I have
> > > something
> > > else that accomplishes the same thing. Any ideas?

>
> > > "Mark L. Ferguson" wrote:

>
> > >> Click Start, and type:
> > >> gpedit.msc
> > >> hit enter
> > >> The path to the logoff script setting is:
> > >> Local Computer Policy/Computer Configuration/Windows
> > >> Settings/Scripts(Startup/Shutdown/...
> > >> It can, of course, be done on a per user basis at:
> > >> LCP/User Configuration/...
> > >> --
> > >> click the Ratings button. Voting helps the web interface.
> > >>http://www.microsoft.com/wn3/locales/help/help_en-us.htmsee ''rate a
> > >> post''
> > >> Mark L. Ferguson

>
> > >> "paroots" <paro...@discussions.microsoft.com> wrote in message
> > >>news:13C19E33-D1A6-4E94-BBC2-A177D0891749@microsoft.com...
> > >> > Thanks for the responses they're much appreciated. I googled on
> > >> > gpedit.msc
> > >> > and discovered that it is a Windows XP feature? Is it available in
> > >> > Vista
> > >> > and
> > >> > if so, how?

>
> > >> > "Mark L. Ferguson" wrote:

>
> > >> >> GPEDIT.MSC has a Logoff script feature.

>
> > >> >> --
> > >> >> click the Ratings button. Voting helps the web interface.
> > >> >>http://www.microsoft.com/wn3/locales/help/help_en-us.htmsee ''rate a
> > >> >> post''
> > >> >> Mark L. Ferguson

>
> > >> >> "solon fox" <solon...@gmail.com> wrote in message
> > >> >>news:d94a950e-6fc7-44f1-9a61-da1f83a5ab01@x35g2000hsb.googlegroups.com...
> > >> >> > On Jun 1, 6:42 am, paroots <paro...@discussions.microsoft.com>
> > >> >> > wrote:
> > >> >> >> I wish to run a task (to dismount a network hard drive) whenever
> > >> >> >> shutting
> > >> >> >> down. I have noticed that the Task Scheduler has a trigger called,
> > >> >> >> 'On
> > >> >> >> local
> > >> >> >> disconnect from any user session'. I have setup a task based on
> > >> >> >> this
> > >> >> >> trigger,
> > >> >> >> but it doesn't execute when I do a shutdown. Any ideas are much
> > >> >> >> appreciated

>
> > >> >> > Great question. I'd just like to point out that at disconnect from
> > >> >> > user session is not the same as shutdown. I suspect that shutdown
> > >> >> > begins a series of events that simply doesn't wait for your task to
> > >> >> > even start let alone finish.

>
> > >> >> > I would be very interested to learn how to force something to run at
> > >> >> > shutdown.

>
> > >> >> > Unless someone figures it out, why not just run your script at
> > >> >> > startup? It seems to me that the end result would be very close.

>
> > >> >> > -solon fox- Hide quoted text -

>
> - Show quoted text -
 
thanks solon fox. I like your idea, but can't make it work. When I create
'test2.vbs' and run your script I get the following error message:
Error in shell32.dll
Missing entry:SHExitWindowsEx
Also, I don't understand why your script is doing a restart?

"solon fox" wrote:

> Hey paroots,
>
> Have you thought about adding shutdown as the last command of the
> script you want to run? Instead of shutting down the normal way, you
> could maybe just run your script?
>
> The command to shutdown is:
> RunDll32.exe shell32.dll,SHExitWindowsEx 1
>
> The commad to restart is:
> RunDll32.exe shell32.dll,SHExitWindowsEx 2
>
> Here's a simple VBS script as an example.
>
> 'BEGIN SCRIPT ***************************************
> 'Restart the desktop
>
> Set oWshShell = WScript.CreateObject("WScript.Shell")
>
> 'This will shutdown the computer.
> oWshShell.Run "RunDll32.exe shell32.dll,SHExitWindowsEx 1"
>
> 'END OF SCRIPT ***************************************
>
>
 
Well, I'm confused. I can't imagine you not having the SHExitWindowsEX
method in shell32.exe. All, I can guess at is either you are running
Vista 64 (I assumed 32), or some kind of error in copying what I
wrote.


The method, SHExitWindowsEx, accepts several parameters. Here are more
examples:
~*~*~*~*~
'This will log the user off.
oWshShell.Run "RunDll32.exe shell32.dll,SHExitWindowsEx 0"

'This will shutdown the computer.
oWshShell.Run "RunDll32.exe shell32.dll,SHExitWindowsEx 1"

'This will restart the computer.
oWshShell.Run "RunDll32.exe shell32.dll,SHExitWindowsEx 2"

'This will do a forced shutdown.
oWshShell.Run "RunDll32.exe shell32.dll,SHExitWindowsEx 4"

'This will power down the machine.
oWshShell.Run "RunDll32.exe shell32.dll,SHExitWindowsEx 8"

~*~*~*~*~*~*~*~*~
I myself, left a comment error ('Restart the desktop), in the sample
script that I gave you.

'1' shuts down. '2' restarts, '4' does an unfriendly shutdown. '8'
shuts off the power also unkind.

So... let's take the script from the top with correct comments and see
if this helps you. I shall show you two scripts one that uses shell32
just like the original and another that uses the WMI (maybe that will
work better for you?)

'BEGIN Copy below this line
--------------------------------------------------------
'Script to shutdown using shell32

'Defines and creates the shell object for later use so we can call it
later
Set oWshShell = WScript.CreateObject("WScript.Shell")

'This will shutdown the computer. calls the method shell32.dll.
'oWshShell.Run "RunDll32.exe shell32.dll,SHExitWindowsEx 1"


'END Copy above this line
---------------------------------------------------

Note the syntax: RunDll32.exe [space]
shell32.exe[comma]SHExitWindowsEX [space] 1

Now, let's take a look at using WMI - which is great if you can't get
the above to work. It is "safer" more elegant, but less direct and
more lines

'BEGIN Copy below this line -------Shutdown with
WMI-------------------------------------------------
'define the SHUTDOWN constant as 1
Const SHUTDOWN = 1

'set the string to this computer
strComputer = "."

'define th object that we need
Set objWMIService = GetObject_
("winmgmts:{impersonationLevel=impersonate,(Shutdown)}\\" & _
strComputer & "\root\cimv2")

'define our OS as Win32
Set colOperating Systems = objWMIService.ExecQuery _
("Select * from Win32_OperatingSystem")

'tight loop shuts down applications, services and the session
For Each objOperatingSystem in colOperatingSystems
objOperatingSystem.Win32Shutdown(SHUTDOWN)
Next

'END Copy above this line
---------------------------------------------------

I hope this works for you.

If still no luck, then feel free to write my gmail account and I can
send attachments. I can't swear to no typo's in the above, but I did
run both scripts.

-solon fox

On Jun 3, 6:20 am, paroots <paro...@discussions.microsoft.com> wrote:
> thanks solon fox. I like your idea, but can't make it work. When I create
> 'test2.vbs' and run your script I get the following error message:
>    Error in shell32.dll
>    Missing entry:SHExitWindowsEx
> Also, I don't understand why your script is doing a restart?
>
>
>
> "solon fox" wrote:
> > Hey paroots,

>
> > Have you thought about adding shutdown as the last command of the
> > script you want to run? Instead of shutting down the normal way, you
> > could maybe just run your script?

>
> > The command to shutdown is:
> > RunDll32.exe shell32.dll,SHExitWindowsEx 1

>
> > The commad to restart is:
> > RunDll32.exe shell32.dll,SHExitWindowsEx 2

>
> > Here's a simple VBS script as an example.

>
> > 'BEGIN SCRIPT ***************************************
> > 'Restart the desktop

>
> > Set oWshShell = WScript.CreateObject("WScript.Shell")

>
> > 'This will shutdown the computer.
> > oWshShell.Run "RunDll32.exe shell32.dll,SHExitWindowsEx 1"

>
> > 'END OF SCRIPT ***************************************- Hide quoted text -

>
> - Show quoted text -
 
I see another error. I left a line commented! The first script would
do nothing!

Here it is again:
'BEGIN Copy below this line
'Script to shutdown using shell32

'Defines and creates the shell object for later use so we can call it
Set oWshShell = WScript.CreateObject("WScript.Shell")

'This will shutdown the computer. calls the method shell32.dll.
oWshShell.Run "RunDll32.exe shell32.dll,SHExitWindowsEx 1"

'END Copy above this line

The second script also has an error caused by word wrap. The line
"WMI------------------------------------------------- " should not be
copied.

-solon fox



On Jun 3, 9:08 pm, solon fox <solon...@gmail.com> wrote:
> Well, I'm confused. I can't imagine you not having the SHExitWindowsEX
> method in shell32.exe. All, I can guess at is either you are running
> Vista 64  (I assumed 32), or some kind of error in copying what I
> wrote.
>
> The method, SHExitWindowsEx, accepts several parameters. Here are more
> examples:
> ~*~*~*~*~
> 'This will log the user off.
> oWshShell.Run "RunDll32.exe shell32.dll,SHExitWindowsEx 0"
>
> 'This will shutdown the computer.
> oWshShell.Run "RunDll32.exe shell32.dll,SHExitWindowsEx 1"
>
> 'This will restart the computer.
> oWshShell.Run "RunDll32.exe shell32.dll,SHExitWindowsEx 2"
>
> 'This will do a forced shutdown.
> oWshShell.Run "RunDll32.exe shell32.dll,SHExitWindowsEx 4"
>
> 'This will power down the machine.
> oWshShell.Run "RunDll32.exe shell32.dll,SHExitWindowsEx 8"
>
> ~*~*~*~*~*~*~*~*~
> I myself, left a comment error ('Restart the desktop), in the sample
> script that I gave you.
>
> '1' shuts down. '2' restarts, '4' does an unfriendly shutdown. '8'
> shuts off the power also unkind.
>
> So... let's take the script from the top with correct comments and see
> if this helps you. I shall show you two scripts one that uses shell32
> just like the original and another that uses the WMI (maybe that will
> work better for you?)
>
> 'BEGIN Copy below this line
> --------------------------------------------------------
> 'Script to shutdown using shell32
>
> 'Defines and creates the shell object for later use so we can call it
> later
> Set oWshShell = WScript.CreateObject("WScript.Shell")
>
> 'This will shutdown the computer. calls the method shell32.dll.
> 'oWshShell.Run "RunDll32.exe shell32.dll,SHExitWindowsEx 1"
>
> 'END Copy above this line
> ---------------------------------------------------
>
> Note the syntax: RunDll32.exe [space]
> shell32.exe[comma]SHExitWindowsEX [space] 1
>
> Now, let's take a look at using WMI - which is great if you can't get
> the above to work. It is "safer" more elegant, but less direct and
> more lines
>
> 'BEGIN Copy below this line -------Shutdown with
> WMI-------------------------------------------------
> 'define the SHUTDOWN constant as 1
> Const SHUTDOWN = 1
>
> 'set the string to this computer
> strComputer = "."
>
> 'define th object that we need
> Set objWMIService = GetObject_
>     ("winmgmts:{impersonationLevel=impersonate,(Shutdown)}\\" & _
>         strComputer & "\root\cimv2")
>
> 'define our OS as Win32
> Set colOperating Systems = objWMIService.ExecQuery _
>     ("Select * from Win32_OperatingSystem")
>
> 'tight loop shuts down applications, services and the session
> For Each objOperatingSystem in colOperatingSystems
>     objOperatingSystem.Win32Shutdown(SHUTDOWN)
> Next
>
> 'END Copy above this line
> ---------------------------------------------------
>
> I hope this works for you.
>
> If still no luck, then feel free to write my gmail account and I can
> send attachments. I can't swear to no typo's in the above, but I did
> run both scripts.
>
> -solon fox
>
> On Jun 3, 6:20 am, paroots <paro...@discussions.microsoft.com> wrote:
>
>
>
> > thanks solon fox. I like your idea, but can't make it work. When I create
> > 'test2.vbs' and run your script I get the following error message:
> >    Error in shell32.dll
> >    Missing entry:SHExitWindowsEx
> > Also, I don't understand why your script is doing a restart?

>
> > "solon fox" wrote:
> > > Hey paroots,

>
> > > Have you thought about adding shutdown as the last command of the
> > > script you want to run? Instead of shutting down the normal way, you
> > > could maybe just run your script?

>
> > > The command to shutdown is:
> > > RunDll32.exe shell32.dll,SHExitWindowsEx 1

>
> > > The commad to restart is:
> > > RunDll32.exe shell32.dll,SHExitWindowsEx 2

>
> > > Here's a simple VBS script as an example.

>
> > > 'BEGIN SCRIPT ***************************************
> > > 'Restart the desktop

>
> > > Set oWshShell = WScript.CreateObject("WScript.Shell")

>
> > > 'This will shutdown the computer.
> > > oWshShell.Run "RunDll32.exe shell32.dll,SHExitWindowsEx 1"

>
> > > 'END OF SCRIPT ***************************************- Hide quoted text -

>
> > - Show quoted text -- Hide quoted text -

>
> - Show quoted text -
 
Thanks again solon fox. Your latest script still generates an error on my
Windows Vista Home Premium 32 bit computer. Here is the script I'm testing
(between the hyphens):
--------------
'Script to shutdown using shell32

'Defines and creates the shell object for later use so we can call it
Set oWshShell = WScript.CreateObject("WScript.Shell")

'This will shutdown the computer. calls the method shell32.dll.
oWshShell.Run "RunDll32.exe shell32.dll,SHExitWindowsEx 1"
-------------

and here is the error message received:
------------
Error in shell32.dll
Missing entry:SHExitWondowsEx
------------

by the way, I have learned from the manufacturer of the NDAS drive that I
will want to execute the program ndascmd.exe with options. I know how I would
do this in a DOS batch file how would I invoke this in this vbs script file?
Thanks.

"solon fox" wrote:

> I see another error. I left a line commented! The first script would
> do nothing!
>
> Here it is again:
> 'BEGIN Copy below this line
> 'Script to shutdown using shell32
>
> 'Defines and creates the shell object for later use so we can call it
> Set oWshShell = WScript.CreateObject("WScript.Shell")
>
> 'This will shutdown the computer. calls the method shell32.dll.
> oWshShell.Run "RunDll32.exe shell32.dll,SHExitWindowsEx 1"
>
> 'END Copy above this line
>
> The second script also has an error caused by word wrap. The line
> "WMI------------------------------------------------- " should not be
> copied.
>
> -solon fox
>
>
>
> On Jun 3, 9:08 pm, solon fox <solon...@gmail.com> wrote:
> > Well, I'm confused. I can't imagine you not having the SHExitWindowsEX
> > method in shell32.exe. All, I can guess at is either you are running
> > Vista 64 (I assumed 32), or some kind of error in copying what I
> > wrote.
> >
> > The method, SHExitWindowsEx, accepts several parameters. Here are more
> > examples:
> > ~*~*~*~*~
> > 'This will log the user off.
> > oWshShell.Run "RunDll32.exe shell32.dll,SHExitWindowsEx 0"
> >
> > 'This will shutdown the computer.
> > oWshShell.Run "RunDll32.exe shell32.dll,SHExitWindowsEx 1"
> >
> > 'This will restart the computer.
> > oWshShell.Run "RunDll32.exe shell32.dll,SHExitWindowsEx 2"
> >
> > 'This will do a forced shutdown.
> > oWshShell.Run "RunDll32.exe shell32.dll,SHExitWindowsEx 4"
> >
> > 'This will power down the machine.
> > oWshShell.Run "RunDll32.exe shell32.dll,SHExitWindowsEx 8"
> >
> > ~*~*~*~*~*~*~*~*~
> > I myself, left a comment error ('Restart the desktop), in the sample
> > script that I gave you.
> >
> > '1' shuts down. '2' restarts, '4' does an unfriendly shutdown. '8'
> > shuts off the power also unkind.
> >
> > So... let's take the script from the top with correct comments and see
> > if this helps you. I shall show you two scripts one that uses shell32
> > just like the original and another that uses the WMI (maybe that will
> > work better for you?)
> >
> > 'BEGIN Copy below this line
> > --------------------------------------------------------
> > 'Script to shutdown using shell32
> >
> > 'Defines and creates the shell object for later use so we can call it
> > later
> > Set oWshShell = WScript.CreateObject("WScript.Shell")
> >
> > 'This will shutdown the computer. calls the method shell32.dll.
> > 'oWshShell.Run "RunDll32.exe shell32.dll,SHExitWindowsEx 1"
> >
> > 'END Copy above this line
> > ---------------------------------------------------
> >
> > Note the syntax: RunDll32.exe [space]
> > shell32.exe[comma]SHExitWindowsEX [space] 1
> >
> > Now, let's take a look at using WMI - which is great if you can't get
> > the above to work. It is "safer" more elegant, but less direct and
> > more lines
> >
> > 'BEGIN Copy below this line -------Shutdown with
> > WMI-------------------------------------------------
> > 'define the SHUTDOWN constant as 1
> > Const SHUTDOWN = 1
> >
> > 'set the string to this computer
> > strComputer = "."
> >
> > 'define th object that we need
> > Set objWMIService = GetObject_
> > ("winmgmts:{impersonationLevel=impersonate,(Shutdown)}\\" & _
> > strComputer & "\root\cimv2")
> >
> > 'define our OS as Win32
> > Set colOperating Systems = objWMIService.ExecQuery _
> > ("Select * from Win32_OperatingSystem")
> >
> > 'tight loop shuts down applications, services and the session
> > For Each objOperatingSystem in colOperatingSystems
> > objOperatingSystem.Win32Shutdown(SHUTDOWN)
> > Next
> >
> > 'END Copy above this line
> > ---------------------------------------------------
> >
> > I hope this works for you.
> >
> > If still no luck, then feel free to write my gmail account and I can
> > send attachments. I can't swear to no typo's in the above, but I did
> > run both scripts.
> >
> > -solon fox
> >
> > On Jun 3, 6:20 am, paroots <paro...@discussions.microsoft.com> wrote:
> >
> >
> >
> > > thanks solon fox. I like your idea, but can't make it work. When I create
> > > 'test2.vbs' and run your script I get the following error message:
> > > Error in shell32.dll
> > > Missing entry:SHExitWindowsEx
> > > Also, I don't understand why your script is doing a restart?

> >
> > > "solon fox" wrote:
> > > > Hey paroots,

> >
> > > > Have you thought about adding shutdown as the last command of the
> > > > script you want to run? Instead of shutting down the normal way, you
> > > > could maybe just run your script?

> >
> > > > The command to shutdown is:
> > > > RunDll32.exe shell32.dll,SHExitWindowsEx 1

> >
> > > > The commad to restart is:
> > > > RunDll32.exe shell32.dll,SHExitWindowsEx 2

> >
> > > > Here's a simple VBS script as an example.

> >
> > > > 'BEGIN SCRIPT ***************************************
> > > > 'Restart the desktop

> >
> > > > Set oWshShell = WScript.CreateObject("WScript.Shell")

> >
> > > > 'This will shutdown the computer.
> > > > oWshShell.Run "RunDll32.exe shell32.dll,SHExitWindowsEx 1"

> >
> > > > 'END OF SCRIPT ***************************************- Hide quoted text -

> >
> > > - Show quoted text -- Hide quoted text -

> >
> > - Show quoted text -

>
>
 
On Jun 4, 3:28 am, paroots <paro...@discussions.microsoft.com> wrote:
> Thanks again solon fox. Your latest script still generates an error on my
> Windows Vista Home Premium 32 bit computer. Here is the script I'm testing
> (between the hyphens):
> --------------
> 'Script to shutdown using shell32
>
> 'Defines and creates the shell object for later use so we can call it
> Set oWshShell = WScript.CreateObject("WScript.Shell")
>
> 'This will shutdown the computer. calls the method shell32.dll.
> oWshShell.Run "RunDll32.exe shell32.dll,SHExitWindowsEx 1"
> -------------
>
> and here is the error message received:
> ------------
> Error in shell32.dll
> Missing entry:SHExitWondowsEx
> ------------



Well, it is clearly not you. They have changed shell32.dll - even
though the method is still in my Vista Ultimate version. I would try
the more modern version using the WMI that I posted previously.

'BEGIN Copy below this line -
Const SHUTDOWN = 1

strComputer = "."

Set objWMIService = GetObject_
("winmgmts:{impersonationLevel=impersonate,(Shutdown)}\\" & _
strComputer & "\root\cimv2")

Set colOperating Systems = objWMIService.ExecQuery _
("Select * from Win32_OperatingSystem")

For Each objOperatingSystem in colOperatingSystems
objOperatingSystem.Win32Shutdown(SHUTDOWN)
Next

'END Copy above this line

> by the way, I have learned from the manufacturer of the NDAS drive that I
> will want to execute the program ndascmd.exe with options. I know how I would
> do this in a DOS batch file how would I invoke this in this vbs script file?


Here is an example that runs notepad. I assume that it would be
similar for ndascmd.exe - though I haven't used it.

Set objShell = CreateObject("Wscript.Shell")
objShell.Run "notepad.exe c:\scripts\test.txt"

> Thanks.
>

<<snip>>

Here is a great resource for scripting.
http://www.microsoft.com/technet/scriptcenter/resources/qanda/default.mspx

You may want to download the scripting archive with loads of examples
and explanations.
http://www.microsoft.com/downloads/...da-923a-4744-8289-afb73f6a5ed8&displaylang=en

I'll help where I can.

Good luck,
-solon fox
 
Back
Top