Glock Forum - GlockTalk banner

1 - 9 of 9 Posts

·
Registered
Joined
·
130 Posts
Discussion Starter · #1 ·
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
 

·
Registered
Joined
·
507 Posts
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
 

·
Registered
Joined
·
130 Posts
Discussion Starter · #3 ·
Thanks but thats for VB6 I need VB 2005. I'll keep looking. I'm new to this and may well have missed something.
 

·
Registered
Joined
·
507 Posts
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")
 

·
Registered
Joined
·
130 Posts
Discussion Starter · #5 ·
: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
 

·
Registered
Joined
·
507 Posts
Originally posted by mfackler
: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
Definitely, I'd love to see it.
 

·
Snack Attack!!!
Joined
·
405 Posts
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.
 

·
Registered
Joined
·
130 Posts
Discussion Starter · #8 ·
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.
 

·
Registered
Joined
·
507 Posts
Originally posted by Glock Bob
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.
With the Resource Kit, NT4 and 2000 will support the shutdown command.
 
1 - 9 of 9 Posts
Top