*** How to LogOff using batch file ***

  • Thread starter Thread starter N@xo
  • Start date Start date
N

N@xo

Hi,
I need to LogOff or Shutdown a Win2k station using a
command file. I found the solution for Win9x and that
looks like:

rundll32.exe shell32.dll,SHExitWindowsEx

But that doesn´t work for Win2k.

Thanks in advance.

N@xo
 
N@xo said:
Hi,
I need to LogOff or Shutdown a Win2k station using a
command file. I found the solution for Win9x and that
looks like:

rundll32.exe shell32.dll,SHExitWindowsEx

But that doesn´t work for Win2k.
Hi


Using VBScript/WMI works very well, put the following code into
a file called e.g. shutdwn.vbs, run it with the command line
wscript.exe <path-to-vbs-file>


'--------------------8<----------------------

' Use "PowerOff" for a poweroff
' Use "PowerOff_Force" for a forced poweroff
' Use "Shutdown" for a shutdown
' Use "Shutdown_Force" for a forced shutdown
' Use "Reboot" for a reboot
' Use "Reboot_Force" for a forced reboot
' Use "LogOff" for a logoff
' Use "LogOff_Force" for a forced logoff

' use "." for local computer

ShutDown ".", "PowerOff"


Sub ShutDown(sNode, sAction)

Const EWX_LOGOFF = 0
Const EWX_SHUTDOWN = 1
Const EWX_REBOOT = 2
Const EWX_FORCE = 4
Const EWX_POWEROFF = 8

Set oWMI = GetObject("winmgmts:" _
& "{impersonationLevel=impersonate,(Shutdown)}!\\" _
& sNode & "\root\cimv2")

Set colOperatingSystems = oWMI.ExecQuery _
("Select * from Win32_OperatingSystem")
For Each obj in colOperatingSystems
Set oOS = obj : Exit For
Next

sAction = LCase(sAction)

Select Case sAction
Case "logoff"
iCmd = EWX_LOGOFF
Case "logoff_force"
iCmd = EWX_LOGOFF + EWX_FORCE
Case "shutdown"
iCmd = EWX_SHUTDOWN
Case "shutdown_force"
iCmd = EWX_SHUTDOWN + EWX_FORCE
Case "reboot"
iCmd = EWX_REBOOT
Case "reboot_force"
iCmd = EWX_REBOOT + EWX_FORCE
Case "poweroff"
iCmd = EWX_POWEROFF
Case "poweroff_force"
iCmd = EWX_POWEROFF + EWX_FORCE
Case Else
' Default value
iCmd = EWX_POWEROFF
End Select

oOS.Win32shutdown iCmd
End Sub

'--------------------8<----------------------
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top