Results 1 to 12 of 12

Thread: Shutdown the computer.

  1. #1

    Thread Starter
    Member
    Join Date
    Feb 2004
    Posts
    48

    Shutdown the computer.

    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.
    ~~VB ROX~~
    ~~X-BOX ROX~~
    --http://boards.dabomb66.com--

  2. #2
    Fanatic Member
    Join Date
    Aug 2000
    Posts
    879
    [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]
    Visual Basic 6.0
    Visual C++ 5
    Delphi 5


  3. #3

  4. #4
    Addicted Member Psychotic's Avatar
    Join Date
    May 2004
    Posts
    164

    Re: Re: Shutdown the computer.

    Originally posted by MartinLiss
    Your program won't be running after shut down so you can't do that.
    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.
    -Psychotic-

  5. #5
    Former Admin/Moderator MartinLiss's Avatar
    Join Date
    Sep 1999
    Location
    San Jose, CA
    Posts
    33,431

    Re: Re: Re: Shutdown the computer.

    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.
    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.

  6. #6
    Addicted Member Psychotic's Avatar
    Join Date
    May 2004
    Posts
    164

    Re: Re: Re: Re: Shutdown the computer.

    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.
    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"
    -Psychotic-

  7. #7
    The picture isn't missing BuggyProgrammer's Avatar
    Join Date
    Oct 2000
    Location
    Vancouver, Canada
    Posts
    5,217
    I think he is trying to clone the Shutdown dialog. There's a way to show that dialog if he wants it.

    VB Code:
    1. Private Declare Function SHShutDownDialog Lib "shell32" Alias "#60" (ByVal YourGuess As Long) As Long
    2. Private Sub Form_Load()
    3.     'KPD-Team 1999
    4.     'URL: [url]http://www.allapi.net/[/url]
    5.     'E-Mail: [email][email protected][/email]
    6.     SHShutDownDialog 0
    7. End Sub

    I know it works in XP but not sure about others.
    Remember, if someone's post was not helpful, you can always rate their post negatively .

  8. #8
    Hyperactive Member Vishalgiri's Avatar
    Join Date
    Oct 2003
    Location
    India
    Posts
    345
    It works for 98 too but any body knows For what value of YourGuess what happens?
    Regards,
    Vishalgiri Goswami
    Gujarat, ( INDIA ).
    ---------------------

  9. #9
    Frenzied Member dis1411's Avatar
    Join Date
    Mar 2001
    Posts
    1,048
    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
    Attached Files Attached Files

  10. #10
    Super Moderator manavo11's Avatar
    Join Date
    Nov 2002
    Location
    Around the corner from si_the_geek
    Posts
    7,171


    Has someone helped you? Then you can Rate their helpful post.

  11. #11
    Member
    Join Date
    Jun 2004
    Location
    Puerto Rico
    Posts
    43
    OK dude, well to shutdown the computer... ON WINDOWS XP ONLY... u enter:

    VB Code:
    1. shell("shutdown.exe")
    2.  
    3. or shellexecute("shutdown.exe") im not too sure since i dont use it much.

  12. #12
    Fanatic Member ididntdoit's Avatar
    Join Date
    Apr 2006
    Location
    :uoıʇɐɔoן
    Posts
    765

    Talking Re: Shutdown the computer.

    Quote Originally Posted by Oblivion02
    OK dude, well to shutdown the computer... ON WINDOWS XP ONLY... u enter:

    VB Code:
    1. shell("shutdown.exe")
    2.  
    3. 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

    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.
    Visit here to learn to make the VB interface fit you!.
    "I have not failed 10,000 times. I have successfully identified 10,000 ways that will not work" Thomas Edison
    "The day Microsoft makes something that doesn't suck is probably the day they start making vacuum cleaners" -- Ernst Jan Plugge

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