C语言写定时关机重启小程序
C语言(关机小程序)

C语⾔(关机⼩程序)关机⼩程序利⽤system写出且复习借鉴于⽼九学堂C语⾔笔记:1 #include<stdio.h>2 #include<stdlib.h>3 #include<string.h>4int print()5 {6 printf("++++++关机⼩程序+++++\n");7 printf("1、定时关机(10分钟以内),请注意需要保存的⽂件\n");8 printf("2、⽴即关闭计算机系统\n");9 printf("3、注销系统\n");10 printf("0、推出程序\n");11return0;12 }13void main()14 {15 system("title C语⾔关机程序");16 system("mode con cols=48 lines=25");17 system("color 72");18 system("date /T");19 system("TIME /T");20char cmd[20]="shutdown -s -t";21char t[5]="0";22 print();23int choose;24 printf("请选择关机的选项:\n");25 scanf("%d",&choose);26 getchar();27switch(choose)28 {29case1:30 printf("输⼊⼏秒后关机,进⾏⾃动关机?(0~600秒)\n");31 scanf("%d",&t);32 system(strcat(cmd,t));33break;34case2:35 system("shutdown -p");36break;37case3:38 system("shutdown -1");39break;40case0:41break;42default:43 printf("选择错误\n");44 }45 system("pause");46 exit(0);47 }48 ```49希望⼤家能喜欢⼀起来进步学习。
c#实现关机,注销,重启源代码

Re:c#实现关机,注销,重启源代码另一份代码using System;using System.Drawing;using System.Collections;using ponentModel;using System.Windows.Forms;using System.Data;using System.Management;using System.Runtime.InteropServices; //加入此名字间是为了引用Windows API来实现关机namespace RebootComputer{public class Form1 : System.Windows.Forms.Form{//---------------这部分都是控件--------private System.Windows.Forms.Button Reboot;private System.Windows.Forms.Button ShutDown;private ponentModel.Container components = null;private System.Windows.Forms.Button Exit;//---------------------------------------------------------private ManagementObjectSearcher obj ;//-----------------程序初始化----------------public Form1(){InitializeComponent();}//-----------------------程序释放----------------------protected override void Dispose( bool disposing ){if( disposing ){if (components != null){components.Dispose();}}base.Dispose( disposing );}//-------------------------初始化----------------------private void InitializeComponent(){this.Reboot = new System.Windows.Forms.Button();this.ShutDown = new System.Windows.Forms.Button();this.Exit = new System.Windows.Forms.Button();this.SuspendLayout();//// Reboot//this.Reboot.Location = new System.Drawing.Point(16, 16); = "Reboot";this.Reboot.TabIndex = 0;this.Reboot.Text = "重启";this.Reboot.Click += new System.EventHandler(this.Reboot_Click);//// ShutDown//this.ShutDown.Location = new System.Drawing.Point(112, 16); = "ShutDown";this.ShutDown.TabIndex = 1;this.ShutDown.Text = "关机";this.ShutDown.Click += new System.EventHandler(this.ShutDown_Click);//// Exit//this.Exit.Location = new System.Drawing.Point(216, 16); = "Exit";this.Exit.TabIndex = 2;this.Exit.Text = "退出";this.Exit.Click += new System.EventHandler(this.Exit_Click);//// Form1//this.AutoScaleBaseSize = new System.Drawing.Size(6, 14);this.ClientSize = new System.Drawing.Size(304, 53);this.Controls.Add(this.Exit);this.Controls.Add(this.ShutDown);this.Controls.Add(this.Reboot); = "Form1";this.Text = "重启、关机";this.ResumeLayout(false);//-----------------主函数,没有此函数可运行不了哦----------[STAThread]static void Main(){Application.Run(new Form1());}//--------------------重启部分程序private void Reboot_Click(object sender, System.EventArgs e){obj = new ManagementObjectSearcher("SELECT * FROM Win32_OperatingSystem");foreach(ManagementObject oc in obj.Get()){DialogResult result = MessageBox.Show("Are you sure want to reboot?","Confirm",MessageBoxB uttons.OKCancel,rmation);//这里为确定用户是否点击“确定”按钮if(DialogResult.OK == result){oc.InvokeMethod("Reboot",null);//点击“确定”按钮后就调用此方法重启机器}}}//---------------关机部分程序------------------------private void ShutDown_Click(object sender, System.EventArgs e){if(DialogResult.OK == MessageBox.Show("Are you sure want to Shut Down?","Confirm",MessageB oxButtons.OKCancel,rmation)) //同上{//主要调用系统API来实现ExitWindowsEx(1,0);}}//这里的[DllImport("user32.dll")]是.net里属性的表达方法,DllImport为引用系统API所在的库" user32.dll"[DllImport("user32.dll")]//主要API是这个,注意:必须声明为static externprivate static extern int ExitWindowsEx(int x,int y);//这个是退出按钮的实现,即实现程序的退出private void Exit_Click(object sender, System.EventArgs e){Application.Exit();}}}c#实现关机,注销,重启源代码一. 设计关闭Windows窗体1. 界面的设计新建一个标准工程,向工程中增加一个Windows窗体并向窗体中添加如下控件,并分别设置其属性:控件名类别 Text 控件名类别TextCheckBox1 CheckBox 自动关机GroupBox1 GroupBox 当前系统时间CheckBox1 CheckBox 倒计时执行操作 GroupBox2 GroupBox 设定时间CheckBox1 CheckBox 定时报警 TxtTime TextBoxButCancle Button 取消 SetupTime DateTimePickerButReOpen Button 重新启动 SetupDate DateTimePickerButClose Button 关机Timer1 Timer 100ButSysInto Button 系统信息 ButReLogin Button 注消Windows窗体界面:将窗体属性中的caption设置为"关闭windows",名称设置为"frmmain"。
c语言自动关机程序代码

