hey guys i am looking for a command to shutdown/restart my computer when i press a button. can anyone tell me the code?
Printable View
hey guys i am looking for a command to shutdown/restart my computer when i press a button. can anyone tell me the code?
To shutdown you can execute the folling command: "shutdown -s -t 0".
To restart: "shutdown -r -t 0".
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 :o
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.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.Quote:
Originally Posted by BlackDragon
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()
Here is how my program should work
Shutdown (radioButton)[, Restart(radioButton), Log off (radio button)Code:shutdown.select()
|
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")
Just:Quote:
Originally Posted by dee-u
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("shutdown", "-s")vb.net Code:
Process.Start(New ProcessStartInfo("shutdown", "-s") With {.CreateNoWindow = True})
ok thank you much
Is that a LINQ?Quote:
Originally Posted by jmcilhinney
Oh no it don't work
Follow the Initialiser Syntax link in my signature.Quote:
Originally Posted by dee-u
ugh guys help... niether of the stuff i tried works :sick:
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?
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.Quote:
Originally Posted by BlackDragon
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.Quote:
Originally Posted by BlackDragon
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.:duck: 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...Quote:
Originally Posted by sparrow1
That's kinda weird given that this is what I got when I executed "shutdown \?" in a Console window:Quote:
Originally Posted by sparrow1
Quote:
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)
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!
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.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.:ehh:
So you're saying that if you execute the code that I provided in post #9, your computer will not shutdown. Is that correct?Quote:
Originally Posted by BlackDragon
yes it doesn't work
Assuming you have a radiobutton named radioButton1 and a button named Button1 this code will work(put it under the Button1's click event:
You should be able to work out the label thing on your own.Code:If radioButton1.checked = True Then
process.start("shutdown", "-r")
Else
Messagebox.Show("Not Checked")
End If
ugh no, it don't work when my 6 labels match up... but the whole thing works fine thx man