close

Privacy guaranteed - Your email is not shared with anyone.

VB.NET (2005) Question?

Discussion in 'Tech Talk' started by mfackler, Apr 27, 2006.

  1. mfackler

    mfackler

    Messages:
    130
    Likes Received:
    0
    Joined:
    Jan 16, 2001
    Location:
    Van Wert, Ohio, USA
    I am experimenting with VB.NET 2005 Express (Free). I am attempting to write a small utility. I thought I had all the hard parts figured out and working properly. Now I want my app to give an option to reboot the system. I "thought" that should be simple (and may still be) but I have spent 3 days with google and have found nothing I can make work. Shell("shutdown.exe -r-t00") looked promising but it didn't reboot at least not in the IDE. I sure would appreciate a little help here. Wife started the day by asking "Are you going to be on that computer all day?" :)
    Thanks in advance

    Mike
     
  2. grokdesigns

    grokdesigns

    Messages:
    507
    Likes Received:
    0
    Joined:
    Dec 23, 2004
    Code:
    ' SHUT DOWN AND RESTART IN VB6
           Const EWX_LogOff As Long = 0
           Const EWX_SHUTDOWN = 1
           Const EWX_REBOOT = 2
           Const EWX_FORCE = 4
           Private Declare Function ExitWindows _
                   Lib "User32" Alias "ExitWindowsEx" _
                   (ByVal dwOptions As Long, ByVal dwReserved As Long) As Long
          
         Private Sub Command1_Click()
     
              'Shut down windows
              ExitWindows EWX_SHUTDOWN, &HFFFFFFFF
          
          
         End Sub
          
         Private Sub Command2_Click()
         
              
              ExitWindows EWX_REBOOT, &HFFFFFFFF
          
          
         End Sub
     

  3. mfackler

    mfackler

    Messages:
    130
    Likes Received:
    0
    Joined:
    Jan 16, 2001
    Location:
    Van Wert, Ohio, USA
    Thanks but thats for VB6 I need VB 2005. I'll keep looking. I'm new to this and may well have missed something.
     
  4. grokdesigns

    grokdesigns

    Messages:
    507
    Likes Received:
    0
    Joined:
    Dec 23, 2004
    Sorry about that, here, this should work, I just tested it in 2005:

    Code:
    System.Diagnostics.Process.Start (Shutdown", "/s") 'to shutdown
    
    System.Diagnostics.Process.Start("Shutdown", "/r") 'to restart
    
    System.Diagnostics.Process.Start("Shutdown", "/l") 'to logoff
    
    System.Diagnostics.Process.Start("Shutdown", "/a") 'to abort
    
    You can add '/t 30' as an argument to set the wait time before action is taken (where 30 is the number, in seconds, to wait).

    Ex: System.Diagnostics.Process.Start("Shutdown", "/r /t 30")
     
  5. mfackler

    mfackler

    Messages:
    130
    Likes Received:
    0
    Joined:
    Jan 16, 2001
    Location:
    Van Wert, Ohio, USA
    :notworthy: You are the man :notworthy:

    That did it. Thanks a million.

    It appears you know a thing or two about VB. I am writing this little utility to turn on XPs autoadminlogin. Yea I know there are several ways to go about doing this without a utility, but I sometimes do this on a domain. I never could remember the keys. This utility should put a nice front end on it. I would love to have you take a look at it when I get finished.

    Like I said this is my first try at VB.NET. I would really appreciate someone giving me some thoughts. Can I send it to you in a few days when I get done?

    Mike
     
  6. grokdesigns

    grokdesigns

    Messages:
    507
    Likes Received:
    0
    Joined:
    Dec 23, 2004
    Definitely, I'd love to see it.
     
  7. Glock Bob

    Glock Bob Snack Attack!!!

    Messages:
    405
    Likes Received:
    0
    Joined:
    Aug 5, 2004
    Location:
    Alabama
    Something to keep in mind: Shutdown.exe is only available in XP. Anything prior, such as 2000, NT, 98, etc., will not respond to shutdown commands.
     
  8. mfackler

    mfackler

    Messages:
    130
    Likes Received:
    0
    Joined:
    Jan 16, 2001
    Location:
    Van Wert, Ohio, USA
    Thanks Glock Bob. Yea, I know that. This utility is primely for setting up a new machine. It works on the XP registry so I'm sure it has other XP only features as well.

    I will keep that in mind if and when I write another.
     
  9. grokdesigns

    grokdesigns

    Messages:
    507
    Likes Received:
    0
    Joined:
    Dec 23, 2004
    With the Resource Kit, NT4 and 2000 will support the shutdown command.