Windows Vista Tips

Windows Vista Tips > Newsgroups > Windows Server > Batch file to Safely Remove Hardware and then Log Off

Reply
Thread Tools Display Modes

Batch file to Safely Remove Hardware and then Log Off

 
 
Conan Kelly
Guest
Posts: n/a

 
      11-19-2007
Hello all,

I have a co-worker that forgets to run Safely Remove Hardware to stop her
iPod before she logs off at the end of the day, so then she logs back on to
stop her iPod and then logs off again.

I was going to create a 2-line batch file that would first run Safely Remove
Hardware and then log her off. I already know the command prompts to
accomplish both task, but I have 2 questions concerning this:

1. In this batch file, if I first run Safely Remove Hardware, will Log Off
run immediately after that, or will the batch file pause and wait for the
user to finish with and close Safely Remove Hardware and then run Log Off?
If it will not automatically pause, how can I get it to?
2. I would like Safely Remove Hardware to show up only when there is
hardware connected that can be/needs to be stopped. How can I get it to
"poll the system" to check if there is hardware that can be stopped before
displaying?

The commands I intend to use are:

RunDll32.exe shell32.dll,Control_RunDLL hotplug.dll (from
http://ask-leo.com/safely_remove_har...ithout_it.html)
C:\WINDOWS\SYSTEM32\shutdown.exe -l -t 5


Thanks for any help anyone can provide,

Conan Kelly


 
Reply With Quote
 
 
 
 
Pegasus \(MVP\)
Guest
Posts: n/a

 
      11-19-2007
*** See below.

"Conan Kelly" <> wrote in message
newsmk0j.114878$...
> Hello all,
>
> I have a co-worker that forgets to run Safely Remove Hardware to stop her
> iPod before she logs off at the end of the day, so then she logs back on
> to stop her iPod and then logs off again.
>
> I was going to create a 2-line batch file that would first run Safely
> Remove Hardware and then log her off. I already know the command prompts
> to accomplish both task, but I have 2 questions concerning this:
>
> 1. In this batch file, if I first run Safely Remove Hardware, will Log
> Off run immediately after that, or will the batch file pause and wait for
> the user to finish with and close Safely Remove Hardware and then run Log
> Off? If it will not automatically pause, how can I get it to?


This command won't pause. You would have to insert a loop
into your batch file like so:

RunDll32.exe shell32.dll,Control_RunDLL hotplug.dll
:again
ping localhost -n 6 > nul
tasklist | find /i "dundll32.exe" > nul && goto again
C:\WINDOWS\SYSTEM32\shutdown.exe -l -t 5

> 2. I would like Safely Remove Hardware to show up only when there is
> hardware connected that can be/needs to be stopped. How can I get it to
> "poll the system" to check if there is hardware that can be stopped before
> displaying?

AFAIK, all hardware that requires a safe removal is visible as
a drive letter. You could use this command to check your drives:

fsutil.exe fsinfo drives

As an alternative you could use devcon.exe to disconnect
the hardware automatically, without user intervention. This
approach would also take care of the wait period you refer
to. Have a look here for further details, and post again if
unsure how to use it:
http://download.microsoft.com/downlo...240/devcon.exe

>
> The commands I intend to use are:
>
> RunDll32.exe shell32.dll,Control_RunDLL hotplug.dll (from
> http://ask-leo.com/safely_remove_har...ithout_it.html)
> C:\WINDOWS\SYSTEM32\shutdown.exe -l -t 5
>
>
> Thanks for any help anyone can provide,
>
> Conan Kelly
>



 
Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off




1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59