How to: Command Windows with C

There are lot of programming and scripting languages in this IT world. If considering windows i think, the easiest and interesting code is bat code. It is nothing but series of windows commands. mostly win users first get known about bat codes. That is -- windows commanding.(If write a series of win commands into a file and set it's extension to .bat then it becomes bat file and it can be executed)

There are lot of things that can be done using bat codes. Ex: delete a file, move, copy files,format drives, show message box, end processes, start a program, shutdown, etc

if considering C language, we all know it is strict, and difficult to use. But if we use some system commands with this, it becomes interesting-funny and easy. We can easily execute external programs or commands and show results in console. For example, if we take file reading example, it's becomes little bit lengthy in C. But if we use the command 'TYPE [FILENAME]" from windows, then we can finish it off with a single line!!

In C (or C++) programming, we can execute windows commands ( or commands related to any other OSes) using ' system(); ' function. You have to include the header file 'iostream.h' for this function.

On the basis of this, I've given some examples for you:

Example 1: Shutdown Windows

#include using namespace std; int main() { cout << "\t\t Shutdown Windows \n\n"; cout << "Press any key to shutdown windows"; cin.get(); system("shutdown -r -t 0 -f"); return 0; }

Example 2: Show Special folders path

#include<iostream> using namespace std; int main() { system("echo Temporary Folder is: %temp%\n"); system("echo Windows in installed in: %systemdrive%\n"); system("echo Application data directory is: %appdata%\n"); system("echo The time and date: %time% and %date%\npause"); return 0; } Thus... What? Find out more yourself!!