Computer can be shutdown using c program. But the commands are different in Windows and Linux. The system() function in c can be used to execute system commands ( Windows command or Linux command ). To shutdown the computer using c program, we execute the appropriate shutdown command using the system() function.
Search This Blog
Showing posts with label system. Show all posts
Showing posts with label system. Show all posts
How to Execute Windows Commands in C
You may have used Windows commands like ipconfig, netstat, type, set, mkdir, cd etc in cmd (DOS Prompt or Command Prompt). You can execute these commands from a C program. This post will tell you how to execute Windows commands (cmd commands) from c program. To execute different Windows commands, you can use the system() function c language. The system() function is used to invoke command processor to execute a given command. The command which is to be executed is passed as argument to the function. An example c program with system() function is shown below.
C Program to Logoff or Signout From Windows
You can logoff (also called logout or sign out) from a windows computer using c program. This can be done by executing a command. You just have to execute the command shutdown /l which executes shutdown.exe with command line parameter /l to force logout from Windows. The system() function in c can be used to execute any system commands. Therefore, the following simple c program when executed, will logout you from Windows instantly.
#include<stdio.h>
void main()
{
system("shutdown /l");
}
C Program to Display and Set System Time and Date Using 8086 Interrupts
This is a C Program to Display and Set System Time and Date Using 8086 Interrupts. Interrupt number 21 (in hexadecimal) is used to:
![]() |
| Output of c Program to get and set system time and date |
- Get System time
- Set System time
- Get System Date
- Set System Date
To Get system date:
- Call interrupt 0x21 (hexadecimal)
- AH (higher byte of accumulator) should be made equal to 2A (hex) before calling interrupt
Output:
- day in DL
- Month in DH
- Year in CX
To set System Date:
- Call interrupt 0x21 (hexadecimal)
- AH (higher byte of accumulator) should be made equal to 2B (hex) before calling interrupt
- Before Calling interrupt, store:- Year in CX
- Month in DH
- Day in DL
To Get system time:
- Call interrupt 0x21 (hexadecimal)
- AH (higher byte of accumulator) should be made equal to 2C (hex) before calling interrupt
Output:
- Hours in CH
- Minutes in CL
- Seconds in DH
- 1/100 th of a second in DL
To set System Time:
- Call interrupt 0x21 (hexadecimal)
- AH (higher byte of accumulator) should be made equal to 2D (hex) before calling interrupt
- Before Calling interrupt, store:
- Hour in CH
- Minutes in CL
- Seconds in DH
- 1/100 th of second in DL
#include<stdio.h>
#include<dos.h>
#include<conio.h>
void main()
{
int day,month,year,tflag=0,dflag=0,hr,min,sec;
union REGS inreg,outreg;
DISDATE:printf("\nCurrent date:\n");
inreg.h.ah=0x2a;
int86(0x21,&inreg,&outreg);
printf("%d-%d-%d ",outreg.h.dl,outreg.h.dh,outreg.x.cx);
switch(outreg.h.al)
{
case 0:printf("Sunday");break;
case 1:printf("Monday");break;
case 2:printf("Tueday");break;
case 3:printf("Wednesday");break;
case 4:printf("Thursday");break;
case 5:printf("Friday");break;
case 6:printf("Sunday");break;
}
if(dflag==1)
goto SETTIME;
DISTIME:printf("\nCurrent Time:\n");
inreg.h.ah=0x2c;
int86(0x21,&inreg,&outreg);
printf("%d:%d:%d.%d ",outreg.h.ch,outreg.h.cl,outreg.h.dh,outreg.h.dl);
if(tflag==1)
goto END;
SETDATE:printf("\nSet Date.\nDay,Month and Year\n");
scanf("%d%d%d",&day,&month,&year);
inreg.h.ah=0x2b;
inreg.x.cx=year;
inreg.h.dh=month;
inreg.h.dl=day;
int86(0x21,&inreg,&outreg);
if(outreg.h.al==0x00)
{
dflag=1;
goto DISDATE;
}
else
{
printf("\nInvalid entry");
getch();
exit(0);
}
SETTIME:printf("\nSet Time. Enter Time.\nHour,Minutes and Seconds\n");
scanf("%d%d%d",&hr,&min,&sec);
inreg.h.ah=0x2d;
inreg.h.ch=hr;
inreg.h.dh=sec;
inreg.h.cl=min;
inreg.h.dl=0;
int86(0x21,&inreg,&outreg);
if(outreg.h.al==0x00)
{
tflag=1;
goto DISTIME;
}
else
{
printf("\nInvalid entry");
getch();
exit(0);
}
END: getch();
}
Subscribe to:
Posts (Atom)
