- //引入API函数
- [DllImportAttribute("user32.dll")]
- private static extern int FindWindow(string ClassName, string WindowName);
- [DllImport("user32.dll")]
- private static extern int ShowWindow(int handle, int cmdShow);
- [DllImport("winmm.dll", EntryPoint = "mciSendString", CharSet = CharSet.Auto)]
- private static extern int mciSendString(string lpstrCommand, string lpstrReturnstring, int uReturnLength, int hwndCallback);
- private const int SW_HIDE = 0;//API参数表示隐藏窗口
- private const int SW_SHOW = 5;//API参数表示用当前的大小和位置显示窗口
- public void 打开控制面板游戏控制器进阶()
- {
- Process.Start("rundll32.exe", " shell32.dll,Control_RunDLL joy.cpl,,1");
- }
- public void 打开控制面板键盘属性速度()
- {
- Process.Start("rundll32.exe", " shell32.dll,Control_RunDLL main.cpl @1");
- }
- public void 打开控制面板键盘属性语言()
- {
- Process.Start("rundll32.exe", " shell32.dll,Control_RunDLL main.cpl @1,,1");
- }
- public void 打开Windows打印机档案夹()
- {
- Process.Start("rundll32.exe", " shell32.dll,Control_RunDLL main.cpl @2");
- }
- public void 打开Windows字体档案夹()
- {
- Process.Start("rundll32.exe", " shell32.dll,Control_RunDLL main.cpl @3");
- }
- public void 打开控制面板输入法属性()
- {
- Process.Start("rundll32.exe", " shell32.dll,Control_RunDLL main.cpl @4");
- }
- public void 打开添加新调制解调器向导()
- {
- Process.Start("rundll32.exe", " shell32.dll,Control_RunDLL modem.cpl,,add");
- }
- public void 打开控制面板多媒体属性音频()
- {
- Process.Start("rundll32.exe", " shell32.dll,Control_RunDLL mmsys.cpl,,0");
- }
- public void 打开控制面板多媒体属性视频()
- {
- Process.Start("rundll32.exe", " shell32.dll,Control_RunDLL mmsys.cpl,,1");
- }
- public void 打开控制面板多媒体属性MIDI()
- {
- Process.Start("rundll32.exe", " shell32.dll,Control_RunDLL mmsys.cpl,,2");
- }
- public void 打开控制面板多媒体属性CD音乐()
- {
- Process.Start("rundll32.exe", " shell32.dll,Control_RunDLL mmsys.cpl,,3");
- }
- public void 打开控制面板多媒体属性设备()
- {
- Process.Start("rundll32.exe", " shell32.dll,Control_RunDLL mmsys.cpl,,4");
- }
- public void 打开控制面板声音()
- {
- Process.Start("rundll32.exe", " shell32.dll,Control_RunDLL mmsys.cpl @1");
- }
- public void 打开控制面板网络()
- {
- Process.Start("rundll32.exe", " shell32.dll,Control_RunDLL netcpl.cpl");
- }
- public void 打开控制面板密码()
- {
- Process.Start("rundll32.exe", " shell32.dll,Control_RunDLL password.cpl");
- }
- public void 打开控制面板电源管理()
- {
- Process.Start("rundll32.exe", " shell32.dll,Control_RunDLL powercfg.cpl");
- }
- public void 打开控制面板区域设置属性区域设置()
- {
- Process.Start("rundll32.exe", " shell32.dll,Control_RunDLL intl.cpl,,0");
- }
- public void 打开控制面板区域设置属性数字选项()
- {
- Process.Start("rundll32.exe", " shell32.dll,Control_RunDLL intl.cpl,,1");
- }
- public void 打开控制面板区域设置属性货币选项()
- {
- Process.Start("rundll32.exe", " shell32.dll,Control_RunDLL intl.cpl,,2");
- }
- public void 打开控制面板区域设置属性时间选项()
- {
- Process.Start("rundll32.exe", " shell32.dll,Control_RunDLL intl.cpl,,3");
- }
- public void 打开控制面板区域设置属性日期选项()
- {
- Process.Start("rundll32.exe", " shell32.dll,Control_RunDLL intl.cpl,,4");
- }
- /*shutdown -s -t 3600 -f
- 一小时后强行关机 用强行主要怕有些程序卡住 关不了机
- -s 关机
- -r重启
- -f强行
- -t 时间
- -a 取消关机
- -l 注销
- -i 显示用户界面 具体是什么试试就知道了*/
- public void 关闭并重启计算机()
- {
- Process.Start("shutdown.exe", "-r");
- }
- public void 关闭计算机()
- {
- Process.Start("shutdown.exe", "-s -f");
- }
- //重载关闭计算机函数,可以设定倒计时
- public void 关闭计算机(string time)
- {
- string s = "-s -t " + time;
- Process.Start("shutdown.exe", s);
- }
- public void 注销计算机()
- {
- Process.Start("shutdown.exe", "-l");
- }
- public void 撤销关闭计算机()
- {
- Process.Start("shutdown.exe", "-a");
- }
- public void 显示任务栏()
- {
- ShowWindow(FindWindow("Shell_TrayWnd", null), SW_SHOW);
- }
- public void 隐藏任务栏()
- {
- ShowWindow(FindWindow("Shell_TrayWnd", null), SW_HIDE);
- }
- public void 打开系统文件夹()
- {
- Process.Start(Environment.GetFolderPath(Environment.SpecialFolder.System));
- }
- public void 打开ProgramFiles目录()
- {
- Process.Start(Environment.GetFolderPath(Environment.SpecialFolder.ProgramFiles));
- }
- public void 打开逻辑桌面()
- {
- Process.Start(Environment.GetFolderPath(Environment.SpecialFolder.Desktop));
- }
- public void 打开启动程序组()
- {
- Process.Start(Environment.GetFolderPath(Environment.SpecialFolder.Startup));
- }
- public void 打开Cookies文件夹()
- {
- Process.Start(Environment.GetFolderPath(Environment.SpecialFolder.Cookies));
- }
- public void 打开Internet历史文件夹()
- {
- Process.Start(Environment.GetFolderPath(Environment.SpecialFolder.History));
- }
- public void 打开我的电脑文件夹()
- {
- Process.Start(Environment.GetFolderPath(Environment.SpecialFolder.MyComputer));
- }
- //该片段来自于http://www.codesnippet.cn/detail/270620134346.html
来源: http://www.codesnippet.cn/detail/270620134346.html