|
-
Jan 16th, 2009, 01:44 AM
#1
Thread Starter
Member
[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?
-
Jan 16th, 2009, 01:58 AM
#2
Re: [2008] Computer shutdown
To shutdown you can execute the folling command: "shutdown -s -t 0".
To restart: "shutdown -r -t 0".
-
Jan 16th, 2009, 02:02 AM
#3
Thread Starter
Member
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
-
Jan 16th, 2009, 02:10 AM
#4
Re: [2008] Computer shutdown
 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.
-
Jan 16th, 2009, 02:12 AM
#5
Thread Starter
Member
Re: [2008] Computer shutdown
why isn't it
Code:
Shell("shutdown -s")
?
-
Jan 16th, 2009, 02:16 AM
#6
Re: [2008] Computer shutdown
 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.
-
Jan 16th, 2009, 02:21 AM
#7
Re: [2008] Computer shutdown
VB.Net Code:
Dim p As New Process()
p.StartInfo.FileName = "Shutdown.exe"
p.StartInfo.Arguments = "-s -t 0"
p.StartInfo.CreateNoWindow = True
p.StartInfo.WindowStyle = ProcessWindowStyle.Hidden
p.Start()
-
Jan 16th, 2009, 02:22 AM
#8
Thread Starter
Member
Re: [2008] Computer shutdown
Here is how my program should work
Shutdown (radioButton)[ , 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")
.......
-
Jan 16th, 2009, 02:27 AM
#9
Re: [2008] Computer shutdown
 Originally Posted by dee-u
VB.Net Code:
Dim p As New Process()
p.StartInfo.FileName = "Shutdown.exe"
p.StartInfo.Arguments = "-s -t 0"
p.StartInfo.CreateNoWindow = True
p.StartInfo.WindowStyle = ProcessWindowStyle.Hidden
p.Start()
Just:
vb.net Code:
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:
Process.Start(New ProcessStartInfo("shutdown", "-s") With {.CreateNoWindow = True})
-
Jan 16th, 2009, 02:29 AM
#10
Thread Starter
Member
Re: [2008] Computer shutdown
-
Jan 16th, 2009, 02:35 AM
#11
Re: [2008] Computer shutdown
 Originally Posted by jmcilhinney
Just:
vb.net Code:
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:
Process.Start(New ProcessStartInfo("shutdown", "-s") With {.CreateNoWindow = True})
Is that a LINQ?
-
Jan 16th, 2009, 02:36 AM
#12
Thread Starter
Member
Re: [2008] Computer shutdown
-
Jan 16th, 2009, 02:39 AM
#13
Re: [2008] Computer shutdown
 Originally Posted by dee-u
Is that a LINQ?
Follow the Initialiser Syntax link in my signature.
-
Jan 16th, 2009, 02:42 AM
#14
Thread Starter
Member
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?
-
Jan 16th, 2009, 02:43 AM
#15
Re: [2008] Computer shutdown
 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.
-
Jan 16th, 2009, 02:44 AM
#16
Re: [2008] Computer shutdown
 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.
-
Jan 16th, 2009, 02:46 AM
#17
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
-
Jan 16th, 2009, 02:49 AM
#18
Thread Starter
Member
Re: [2008] Computer shutdown
 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...
-
Jan 16th, 2009, 02:51 AM
#19
Re: [2008] Computer shutdown
 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)
-
Jan 16th, 2009, 02:53 AM
#20
Thread Starter
Member
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!
-
Jan 16th, 2009, 02:54 AM
#21
Re: [2008] Computer shutdown
 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.
-
Jan 16th, 2009, 02:56 AM
#22
Thread Starter
Member
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.
-
Jan 16th, 2009, 03:03 AM
#23
Re: [2008] Computer shutdown
 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?
-
Jan 16th, 2009, 12:00 PM
#24
Thread Starter
Member
Re: [2008] Computer shutdown
-
Jan 16th, 2009, 12:51 PM
#25
Hyperactive Member
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.
-
Jan 16th, 2009, 01:23 PM
#26
Thread Starter
Member
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|