c语言自动关机程序代码
1.#include<stdlib.h>和#include<stdio.h>分别是C标准库文件,分别包含了系统函数和输入输出函数。
2. #include <windows.h> 是Windows API的头文件,包含了系统调用的函数和数据类型。
3. int main() 是程序的入口函数。
4. int delay; 定义了一个整型变量 delay。
5. printf('请输入关机延迟时间(单位:秒):'); 输出提示信息,让用户输入延迟时间。
6. scanf('%d', &delay); 从键盘读入一个整数,存放在变量delay 中。
7. printf('%d秒后将自动关机!', delay); 输出提示信息,告诉用户将在多少秒后关机。
8. Sleep(delay * 1000); 延迟指定的时间,此处单位为毫秒,需要将秒转换为毫秒。
9. system('shutdown -s -t 0'); 调用系统命令,执行关机操作。
其中,-s 表示关机,-t 0 表示立即关机。
10. return 0; 结束程序。
- 1 -。
c#实现强制关机、重启和注销

c#实现强制关机、重启、注销c#编程 2011-06-12 10:18:25 阅读0 评论0字号:大中小订阅//case "关闭计算机"://自动关闭主窗口,不需要密码,-f参数是强制执行Gloaljt.Isaq = false;System.Diagnostics.Process myProcess = newSystem.Diagnostics.Process();myProcess.StartInfo.FileName = "cmd.exe";eShellExecute = false;myProcess.StartInfo.RedirectStandardInput = true;myProcess.StartInfo.RedirectStandardOutput = true;myProcess.StartInfo.RedirectStandardError = true;myProcess.StartInfo.CreateNoWindow = true;myProcess.Start();myProcess.StandardInput.WriteLine("shutdown -s -f -t 0");// break;// case "重启计算机"://自动关闭主窗口,不需要密码Gloaljt.Isaq = false;System.Diagnostics.Process myProcesscq = new System.Diagnostics.Process();myProcesscq.StartInfo.FileName = "cmd.exe";eShellExecute = false;myProcesscq.StartInfo.RedirectStandardInput = true;myProcesscq.StartInfo.RedirectStandardOutput = true;myProcesscq.StartInfo.RedirectStandardError = true;myProcesscq.StartInfo.CreateNoWindow = true;myProcesscq.Start();myProcesscq.StandardInput.WriteLine("shutdown -r -f -t 0");break;// case "注销用户名"://注销用户,强制关闭程序Gloaljt.Isaq = false;System.Diagnostics.Process myProcesszx = new System.Diagnostics.Process();myProcesszx.StartInfo.FileName = "cmd.exe";eShellExecute = false;myProcesszx.StartInfo.RedirectStandardInput = true;myProcesszx.StartInfo.RedirectStandardOutput = true;myProcesszx.StartInfo.RedirectStandardError = true;myProcesszx.StartInfo.CreateNoWindow = true;myProcesszx.Start();myProcesszx.StandardInput.WriteLine("shutdown -l -f");// break;。
在C#中运用API函数编写多功能关机程序.doc

