Advertisement
If you have a new account but are having problems posting or verifying your account, please email us on hello@boards.ie for help. Thanks :)
Hello all! Please ensure that you are posting a new thread or question in the appropriate forum. The Feedback forum is overwhelmed with questions that are having to be moved elsewhere. If you need help to verify your account contact hello@boards.ie

restarting windows 2000 pro from cmd line

Options
  • 16-04-2004 11:11am
    #1
    Registered Users Posts: 1,775 ✭✭✭


    how would you restart a win2k pro machine using a shortcut, from the command line or by remote? without installing RK (just the basic install of 2k).


Comments

  • Registered Users Posts: 2,931 ✭✭✭Ginger


    Not too sure if this works on 2K as i really dont want to restart my machine

    C:\WINNT\rundll.exe user.exe,exitWindows

    Should do it as a shortcut


  • Registered Users Posts: 2,931 ✭✭✭Ginger


    This might also work

    C:\WINDOWS\SYSTEM32\TSSHUTDN.EXE 0 /DELAY:0 /POWERDOWN


  • Closed Accounts Posts: 3 Bizarre


    You can also use shutdown with the switches bdlow:

    shutdown.exe /L /R /Y /C /T:05

    Or try shutdown /? to try your own.


  • Registered Users Posts: 3,146 ✭✭✭oneweb


    Originally posted by Ginger
    This might also work

    C:\WINDOWS\SYSTEM32\TSSHUTDN.EXE 0 /DELAY:0 /POWERDOWN
    That file doesn't exist on Win2kPro, nor does
    Originally posted by Bizarre
    shutdown.exe

    Ginger's first suggestion is the MS documented way, there are some variants such as logoff, force logoff, powerdown etc. <edit, doesn't work on w2k :dunno: >

    shutdown utility

    It is what it's.



  • Closed Accounts Posts: 545 ✭✭✭ColmOT [MSFT]


    Ginger's way is for Windows 9x.

    rundll32 user32.dll,ExitWindowsEx

    should work on W2K.

    I've no W2K machine to try it on though...anyone wanna verify if it works?

    Colm.


  • Advertisement
  • Registered Users Posts: 1,775 ✭✭✭Spacedog


    nope :( none of the above work, the shutdown.exe is part of the resource kit and isn't available in vanilla flavour Win2k :( anyone know anything about specialised scripting, say perl or someink that could apply?


  • Closed Accounts Posts: 3 Bizarre


    Can you not donwload the resource kit?


  • Registered Users Posts: 1,391 ✭✭✭fatherdougalmag


    Keep in mind that you'll probably need admin privileges to do this sort of thing.


  • Registered Users Posts: 1,775 ✭✭✭Spacedog


    suppose I could dl it, but I'd have to roll it out and what-not. I just assumed microsoft would have the good sense to allow users to... nevermind.


  • Registered Users Posts: 2,931 ✭✭✭Ginger


    If fancy a bit of C++ coding its fairly easy

    ExitWindowsEx from Windows.h i think ..

    Or else you could do it in VB and import one of the dlls .. It should be possible to do it

    Such as this

    Thank you MSDN :P

    Also with a slight be of modification this can be done in VBA and possibly but unsure VBS

    HTH



    Create a new standard EXE in Visual Basic. Form1 is created by default.

    View the code for Form1. In the Declarations section, add the following code:


    Private Type LUID
    UsedPart As Long
    IgnoredForNowHigh32BitPart As Long
    End Type

    Private Type TOKEN_PRIVILEGES
    PrivilegeCount As Long
    TheLuid As LUID
    Attributes As Long
    End Type

    Private Const EWX_SHUTDOWN As Long = 1
    Private Const EWX_FORCE As Long = 4
    Private Const EWX_REBOOT = 2

    Private Declare Function ExitWindowsEx Lib "user32" (ByVal _
    dwOptions As Long, ByVal dwReserved As Long) As Long

    Private Declare Function GetCurrentProcess Lib "kernel32" () As Long
    Private Declare Function OpenProcessToken Lib "advapi32" (ByVal _
    ProcessHandle As Long, _
    ByVal DesiredAccess As Long, TokenHandle As Long) As Long
    Private Declare Function LookupPrivilegeValue Lib "advapi32" _
    Alias "LookupPrivilegeValueA" _
    (ByVal lpSystemName As String, ByVal lpName As String, lpLuid _
    As LUID) As Long
    Private Declare Function AdjustTokenPrivileges Lib "advapi32" _
    (ByVal TokenHandle As Long, _
    ByVal DisableAllPrivileges As Long, NewState As TOKEN_PRIVILEGES _
    , ByVal BufferLength As Long, _
    PreviousState As TOKEN_PRIVILEGES, ReturnLength As Long) As Long

    Add a procedure called AdjustToken with the following code:


    Private Sub AdjustToken()
    Const TOKEN_ADJUST_PRIVILEGES = &H20
    Const TOKEN_QUERY = &H8
    Const SE_PRIVILEGE_ENABLED = &H2
    Dim hdlProcessHandle As Long
    Dim hdlTokenHandle As Long
    Dim tmpLuid As LUID
    Dim tkp As TOKEN_PRIVILEGES
    Dim tkpNewButIgnored As TOKEN_PRIVILEGES
    Dim lBufferNeeded As Long

    hdlProcessHandle = GetCurrentProcess()
    OpenProcessToken hdlProcessHandle, (TOKEN_ADJUST_PRIVILEGES Or _
    TOKEN_QUERY), hdlTokenHandle

    ' Get the LUID for shutdown privilege.
    LookupPrivilegeValue "", "SeShutdownPrivilege", tmpLuid

    tkp.PrivilegeCount = 1 ' One privilege to set
    tkp.TheLuid = tmpLuid
    tkp.Attributes = SE_PRIVILEGE_ENABLED

    ' Enable the shutdown privilege in the access token of this process.
    AdjustTokenPrivileges hdlTokenHandle, False, _
    tkp, Len(tkpNewButIgnored), tkpNewButIgnored, lBufferNeeded

    End Sub

    Add a CommandButton to the form. In the Click event, add the following code:


    Private Sub Command1_Click()
    AdjustToken
    ExitWindowsEx (EWX_SHUTDOWN Or EWX_FORCE Or EWX_REBOOT), &HFFFF
    End Sub

    Save the project and build an executable. When you run the executable and click the CommandButton the computer will reboot as expected.


  • Advertisement
  • Registered Users Posts: 2,931 ✭✭✭Ginger


    Just a thought ...

    You say that the problem is roll out .. how were you going to roll out the shortcut?


  • Registered Users Posts: 1,775 ✭✭✭Spacedog


    I wasn't going to rollout the shortcut, I wanted to be able to telnet into users pcs and reboot them remotley. linux example

    ssh 192.168.0.x
    user
    pass
    shutdown -r now


    I didn't think it'd be an episode of Eastenders doing this in Windows 2k.


  • Registered Users Posts: 2,931 ✭✭✭Ginger


    Ahh this makes it easier

    You can in Computer Management remotely shut down a machine

    So here is a walkthru

    On your machine open up Computer Management

    Right Click on Computer Management (Local)

    Connect to Another Computer

    Type in the name of the machine/IP

    Right Click on Computer Management (Comp_Name)

    Cick Properties -> Advanced -> Startup & Recovery ...

    Nice shut down button for you to reboot the machine

    That any better ...


  • Moderators, Recreation & Hobbies Moderators, Science, Health & Environment Moderators, Technology & Internet Moderators Posts: 91,807 Mod ✭✭✭✭Capt'n Midnight


    have a look at PSTOOLS too on systeminternals too
    or you could VNC in and manually reboot.


  • Registered Users Posts: 1,775 ✭✭✭Spacedog


    Ah, lovely stuff Ginger, yer a star! thanks capn' too, good ideas lads! muchos grasci!


  • Registered Users Posts: 2,931 ✭✭✭Ginger


    De nadda .. handy trick really but i think you may need to be an admin on the machine


Advertisement