Shutdown

AutoIt

Q #1: Is there a sure way to command my Windows to reboot?

      ---------------------------------------------------------------------

A #1: Have you tried the AutoIt shutdown command?

      from the manual:

      Shutdown,

      This command allows you to perform various forms of
      shutdown.  The type is determined by .  The flag
      can be a combination from the table below:

      Function                          Flag
      ---------------------------------------------------------------------
      Log off the current user           0
      Shutdown the workstation           1
      Reboot the workstation             2
         Force closing of applications
           (may lose unsaved work)       4
      Shutdown and power off 
                   (if supported)        8

      e.g. To shutdown and force applications to close
      without saving = Shutdown + Force = 1 + 4 = 5:
      Shutdown, 5

      ---------------------------------------------------------------------

A #2: Here's the page where I found this...

      http://www.onecomputerguy.com/desktop.htm#logoff_icon

      And here's a list of commands that they show.  It's been a long time
      since I've had Windows 9x, so I can't test this: sorry.  I would
      suggest trying this from a command prompt, then working your way
      outward toward a script.  Isolate whether the problem is with the
      script or the command.

      For Shutdown, the command is
      C:\WINDOWS\RUNDLL.EXE user.exe,exitwindows

      For Restart, the command is
      C:\WINDOWS\RUNDLL.EXE user.exe,exitwindowsexec

      For Logoff, the command is
      C:\WINDOWS\RUNDLL.EXE shell32.dll,SHExitWindowsEx0

      ---------------------------------------------------------------------

A #3: With Windows98, there are several known shutdown bugs.  I don't know
      specifically of shutdown bugs on Windows95, but you can get this
      same sort of problem with bad software interactions.  The way to test
      this is to first run a normal shutdown through the Start Menu
      shutdown option.  If that works, use the standard command
      "rundll32.exe user,exitwindows" in the Start Menu run option. If
      either one of these fails, it is probably a problem with your OS. If
      they both work, it's harder to say what the problem is, but knowing
      that this works would help someone point you closer to the right
      direction.

      ---------------------------------------------------------------------

A #4: To remotely reboot you might use the "Shutgui" utility from the
      NT-Server Resource Kit. The NT res kit has a "Shutdown" manager that
      allows you to SD a PC on your network, but there is a command line 1
      "SHUTDOWN" that can be run as an "AT" script on your server.
           Check out the help file for both of the above for the syntax...
      It should be ..

      SHUTDOWN \\"Computername" ..

      Or see the following for more details

      http://download.mycomputer.com/detail/57/56.html


      ---------------------------------------------------------------------

A #5: To currently log off the current user from WIN NT4.0, NOT 95 etc from
      the command line or batch script the command is this,

      rundll32 user32.dll,ExitWindowsEx

      Using this method removes dependencies on resource kit utils etc.
      what about the good old dos (use ipconfig /release // /renew)

-----------------------------------------------------------------------------

Q #2: What do I do if other users are connected to the system as well?

      ---------------------------------------------------------------------

A #1: Try:

      Runwait, %COMSPEC% /c net.exe STOP

-----------------------------------------------------------------------------

Q #3: I'm trying to use Shutdown in a script to create an executable to
      reboot a PC.  The PC is on a W95 network, and accessed by others, so
      I get the Sharing Message Box before shutdown, telling me "there are
      2 users connected to your PC, etc" and prompting for Y/N to continue
      with the reboot.

      The gist of the script is:

      Shutdown, 2
      ; to reboot the PC (I've also tried Shutdown, 6)

      WinWaitActive, Sharing
      ; waits for the Sharing message box

      Send, y
      ; answers Yes, to continue with reboot

      It seems a simple enough script, but it never gets past the Sharing
      box. Has it shut down by then to a state where Autoit executables
      can't continue (the icon is still in the system tray, so I presume
      it's still running), or have I got something more fundamental wrong?
      If so, any solutions, anyone?

      ---------------------------------------------------------------------

A #1: You may want to put the line that sends a !Y to the Sharing dialog
      box to a [ADLIB] section just in case there are no other users
      connected to the machine.because with the WinWaitAcive statement the
      script will stop running until that window appears and if no one
      else is attached to the box then the windows will not appear and the
      script will wait. Also you can try a IfWinExist statement on that
      line instead of the [ADLIB] section.

      ---------------------------------------------------------------------

A #2: There's a not-normally-installed Windows95 accessory component, Net
      Watcher, on the W95 CD that allows you to disconnect users. I'll do a
      script for it on Monday to clear the connections prior to rebooting,
      then I can't see why Restart shouldn't work.  I can't find it on W98
      at home though - anyone know if it's been replaced by something
      different in W98?

      ---------------------------------------------------------------------

      Actually, AutoIt quits straight after a shutdown command, if it's
      still in the taskbar after this command it's because there is a
      reboot in progress.... So, once the shutdown command has been issued,
      no other commands (ADLIB or otherwise) will be executed.

      There's probably a way to stop all network connections before running this
      (on 9x and NT).  Anyone seen such a program?

      ---------------------------------------------------------------------

A #3: For a Win Reboot or (current) User Logoff/Logon

      Create a shortcut to the Rundll.exe or the Rundll32.exe file and type
      the following Path property, eg the SYNTAX :

      C:\Windows\RUNDLL.EXE user,exitwindowsexec

      -one single space between .EXE and user
      -one single comma between user and exitwindowsexec
 
      single/doubleclick the link,

      ---------------------------------------------------------------------

A #4: The purpose is to release a client DHCP IP lease just before system
      shutdown so that a geographically roaming notebook user will
      automatically be serviced with a new IP address when they connect to
      a different DHCP server. I assume it would look something like this.

      ; ======== Script Starts Here =======
      @ECHO OFF
      IPCONFIG /RELEASE
      Rundll32, user, ExitWindowsExec (I know this syntax is incorrect, ideas?)
      ; ======= Script Ends Here =======

      ---------------------------------------------------------------------

A #5: For those interested in techie stuff....
     
           NT is very easy to shutdown from the API and it also has the
      facility to "force" shutdowns (i.e. any open programs and data are
      dumped) - This is why the code in AutoIt will always work under NT.

           Different story under 95, internally I'm using the ExitWindows
      API but under 95 there is NO way to force a shutdown with the API
      (bit of a bonkers decision on MS's part in my opinion).  So each
      shutdown utility for 95 will work in a different way depending on
      how the author tried to force the issue.  I'm using some code from
      MSDN which basically gets a list of all processes running and tries
      to kill them.  If they haven't "died" within a couple of seconds
      ("Please save data - blah blah blah") then they are given a kick and
      really killed.  After this the normal windows "ExitWindows" API is
      used - which usually succeeds if all applications have been closed.
           This works for most 95 machines but I've also seen the "Please
      wait for windows to shutdown" message as well (and I've also seen
      that message quite a few times on manual shutdown!)
           Anyway, that's just for info, and that's why there are sooooooo
      many 95 shutdown applications that don't work 100%.

-----------------------------------------------------------------------------

Q #4: I would like to know how to run a script on a local network from a
      Windows 98 "server". For exemple,  i would like to shutdown all
      computers of my local network in the same way. is it possible ?

      ---------------------------------------------------------------------

A #1: You could make the script and then compile it. Place it on the
      network and then have a link to it for the users. I also email the
      compiled scripts as attachments when convenient.  This allows the
      receipient to run the script immediately upon getting the email.