我用visual C#来编写一个多功能的关机程序。
该程序具有:定时关机、倒计时关机、关机 提醒、系统信息获取等四项功能,可设宦关机时间精确到秒。
并且让你很快掌握Visual C#H' 对API 的操作程序。
编写过程如下: 一、设计关闭Windows 窗体1 •界面的设计:新建一个标准工程,向工程中增加一个Windows 窗体并向窗体中添加如下控件,并分别 设置其属性:控件名类别 Text 控件名类别 TextCheckBox 0动关机 GixwpBox 1 GroupBox 当前系统时间 CheckBox 倒计时执行操作 GroupBox2 GroupBox 设定时间 CheckBox 定时报警 TxtTime TextBoxB utCancle B utton 取消 SetupTime DateTimePicker ButReOpen Button 重新启动 SetupDate DateTimePickerButClose Button 关机 Timer 1 Timer 100ButSyslnto Button 系统信息 ButReLogin BuMon 注消Windows 窗体界面:将窗体属性中的caption 设置为“关闭windows”,名称设置为'Trmmain^o2. 在窗体类屮引用APl|函数API 两数是构筑Windows 应用程序的基石,是Windows 编程的必备利器。
每一种 Windows 应用程序开发工具都提供了间接或直接调用了 Windows API 〔函数的方法,或者是 调用Windows API I®数的接口,也就是说具备调用动态连接库的能力。
VisualC#和其它开 发工具一样也能够调用动态链接库的API 函数。
在Visual C#中调用APl|的基本过程:首先,在调用APl|Z 前,你必须先导入System.Runtime.InteropServices 这个名称空间。
VC++ 实现定时关机或休眠-MFC 对话框应用程序介绍文档

// DDX/DDV support
BEGIN_MESSAGE_MAP(CAboutDlg, CDialog) END_MESSAGE_MAP() // CTimePowerOffDlg dialog //以离关机时间多长为主 CTimePowerOffDlg::CTimePowerOffDlg(CWnd* pParent /*=NULL*/)
// CTimePowerOffDlg message handlers
BOOL CTimePowerOffDlg::OnInitDialog() {
CDialog::OnInitDialog();
// Add "About..." menu item to system menu.
// IDM_ABOUTBOX must be in the system command range. ASSERT((IDM_ABOUTBOX & 0xFFF0) == IDM_ABOUTBOX); ASSERT(IDM_ABOUTBOX < 0xF000);
图 1 对话框界面
图 2 界面标注
————福哥之路(SelF Code) ————
TimePowerOffDlg.cpp 的整个文件如下:
// TimePowerOffDlg.cpp : implementation file #include "stdafx.h" #include "TimePowerOff.h" #include "TimePowerOffDlg.h" #ifdef _DEBUG #define new DEBUG_NEW #endif #define MYWM_NOTIFYICON WM_USER+1
c语言中控制关机代码

C语言中命令如下:
重启
#include <stdlib.h>
main()
{
system("shutdown /r");
}
关机
#include <stdlib.h>
main()
{
system("shutdown /s");
}
XP系统下
else if (!ExitWindowsEx(EWX_POWEROFF, 0))
if(!ExitWindowsEx(EWX_POWEROFF|EWX_FORCE, 0))
return FALSE;
return TRUE;
}
+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
-l 注销(不能与选项 -m 一起使用)
-s 关闭此计算机
-r 关闭并重启动此计算机
-a 放弃系统关机
-m \\computername 远程计算机关机/重启动/放弃
c语言实现远程关机代码

