Windows 2003 Batch file to Safely Remove Hardware and then Log Off

  • Thread starter Thread starter Conan Kelly
  • Start date Start date
C

Conan Kelly

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_ha...w_do_i_safely_remove_hardware_without_it.html)
C:\WINDOWS\SYSTEM32\shutdown.exe -l -t 5


Thanks for any help anyone can provide,

Conan Kelly
 
*** See below.

"Conan Kelly" <CTBarbarinNOSPAM@msnNOSPAM.comNOSPAM> wrote in message
news:pmk0j.114878$kj1.84375@bgtnsc04-news.ops.worldnet.att.net...
> 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/download/1/1/f/11f7dd10-272d-4cd2-896f-9ce67f3e0240/devcon.exe

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