Results 1 to 5 of 5

Thread: restarting windows in vb apps

  1. #1

    Thread Starter
    Junior Member
    Join Date
    Sep 2000
    Location
    South Africa
    Posts
    25

    Talking

    i have written an app that starts with windows as the shell.
    the user then has to wait for it to restart windows.
    how do i restart windows in the app?
    can i use the api if the explorer shell was not loaded ?
    i have tried the code below , but it just freezes the pc
    Code:
    Option Explicit
    Private Declare Sub Sleep Lib "kernel32" _
    (ByVal dwMilliseconds As Long)
    
    Private Sub Form_Load()
    'this app gets called from my other app which started as
    ' the windows shell. When that app closes , then it calls 
    'this one to restart windows.
    Sleep 3000
    Label1.Caption = "Setting up Explorer..."
    Name "c:\windows\explorer.exe" As "c:\windows\desklok.exe" 
    'rename my "explorer.exe" to "desklok.exe" 
    Sleep 500
    Name "c:\windows\desklok.qaz" As "c:\windows\Explorer.exe"
    'rename original "Explorer.exe" from "desklok.qaz"
    Sleep 500
    Label1.Caption = "Starting Windows..."
    Sleep 500
    Shell ("rundll user,exitwindowsexec")
    'here it hangs
    Sleep 2000
    Unload Me
    Set winex = Nothing
    End
    End Sub
    plz can somebody help urgently

    thankz
    Go Luke , and may the source be with you.

  2. #2
    Frenzied Member Vlatko's Avatar
    Join Date
    Aug 2000
    Location
    Skopje, Macedonia
    Posts
    1,409
    This wil restart the computer:
    Code:
    Const EWX_LOGOFF = 0
    Const EWX_SHUTDOWN = 1
    Const EWX_REBOOT = 2
    Const EWX_FORCE = 4
    Private Declare Function ExitWindowsEx Lib "user32" (ByVal uFlags As Long, ByVal dwReserved As Long) As Long
    
    ExitWindowsEx EWX_FORCE Or EWX_REBOOT, 0
    I am become death, the destroyer of worlds.
    mail:[email protected]

    • Visual Basic 6.0 & .NET
    • Visual C++ 6.0 & .NET
    • ASP
    • LISP
    • PROLOG
    • C
    • Pascal

  3. #3

    Thread Starter
    Junior Member
    Join Date
    Sep 2000
    Location
    South Africa
    Posts
    25
    thanks , but how do i use it

    i tried the code below but it gives an error that says
    "Argument not optional"

    Code:
    exitwindowsex 2  ' 2 = restart windows
    Go Luke , and may the source be with you.

  4. #4
    Fanatic Member
    Join Date
    Aug 2000
    Posts
    736
    You need that last parameter. This example is from http://www.vbapi.com.

    Code:
    ' Reboot the computer, forcing any open programs to close
    Dim retval As Long  ' return value
    
    retval = ExitWindowsEx(EWX_REBOOT Or EWX_FORCE, 0)
    If retval = 0 Then Debug.Print "Reboot attempt failed."
    I have tried this code before and have not been able to get it to re-boot, so something must still be missing. I am running NT. Does this code work for others out there ?

    [Edited by jbart on 10-31-2000 at 07:04 AM]

  5. #5
    Guest
    Originally posted by railor
    thanks , but how do i use it

    i tried the code below but it gives an error that says
    "Argument not optional"

    Code:
    exitwindowsex 2  ' 2 = restart windows
    You are missing something.

    exitwindowsex 2, 0

    That's why you get the error.

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