Results 1 to 26 of 26

Thread: [2008] Computer shutdown

  1. #1

    Thread Starter
    Member
    Join Date
    Jan 2009
    Location
    Basement
    Posts
    48

    Exclamation [2008] Computer shutdown

    hey guys i am looking for a command to shutdown/restart my computer when i press a button. can anyone tell me the code?

  2. #2
    Software Carpenter dee-u's Avatar
    Join Date
    Feb 2005
    Location
    Pinas
    Posts
    11,127

    Re: [2008] Computer shutdown

    To shutdown you can execute the folling command: "shutdown -s -t 0".

    To restart: "shutdown -r -t 0".
    Regards,


    As a gesture of gratitude please consider rating helpful posts. c",)

    Some stuffs: Mouse Hotkey | Compress file using SQL Server! | WPF - Rounded Combobox | WPF - Notify Icon and Balloon | NetVerser - a WPF chatting system

  3. #3

    Thread Starter
    Member
    Join Date
    Jan 2009
    Location
    Basement
    Posts
    48

    Re: [2008] Computer shutdown

    thats for a shortcut, im talking about Vb 2008 when a user sets a time to when the computer will restart/shutdown/log off.. i got the timer part done all i need now is a code for the computer to shutdown

  4. #4
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: [2008] Computer shutdown

    Quote Originally Posted by BlackDragon
    thats for a shortcut, im talking about Vb 2008 when a user sets a time to when the computer will restart/shutdown/log off.. i got the timer part done all i need now is a code for the computer to shutdown
    No, that's not for a shortcut, or not specifically anyway. Calling Process.Start in VB is the equivalent of executing a file via a shortcut or from Windows Explorer or whatever. "shutdown" is the file name, i.e. C:\WINDOWS\system32\shutdown.exe, and the rest is the arguments.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  5. #5

    Thread Starter
    Member
    Join Date
    Jan 2009
    Location
    Basement
    Posts
    48

    Re: [2008] Computer shutdown

    why isn't it

    Code:
    Shell("shutdown -s")
    ?

  6. #6
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: [2008] Computer shutdown

    Quote Originally Posted by BlackDragon
    why isn't it

    Code:
    Shell("shutdown -s")
    ?
    You can call Shell in VB.NET but you shouldn't. Shell is a holdover from VB6 while Process.Start is the .NET method designed for starting processes. With regards to the commandline arguments, if I remember correctly the "-t 0" part means in a time of zero seconds, i.e. immediately, which is superfluous. If you did want to wait for a specific time period then the -t switch would be required.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  7. #7
    Software Carpenter dee-u's Avatar
    Join Date
    Feb 2005
    Location
    Pinas
    Posts
    11,127

    Re: [2008] Computer shutdown

    VB.Net Code:
    1. Dim p As New Process()
    2. p.StartInfo.FileName = "Shutdown.exe"
    3. p.StartInfo.Arguments = "-s -t 0"
    4. p.StartInfo.CreateNoWindow = True
    5. p.StartInfo.WindowStyle = ProcessWindowStyle.Hidden
    6. p.Start()
    Regards,


    As a gesture of gratitude please consider rating helpful posts. c",)

    Some stuffs: Mouse Hotkey | Compress file using SQL Server! | WPF - Rounded Combobox | WPF - Notify Icon and Balloon | NetVerser - a WPF chatting system

  8. #8

    Thread Starter
    Member
    Join Date
    Jan 2009
    Location
    Basement
    Posts
    48

    Re: [2008] Computer shutdown

    Here is how my program should work

    Shutdown (radioButton)[
    Code:
    shutdown.select()
    , Restart(radioButton), Log off (radio button)
    |
    Current Time (Constantly updates with a timer)
    |
    Add user time (3 textboxs)
    |
    Final time
    |
    Shutdown, Restart, Log Off (all Buttons) [visible =false]
    |
    Code:
     Shell("shutdown - s")
    .......

  9. #9
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: [2008] Computer shutdown

    Quote Originally Posted by dee-u
    VB.Net Code:
    1. Dim p As New Process()
    2. p.StartInfo.FileName = "Shutdown.exe"
    3. p.StartInfo.Arguments = "-s -t 0"
    4. p.StartInfo.CreateNoWindow = True
    5. p.StartInfo.WindowStyle = ProcessWindowStyle.Hidden
    6. p.Start()
    Just:
    vb.net Code:
    1. Process.Start("shutdown", "-s")
    is enough. If that creates a Console window that you don't want then you can do this to keep it succinct:
    vb.net Code:
    1. Process.Start(New ProcessStartInfo("shutdown", "-s") With {.CreateNoWindow = True})
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  10. #10

    Thread Starter
    Member
    Join Date
    Jan 2009
    Location
    Basement
    Posts
    48

    Re: [2008] Computer shutdown

    ok thank you much

  11. #11
    Software Carpenter dee-u's Avatar
    Join Date
    Feb 2005
    Location
    Pinas
    Posts
    11,127

    Re: [2008] Computer shutdown

    Quote Originally Posted by jmcilhinney
    Just:
    vb.net Code:
    1. Process.Start("shutdown", "-s")
    is enough. If that creates a Console window that you don't want then you can do this to keep it succinct:
    vb.net Code:
    1. Process.Start(New ProcessStartInfo("shutdown", "-s") With {.CreateNoWindow = True})
    Is that a LINQ?
    Regards,


    As a gesture of gratitude please consider rating helpful posts. c",)

    Some stuffs: Mouse Hotkey | Compress file using SQL Server! | WPF - Rounded Combobox | WPF - Notify Icon and Balloon | NetVerser - a WPF chatting system

  12. #12

    Thread Starter
    Member
    Join Date
    Jan 2009
    Location
    Basement
    Posts
    48

    Re: [2008] Computer shutdown

    Oh no it don't work

  13. #13
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: [2008] Computer shutdown

    Quote Originally Posted by dee-u
    Is that a LINQ?
    Follow the Initialiser Syntax link in my signature.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  14. #14

    Thread Starter
    Member
    Join Date
    Jan 2009
    Location
    Basement
    Posts
    48

    Re: [2008] Computer shutdown

    ugh guys help... niether of the stuff i tried works

    when the radiobutton1 is checked then i want the system to shutdown only if hourLabel.text and minuteLabel.text and secondLabel.text to match up (=) with newHourLabel.text and NewMinuteLabel.text and newSecondLabel.text



    any help?

  15. #15
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: [2008] Computer shutdown

    Quote Originally Posted by BlackDragon
    Oh no it don't work
    One point to note is that dee-u's "-t 0" isn't so superflous after all because it seems that the default delay is 30 seconds. If you're cool with that then you can omit the -t switch. As for it working or not, I just tried the second code snippet I provided and it worked for me.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  16. #16
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: [2008] Computer shutdown

    Quote Originally Posted by BlackDragon
    ugh guys help... niether of the stuff i tried works

    when the radiobutton1 is checked then i want the system to shutdown only if hourLabel.text and minuteLabel.text and secondLabel.text to match up (=) with newHourLabel.text and NewMinuteLabel.text and newSecondLabel.text



    any help?
    This thread is about shutting down the computer. Does the shutdown cod work or not? You're getting off onto a completely separate topic now, so you should create a new thread for that. One topic per thread and one thread per topic.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  17. #17
    PowerPoster sparrow1's Avatar
    Join Date
    May 2005
    Location
    Globetrotter
    Posts
    2,820

    Re: [2008] Computer shutdown

    Hi,

    Here's is an explanation how to manipulate Shutdown.exe.

    Description of the Shutdown.exe Tool
    Shutdown.exe uses the following syntax:

    shutdown \\computername /l /a /r /t:xx "msg" /y /c
    You can use the following switches with Shutdown.exe:

    * \\computername: Use this switch to specify the remote computer to shut down. If you omit this parameter, the local computer name is used.
    * /l (Note that this is a lowercase "L" character): Use this switch to shut down the local computer
    * /a: Use this switch to quit a shutdown operation. You can do this only during the time-out period. If you use this switch, all other parameters are ignored.
    * /r: Use this switch to restart the computer instead of fully shutting it down.
    * /t:xx: Use this switch to specify the time (in seconds) after which the computer is shut down. The default is 20 seconds.
    * "msg": Use this switch to specify a message during the shutdown process. The maximum number of characters that the message can contain is 127.
    * /y: Use this switch to force a "yes" answer to all queries from the computer.
    * /c: Use this switch quit all running programs. If you use this switch, Windows forces all programs that are running to quit. The option to save any data that may have changed is ignored. This can result in data loss in any programs for which data is not previously saved.

    Wkr,

    sparrow1
    Wkr,
    sparrow1

    If I helped you, don't forget to Rate my post. Thank you

    I'm using Visual Studio.Net 2003 and
    2005
    How to learn VB.Net Create setup with VB 2005 Drawing for beginners VB.Net Tutorials GDI+ Tutorials
    Video's for beginners

  18. #18

    Thread Starter
    Member
    Join Date
    Jan 2009
    Location
    Basement
    Posts
    48

    Re: [2008] Computer shutdown

    Quote Originally Posted by sparrow1
    Hi,

    Here's is an explanation how to manipulate Shutdown.exe.

    Description of the Shutdown.exe Tool
    Shutdown.exe uses the following syntax:

    shutdown \\computername /l /a /r /t:xx "msg" /y /c
    You can use the following switches with Shutdown.exe:

    * \\computername: Use this switch to specify the remote computer to shut down. If you omit this parameter, the local computer name is used.
    * /l (Note that this is a lowercase "L" character): Use this switch to shut down the local computer
    * /a: Use this switch to quit a shutdown operation. You can do this only during the time-out period. If you use this switch, all other parameters are ignored.
    * /r: Use this switch to restart the computer instead of fully shutting it down.
    * /t:xx: Use this switch to specify the time (in seconds) after which the computer is shut down. The default is 20 seconds.
    * "msg": Use this switch to specify a message during the shutdown process. The maximum number of characters that the message can contain is 127.
    * /y: Use this switch to force a "yes" answer to all queries from the computer.
    * /c: Use this switch quit all running programs. If you use this switch, Windows forces all programs that are running to quit. The option to save any data that may have changed is ignored. This can result in data loss in any programs for which data is not previously saved.

    Wkr,

    sparrow1
    thx man this is really useful but right now i am trying to get my program to shutdown my computer. so we are still in the topic but it is about my program that matches up those 3 labels with another 3 labels and shuts down the computer...

  19. #19
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: [2008] Computer shutdown

    Quote Originally Posted by sparrow1
    Hi,

    Here's is an explanation how to manipulate Shutdown.exe.

    Description of the Shutdown.exe Tool
    Shutdown.exe uses the following syntax:

    shutdown \\computername /l /a /r /t:xx "msg" /y /c
    You can use the following switches with Shutdown.exe:

    * \\computername: Use this switch to specify the remote computer to shut down. If you omit this parameter, the local computer name is used.
    * /l (Note that this is a lowercase "L" character): Use this switch to shut down the local computer
    * /a: Use this switch to quit a shutdown operation. You can do this only during the time-out period. If you use this switch, all other parameters are ignored.
    * /r: Use this switch to restart the computer instead of fully shutting it down.
    * /t:xx: Use this switch to specify the time (in seconds) after which the computer is shut down. The default is 20 seconds.
    * "msg": Use this switch to specify a message during the shutdown process. The maximum number of characters that the message can contain is 127.
    * /y: Use this switch to force a "yes" answer to all queries from the computer.
    * /c: Use this switch quit all running programs. If you use this switch, Windows forces all programs that are running to quit. The option to save any data that may have changed is ignored. This can result in data loss in any programs for which data is not previously saved.

    Wkr,

    sparrow1
    That's kinda weird given that this is what I got when I executed "shutdown \?" in a Console window:
    Usage: shutdown [-i | -l | -s | -r | -a] [-f] [-m \\computername] [-t xx] [-c "comment"] [-d up:xx:yy]

    No args Display this message (same as -?)
    -i Display GUI interface, must be the first option
    -l Log off (cannot be used with -m option)
    -s Shutdown the computer
    -r Shutdown and restart the computer
    -a Abort a system shutdown
    -m \\computername Remote computer to shutdown/restart/abort
    -t xx Set timeout for shutdown to xx seconds
    -c "comment" Shutdown comment (maximum of 127 characters)
    -f Forces running applications to close without warning
    -d [u][p]:xx:yy The reason code for the shutdown
    u is the user code
    p is a planned shutdown code
    xx is the major reason code (positive integer less than 256)
    yy is the minor reason code (positive integer less than 65536)
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  20. #20

    Thread Starter
    Member
    Join Date
    Jan 2009
    Location
    Basement
    Posts
    48

    Re: [2008] Computer shutdown

    Dude, guys on topic please!!! if you want go talk somewhere in the general topic section or w.e don't Spam my thread. i really want to get this thing working and my head hurts so bad from all this work yet, i thought i could get some help here, so please help!

  21. #21
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: [2008] Computer shutdown

    Quote Originally Posted by BlackDragon
    thx man this is really useful but right now i am trying to get my program to shutdown my computer. so we are still in the topic but it is about my program that matches up those 3 labels with another 3 labels and shuts down the computer...
    Matching up labels has nothing really to do with shutting down the computer. Does the shutdown code work, i.e. does your computer shutdown if you execute it? If so then that's the topic of this thread covered. If you want to ask another question about how to match the text in controls then that's another topic and belongs in another thread. That's how the forum is kept orderly and easy to use for everyone, including those who may be searching for information at a later date. If you start jumbling information about different topics in the same thread then it becomes harder for others to find information on any of those topics.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  22. #22

    Thread Starter
    Member
    Join Date
    Jan 2009
    Location
    Basement
    Posts
    48

    Re: [2008] Computer shutdown

    this was about shutting down my computer and still is, because i thought i could get it to work, but it don't want to work so i add more information for you guy to figure out. what i need to make this thing working.

  23. #23
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: [2008] Computer shutdown

    Quote Originally Posted by BlackDragon
    this was about shutting down my computer and still is, because i thought i could get it to work, but it don't want to work so i add more information for you guy to figure out. what i need to make this thing working.
    So you're saying that if you execute the code that I provided in post #9, your computer will not shutdown. Is that correct?
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  24. #24

    Thread Starter
    Member
    Join Date
    Jan 2009
    Location
    Basement
    Posts
    48

    Re: [2008] Computer shutdown

    yes it doesn't work

  25. #25
    Hyperactive Member
    Join Date
    Jan 2009
    Posts
    448

    Re: [2008] Computer shutdown

    Assuming you have a radiobutton named radioButton1 and a button named Button1 this code will work(put it under the Button1's click event:

    Code:
    If radioButton1.checked = True Then
    process.start("shutdown", "-r")
    Else
    Messagebox.Show("Not Checked")
    End If
    You should be able to work out the label thing on your own.

  26. #26

    Thread Starter
    Member
    Join Date
    Jan 2009
    Location
    Basement
    Posts
    48

    Re: [2008] Computer shutdown

    ugh no, it don't work when my 6 labels match up... but the whole thing works fine thx man

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