-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathShutdown.c
More file actions
108 lines (68 loc) · 2.35 KB
/
Shutdown.c
File metadata and controls
108 lines (68 loc) · 2.35 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
/*@Shyed Shahriar Housaini
Copyright: @uthor*/
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#include <unistd.h>
#include <windows.h>
///#include <threads.h>
#include <conio.h>
#include <dos.h>
#include <direct.h>
#include <math.h>
#include <stdbool.h>
#include<ctype.h>
#include <string.h>
#include <strings.h>
int main(void)
{
printf (" ");
return 0;
}
/**
https://www.geeksforgeeks.org/cc-program-shutdown-system/?ref=rp
C/C++ program to shutdown a system
23-12-2016
How to shutdown your computer in Linux and/or Windows?
The idea is to use system() in C. This function is used to invoke operating system commands from C program.
Linux OS:
filter_none
edit
play_arrow
brightness_4
// C program to shutdown in Linux
#include <stdio.h>
#include <stdlib.h>
int main()
{
// Running Linux OS command using system
system("shutdown -P now");
return 0;
}
Windows OS:
Shutdown/ Log off/ Restart a Windows OS
We will make use of system() from < stdlib.h > to perform a system operation with the help of a C program.To perform any of the afore-mentioned system operation we will code as:
filter_none
edit
play_arrow
brightness_4
#include <stdio.h>
#include <stdlib.h>
int main()
{
system("c:\\windows\\system32\\shutdown /i");
return 0;
}
The argument to the system function is the path to OS and /i is one of the entity from the vast options available to us.To view the options, we run cmd and type:
C:\Users\User>shutdown
The shutdown command presents us with a list of options available for us.These are :
To perform different operations, we just replace the last “/path” in system() argument.The common operations are:
Shutdown
system("c:\\windows\\system32\\shutdown /s");
Restart
system("c:\\windows\\system32\\shutdown /r");
Logoff
system("c:\\windows\\system32\\shutdown /l");
This article is contributed by Sahil Chhabra and Amartya Ranjan Saikia. If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please write comments if you find anything incorrect, or you want to share more information about the topic discussed above.
**/