How can I make it so that when i click on command1 it will shut down the computer, AND when i click command2 it will restart? And if you know how to log-off that would also be helpfull(Log off of your windows session)
Thanks in advance.
Printable View
How can I make it so that when i click on command1 it will shut down the computer, AND when i click command2 it will restart? And if you know how to log-off that would also be helpfull(Log off of your windows session)
Thanks in advance.
[Highlight=VB]
Declare Function ExitWindowsEx Lib "user32" Alias "ExitWindowsEx" (ByVal uFlags As Long, ByVal dwReserved As Long) As Long
Const EWX_LOGOFF = 0
Const EWX_SHUTDOWN = 1
Const EWX_REBOOT = 2
Const EWX_FORCE = 4
ExitWindowsEx(EWX_REBOOT, 0) 'Reboots
ExitWindowsEx(EWX_LOGOFF, 0) 'Logs off
ExitWindowsEx(EWX_SHUTDOWN, 0) 'Shuts Down
ExitWindowsEx(EWX_FORCE or EWX_SHUTDOWN, 0) 'Forced shut down
[/vbcocde]
Your program won't be running after shut down so you can't do that.Quote:
Originally posted by dabomb66
...AND when i click command2 it will restart?....
I would think he would click Command2 instead of Command1.Quote:
Originally posted by MartinLiss
Your program won't be running after shut down so you can't do that.
eg. When you open up your start menu and click Shut Down Computer. You would get a pop up thing asking you what you want to do.
Perhaps you're right but lets's see what dabomb66 has to say since his/her question about Command2 specifically refers to restarting and not shuttting down.Quote:
Originally posted by Psychotic
I would think he would click Command2 instead of Command1.
eg. When you open up your start menu and click Shut Down Computer. You would get a pop up thing asking you what you want to do.
It does indeed specifically refer to restarting which would indicate that the computer is on. Otherwise you would just start up the computer....Click on the start menu and click Turn Off Computer. One of your options is to "Restart"Quote:
Originally posted by MartinLiss
Perhaps you're right but lets's see what dabomb66 has to say since his/her question about Command2 specifically refers to restarting and not shuttting down.
I think he is trying to clone the Shutdown dialog. There's a way to show that dialog if he wants it.
VB Code:
Private Declare Function SHShutDownDialog Lib "shell32" Alias "#60" (ByVal YourGuess As Long) As Long Private Sub Form_Load() 'KPD-Team 1999 'URL: [url]http://www.allapi.net/[/url] 'E-Mail: [email][email protected][/email] SHShutDownDialog 0 End Sub
I know it works in XP but not sure about others.
It works for 98 too but any body knows For what value of YourGuess what happens?
here is a module that includes everything needed
note that on NT systems, by default VB programs can't call ExitWindowsEx. you have to adjust the program's priviliges through code.. that function is included
the FORCE flag should be added to whatever action you are performing, if you want it forced
if you get stuck at the 'It is now safe to turn off your computer' screen, try using EWX_POWEROFF instead of EWX_SHUTDOWN
OK dude, well to shutdown the computer... ON WINDOWS XP ONLY... u enter:
VB Code:
shell("shutdown.exe") or shellexecute("shutdown.exe") im not too sure since i dont use it much.
This hasen't worked for me and I believe it won't on XP, but will on older versions, since XP has more to just the shutdown.exe to shutdown. Itwould also make it a bit easier for a hacker to just put a shortcut to this in the startup folder ;)Quote:
Originally Posted by Oblivion02
Use Shell ("C:\WINDOWS\system32\shutdown.exe -s"), as far as I know this works. To reboot instead, replace the "s" with "r". Again, not possitive if this code works yet, will test it in a while when I'm ready to shut down my computer. im 2 lazy 4 a reboot with all of my windows open and setup now. :p