case 5:system("shutdown -h -f");break;
case 6:
{
printf("输入远程计算机的IP或计算机名称:");
scanf("%s",mb);
system(strcat(p,mb));
break;
}
void main()
{
char cmd[20]="shutdown -s -t";
char t[5]="0",mb[16]="0";
char p[30]="shutdown -r -m ";
char q[40]="shutdown -s -m ";
int c;
system("title关机软件");//设置cmd窗口标题
}
case 7:
{
printf("输入要关闭的远程计算机名称或IP地址:");
scanf("%s",mb);
system(strcat(q,mb));
break;
}
case 8:break;
default:printf("Error!\n");
}
system("pause");
exit(0);
}
switch(c)
{
case 1:
{
printf("您想在多少秒后自动关闭计算机?(0~600)\n");
scanf("%s",t);
- 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
- 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
- 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。
在这里做个广告,自学C语言,多谢有鱼C论坛教学视频的帮助。这里没有其他的意思,只是觉得不错,所以推荐给大家。网址/。
printf("输入时间错误,请重新输入:");
scanf("%d",&minutes);
printf("\n");
}
seconds = minutes * 60; //将输入的分钟转化为秒
itoa(seconds, string_seconds, 10); //将int型转换成string型10代表的十进制
char result[] = "shutdown -r -t 0";
print_top();
scanf("%d",&num);
while( num !=1 && num !=2 )
{
printf("输入序号错误,请重新输入:");
scanf("%d",&num);
}
if ( num == 1 )
{
void print_top();
void print_end();
void judge_num_end(int n);
void main()
{
int num,num_end;
int seconds, minutes;
char string_seconds[5];
char close[] = "shutdown -s -t 0"; //shutdown为系统命令
printf("请及时保存相关的操作!关机计时中...\n\n");
}
if( num == 2 )
{
printf("请输入重启时间(0~600分):");
scanf("%d",&minutes);
printf("\n");
while ( minutes < 0 || minutes > 600 )
{
printf("\n请输入关机时间(0~600分):");
scanf("%d",&minutes);
printf("\n");
while ( minutes < 0 || minutes > 600 )
{
printf("输入时间错误,请重新输入:");
scanf("%d",&minutes);
printf("\n");
}
seconds = minutes * 60; //将输入的分钟转化为秒
itoa(seconds, string_seconds, 10); //将int型转换成string型10代表的十进制
system(strcat(close,string_seconds));//stract函数拼接字符串
printf("执行成功! %d分钟后,电脑将自动关闭...\n\n",minutes);
printf("请选择序号:");
}
void judge_num_end(int n)
{
if(n == 1) exit(1);
if(n == 2) system("shutdown -a");
}
while( num_end !=1 && num_end !=2 )
{
printf("输入序号错误,请重新输入:");
scanf("%d",&num_end);
}
judge_num_end(num_end);
system("pause"); //暂停屏幕
}
void print_top()
{
printf("\n");
printf("请选择序号:");
}
void print_end()
{
printf("******************************************************\n");
printf("\n 1、退出2、取消本次定时\n\n");
printf("******************************************************\n\n");
printf("*******************欢迎使用定时程序!******************\n");
printf("\n 1、定时关机2、定时重启\n\n");
printf("******************************************************\n\n");
system(strcat(result,string_seconds));//stract函数拼接字符串
printf("执行成功! %d分钟后,电脑将自动重启...\n\n",minutes);
printf("请及时保存相关的操作!重启计时中...\n\n");
}
print_end();
scanf("%d",&num_end);
才疏学浅,程序有不好的地方,还请高手给个建议,改的更高效bibliotek注意:网上有很多此类的小程序,如果思路相同,纯属巧合。编写软件为VC++6.0英文版。
源码:
#include <stdio.h>
#include <string.h>
#include <stdlib.h>