Programming C, C++, Java, PHP, Ruby, Turing, VB
Computer Science Canada 
Programming C, C++, Java, PHP, Ruby, Turing, VB  

Username:   Password: 
 RegisterRegister   
 Shutting down using batch files
Index -> General Programming
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
lord_pwnerer




PostPosted: Tue Nov 28, 2006 5:35 pm   Post subject: Shutting down using batch files

Using batch files to execute basic windows commands


In this tutorial, you will learn how to create batch files that can perform system functions, such as shutting down, restarting, or even logging off. I am aware of the fact that languages such as VB and C++ can do this because they have access to Windows API, but if you want to learn how to this using languages such as Turing, or Java, that do not have access to Windows API, read on.

What is a batch file?
A batch file is a text file containing a series of commands intended to be executed by the command interpreter. When a batch file is run, the shell program reads the file and executes its commands, normally line-by-line. DOS batch files have the extension of .BAT

How do I make a batch file?
To make a batch file, all you have to do, is open up a simple text editor, write what you want the batch file to do, and save it as "filename.bat".

Why the hell would you want me to learn this?
Well, batch files are extremely usefull to execute commands that a language is not capable of executing by itself. For example, Turing can shut down the computer by using the Sys.Exec command, but you can make batch files that can either, shutdown, restart, or even logoff the computer. And if you wanted to integrate this into your Turing program, all you would have to would be to execute the batch file with Sys.Exec.


Let's start with shutting down.
To do this, all you need to do is open up your text editor and put the following code:

code:
shutdown -s -t 00 -c "Your computer is now shutting down"


Let's go through the different parts of the code.

shutdown this tells the computer that it is going to be performing a function similar to shutting down

-s This tells the computer that it is going to be shutting down (hence the 's')

-t 00 This tells the computer to wait 0 seconds before beginning to shut down.

-c This allows you to put a comment that the user will see while, the computer is shutting down, and/or the counter is counting down.

"blahblah" This is the comment, and must be in quotations, immediately following the
'-c' .

After this is done, simple save it as a 'filename.bat' file and execute it (or use a program to execute it)

Let's move on to restarting
Once you have mastered the shutdown procedure, restarting is simple. All you must do, is, in your text file, replace the '-s' with a '-r'. This sets the shutdown action to restart. If all has gone correctly, your code should look like this.

code:
shutdown -r -t 00 -c "Your computer is now restarting"


After this is done, simple save it as a 'filename.bat' file and execute it (or use a program to execute it)

Logging Off!
The moment that you guys are actually waiting for, because logging off using a language as simple as Turing (not that I'm putting Turing down) is crazy!

All you must do to make a batch file logoff is this. Replace the '-s' from the original code, and make it a '-l'. This sets the shutdown action to logoff. If all has gone correctly, your code should look like this.

code:
shutdown -l -t 00 -c "Your computer is now logging off"


After this is done, simple save it as a 'filename.bat' file and execute it (or use a program to execute it)

Forcing!
Well, now that you know how to do the basic commands, you're wondering, what if a program that isn't responding delays the shutdown. For example, if you want the computer to shutdown by itself, but a program that isn't responding prompts a user to 'Cancel' or 'End Now', the shutdown will not succeed. This is what we have the force command for.

The force command forces these programs to end, without prompting a user for a choice.
This command can be achieved by simply adding a '-f' in between the shutdown option and the time function. If all has gone correctly, your code should look like this.

code:
shutdown -s -f -t 00 -c "Your computer is now shutting down"


After this is done, simple save it as a 'filename.bat' file and execute it (or use a program to execute it)


Command Review
Let's review the commands:
shutdown tells computer what's about to follow
-s shutdown
-r restart
-l logoff
-f force programs to end
-txx two digit number that delays (in seconds) the shutdown
-c " " comment that will be shown if there is a delay

There you have it! Using (just for an example) the Sys.Exec command for Turing, you can execute these batch files, which will, in turn perform the desired procedure. Hoped you liked it. Please comment for questions/improvements. It's my first tutorial, so please don't flame to badly.
Sponsor
Sponsor
Sponsor
sponsor
Clayton




PostPosted: Wed Nov 29, 2006 8:52 am   Post subject: (No subject)

not too bad, although I'm sure this can go much deeper than just shutting down/restarting/logging off, this is pretty basic stuff, perhaps think about adding more to it.

lord_pwnerer wrote:

"blahblah" This is the comment, and must be n parenthesis, immediately following the
'-c' .


that would be quotation marks, actually Razz
wtd




PostPosted: Wed Nov 29, 2006 12:48 pm   Post subject: (No subject)

What about conditionals, looping, variables, and comments? Please expand the tutorial. Smile
lord_pwnerer




PostPosted: Wed Nov 29, 2006 4:46 pm   Post subject: (No subject)

Sorry about that, I will change it. About the expansion, yes, this is very basic. You can obviously do many things with this method, and these are just a taste. I will expand on the tutorial, thanks for the input. I just wanted to let people know about these (basic) commands.

I'll follow up in a bit, (maybe not this week because I'm busy this week)
Andy




