Results 1 to 14 of 14

Thread: [RESOLVED] Restart computer

  1. #1

    Thread Starter
    Fanatic Member
    Join Date
    Mar 2005
    Posts
    537

    Resolved [RESOLVED] Restart computer

    I am trying to restart the user's computer, and I don't know which to use, ExitWindowsEx or Shell (Shutdown.exe -t 0 -r). I tried using:

    VB Code:
    1. ExitWindowsEx (EWX_Force And EWX_Reboot, 0&)

    but that didn't work.

    What should I do?

    Thank you,
    Sir Loin
    Last edited by Sir Loin; Jul 20th, 2005 at 08:30 AM.

  2. #2
    I'm about to be a PowerPoster!
    Join Date
    Jan 2005
    Location
    Everywhere
    Posts
    13,647

    Re: Restart computer

    To shutdown the PC without shelling shutdown.exe your process must have the appropriate permissions set. It works when you use shutdown.exe because it is a separate process that has the permissions to shiut down the system.

  3. #3
    Lively Member
    Join Date
    Aug 2004
    Posts
    72

    Re: Restart computer

    Try
    VB Code:
    1. Shell ("C:\Windows\System32\CMD.exe /C shutdown -r -t 45 -c "See you soon"), vbHide

    The above is broken down like this
    -r = Restart
    -t = The time in seconds before computer restarts
    -c = What ever comment you want

    this just sends a command to the cmd
    hope that helps
    I'm not a pain in the ass, Im just making things intresting......

  4. #4
    I'm about to be a PowerPoster!
    Join Date
    Jan 2005
    Location
    Everywhere
    Posts
    13,647

    Re: Restart computer

    There is no need to shell cmd.exe because you can shell shutdown.exe directly
    Also, he knows how to do it that way, he is asking for a better way
    Last edited by penagate; Jul 20th, 2005 at 01:57 AM. Reason: Somehow managed to turn "shutdown" into profanity. Whoops.

  5. #5

    Thread Starter
    Fanatic Member
    Join Date
    Mar 2005
    Posts
    537

    Re: Restart computer

    If I shell shutdown.exe, it will only work on WinXP computers, right? I need to restart older versions of Windows as well...

    Thank You,
    Sir Loin

  6. #6
    I'm about to be a PowerPoster!
    Join Date
    Jan 2005
    Location
    Everywhere
    Posts
    13,647

    Re: Restart computer

    If you don't mind showing the shutdown dialog?
    VB Code:
    1. Declare Function SHShutDownDialog Lib "shell32" Alias "#60" ( _
    2.     ByVal IDontKnowWhatOnEarthThisDoes As Long _
    3. ) As Long
    4.  
    5. ' Show the Shutdown dialog box
    6. SHShutDownDialog 0&

    Otherwise, since on 9x based OS's I don't believe there is a process permissions model, you could try shutdown.exe on Win2k+ OS's and ExitWindowsEx on Win 95+ OS's,

  7. #7
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333

    Re: Restart computer

    Quote Originally Posted by Sir Loin
    I am trying to restart the user's computer, and I don't know which to use, ExitWindowsEx or Shell (Shutdown.exe -t 0 -r). I tried using:

    VB Code:
    1. ExitWindowsEx (EWX_Force And EWX_Reboot, 0&)

    but that didn't work.

    What should I do?

    Thank you,
    Sir Loin
    For non XP systems (95/98) try
    VB Code:
    1. ExitWindowsEx (EWX_LogOff Or EWX_FORCE), &HFFFF

  8. #8

    Thread Starter
    Fanatic Member
    Join Date
    Mar 2005
    Posts
    537

    Re: Restart computer

    Here is my restart code, it seems to work well, but i'm not sure if it will work on older OS's.

    VB Code:
    1. Private Sub RestartComputer()
    2. On Error Resume Next
    3.  
    4. Shell "Shutdown.exe -t 0 -r"
    5. Call ExitWindowsEx(EWX_REBOOT, 0&)
    6. End Sub

    Since shelling "Shutdown.exe -t 0 -r" would probably error on older OS's I just put an "On Error Resume Next".

    For non XP systems (95/98) try
    VB Code:
    1. ExitWindowsEx (EWX_LogOff Or EWX_FORCE), &HFFFF
    That's the problem, I don't know which OS the user is using...

    Thank you,
    Sir Loin

  9. #9
    I'm about to be a PowerPoster!
    Join Date
    Jan 2005
    Location
    Everywhere
    Posts
    13,647

    Re: Restart computer

    Use GetVersionEx().

    VB Code:
    1. Private Type OSVERSIONINFO
    2.     dwOSVersionInfoSize As Long
    3.     dwMajorVersion As Long
    4.     dwMinorVersion As Long
    5.     dwBuildNumber As Long
    6.     dwPlatformId As Long
    7.     szCSDVersion As String * 128
    8. End Type
    9.  
    10. Private Declare Function GetVersionEx Lib "kernel32" Alias "GetVersionExA" (_
    11.     ByRef lpVersionInformation As OSVERSIONINFO _
    12. ) As Long
    13.  
    14. ' Get OS version
    15. Dim udtOSVer As OSVERSIONINFO
    16. udtOSVer.dwOSVersionInfoSize = Len(udtOSVer)
    17. GetVersionEx udtOSVer
    18.  
    19. ' And then use (udtOSVer.dwMajor >= 5) to determine if you can call shutdown.exe.

  10. #10

    Thread Starter
    Fanatic Member
    Join Date
    Mar 2005
    Posts
    537

    Re: Restart computer

    Oh... I was thinking about using GetVersionEx, but I was getting the platform, and if it returned 2 then that was NT, and I think Win2000, XP, and ME are all WinNT OS's.

    Thanks a lot!

    -Sir Loin

  11. #11

    Thread Starter
    Fanatic Member
    Join Date
    Mar 2005
    Posts
    537

    Re: Restart computer

    I have 1 final question. Is Win95's major build number 1, and 98's 2 and so on...?

    Thanks,
    Sir Loin

  12. #12
    I'm about to be a PowerPoster!
    Join Date
    Jan 2005
    Location
    Everywhere
    Posts
    13,647

    Re: Restart computer

    No, the version numbers go like this

    Edit: Major.Minor.Build

    Win 95 - 4.00.xxx
    Win 98 - 4.01
    Win 2K - 5.00
    Win XP - 5.1

    As for NT, I believe shutdown.exe exists on all NT from 4 up (maybe). But the NT version numbers are obvious anyway. There are also platform constants you can use with .dwPlatformID, if you search GetVersionEx on MSDN you should be able to find these.

  13. #13

    Thread Starter
    Fanatic Member
    Join Date
    Mar 2005
    Posts
    537

    Re: Restart computer

    Oh, thank you for ALL of your help!

    -Sir Loin
    Last edited by Sir Loin; Jul 20th, 2005 at 09:57 AM.

  14. #14
    I'm about to be a PowerPoster!
    Join Date
    Jan 2005
    Location
    Everywhere
    Posts
    13,647

    Re: Restart computer

    No worries

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width