PostPosted: Wed Nov 29, 2006 6:37 pm   Post subject: (No subject)

the problem with your tutorial is that you're not teaching how to write batch files. all you did was list a 1 dos command that can be inputted into the command prompt.
Clayton




PostPosted: Wed Nov 29, 2006 6:59 pm   Post subject: (No subject)

I also found your descriptions on what to do very vague. I also like to know why I'm doing something, just because someone told me to do something doesn't quite cut it Very Happy
lord_pwnerer




PostPosted: Thu Nov 30, 2006 4:31 pm   Post subject: (No subject)

It was originally only supposed to be for writing batch files that shutdown/reastart/logoff the computer..... And the point was so that languages such as Turing that arn't capable of doing such things can easily be done with the use of batch files.

I will continue with variables and looping in a bit.
md




PostPosted: Sun Dec 03, 2006 2:07 pm   Post subject: (No subject)

Uhh, turing can run other executables can it not? Therefor Turing is perfectly capable of doing EVERYTHING a batch file can do; perhaps more.

Using turing to do that however is not the greatest use of space/time/thought
Sponsor
Sponsor
Sponsor
sponsor
lord_pwnerer




PostPosted: Sun Dec 03, 2006 6:16 pm   Post subject: (No subject)

md wrote:
Uhh, turing can run other executables can it not? Therefor Turing is perfectly capable of doing EVERYTHING a batch file can do; perhaps more.


Yeah...that's what the point of this tutorial was, to teach how to make batch files THAT COULD BE EXECUTED using Turing.
[Gandalf]




PostPosted: Sun Dec 03, 2006 11:35 pm   Post subject: (No subject)

Why make a batch file? If you can use Sys.Exec() to execute the batch file, you might as well use Sys.Exec() to directly execute anything you might have put in the batch file.
wtd




PostPosted: Mon Dec 04, 2006 12:45 am   Post subject: (No subject)

Batch files will run on any Windows machine. How many Windows machines do you know that have Turing installed? Or perhaps you'd like to distribute a large Turing "executable" every time you wish to show off your system scripting prowess?
[Gandalf]




PostPosted: Mon Dec 04, 2006 4:38 am   Post subject: (No subject)

wtd wrote:
Batch files will run on any Windows machine. How many Windows machines do you know that have Turing installed? Or perhaps you'd like to distribute a large Turing "executable" every time you wish to show off your system scripting prowess?

Yes, but all we care about is shutting down/restarting/logging off using Turing, which is of course why we're making batch scripts in the first place, to be executed by Turing. After all, "that's what the point of this tutorial was, to teach how to make batch files THAT COULD BE EXECUTED using Turing."
lord_pwnerer




PostPosted: Mon Dec 04, 2006 7:54 am   Post subject: (No subject)

Ok Ok! I'm sorry! Sad Sad Let me go cry in my corner now.
Clayton




PostPosted: Mon Dec 04, 2006 4:28 pm   Post subject: (No subject)

We're not trying to make you cry, it's just that some people apparantly don't see much point in making a batch file to be executed by Turing, seeing as Turing can do anything that a batch file can by using the Sys.Exec() function anyways. However, don't let that discourage you from continuing on with this Tutorial. It may just be that someone wants to know how to make a batch file, just not necessarily to run using Turing Very Happy
Display posts from previous:   
   Index -> General Programming
View previous topic Tell A FriendPrintable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic

Page 1 of 1  [ 14 Posts ]
Jump to:   


Style:  
Search: