C#实现的调用DOS命令操作类实例
程序员文章站
2022-10-25 18:59:03
本文实例讲述了c#实现的调用dos命令操作类。分享给大家供大家参考。具体如下:
/***********************************
*...
本文实例讲述了c#实现的调用dos命令操作类。分享给大家供大家参考。具体如下:
/*********************************** * all rights reserved , copyright (c) 2012 , erichu. * 作 者: erichu * 创建时间: 2012-5-4 15:29:35 ***********************************/ using system; using system.diagnostics; using system.runtime.interopservices; namespace platform.utilities { /// <summary> /// /// doshelper /// dos常用操作类 /// /// </summary> public class doshelper { //引入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 弹出光驱() { mcisendstring("set cdaudio door open", null, 127, 0); } public void 关闭光驱() { mcisendstring("set cdaudio door closed", null, 127, 0); } public void 打开c盘() { process.start("c:\"); } public void 打开d盘() { process.start("d:\"); } public void 打开e盘() { process.start("e:\"); } public void 打开f盘() { process.start("f:\"); } public void 打开指定盘(string hardpath) { process.start(hardpath); } public void 打开word() { process.start(@"c:program filesmicrosoft officeoffice11winword.exe"); } public void 打开excel() { process.start(@"c:program filesmicrosoft officeoffice11excel.exe"); } public void 打开access() { process.start(@"c:program filesmicrosoft officeoffice11msaccess.exe"); } public void 打开powerpoint() { process.start(@"c:program filesmicrosoft officeoffice11powerpnt.exe"); } public void 打开outlook() { process.start(@"c:program filesmicrosoft officeoffice11outlook.exe"); } public void 打开记事本() { process.start("notepad.exe"); } public void 打开计算器() { process.start("calc.exe"); } public void 打开dos命令窗口() { process.start("cmd.exe"); } public void 打开注册表() { process.start("regedit.exe"); } public void 打开画图板() { process.start("mspaint.exe"); } public void 打开写字板() { process.start("write.exe"); } public void 打开播放器() { process.start("mplayer2.exe"); } public void 打开资源管理器() { process.start("explorer.exe"); } public void 打开任务管理器() { process.start("taskmgr.exe"); } public void 打开事件查看器() { process.start("eventvwr.exe"); } public void 打开系统信息() { process.start("winmsd.exe"); } public void 打开备份还原() { process.start("ntbackup.exe"); } public void 打开windows版本() { process.start("winver.exe"); } public void 打开控制面板() { process.start("rundll32.exe", "shell32.dll,control_rundll"); } public void 打开控制面板辅助选项键盘() { process.start("rundll32.exe", "shell32.dll,control_rundll access.cpl,,1"); } public void 打开控制面板辅助选项声音() { process.start("rundll32.exe", "shell32.dll,control_rundll access.cpl,,2"); } public void 打开控制面板辅助选项显示() { process.start("rundll32.exe", "shell32.dll,control_rundll access.cpl,,3"); } public void 打开控制面板辅助选项鼠标() { process.start("rundll32.exe", "shell32.dll,control_rundll access.cpl,,4"); } public void 打开控制面板辅助选项常规() { process.start("rundll32.exe", "shell32.dll,control_rundll access.cpl,,5"); } public void 打开控制面板添加新硬件向导() { process.start("rundll32.exe", "shell32.dll,control_rundll sysdm.cpl @1"); } public void 打开控制面板添加新打印机向导() { process.start("rundll32.exe", "shell32.dll,shhelpshortcuts_rundll addprinter"); } public void 打开控制面板添加删除程序安装卸载面板() { process.start("rundll32.exe", "shell32.dll,shell32.dll,control_rundll appwiz.cpl,,1"); } public void 打开控制面板添加删除程序安装windows面板() { process.start("rundll32.exe", "shell32.dll,shell32.dll,control_rundll appwiz.cpl,,2"); } public void 打开控制面板添加删除程序启动盘面板() { process.start("rundll32.exe", "shell32.dll,shell32.dll,control_rundll appwiz.cpl,,3"); } public void 打开建立快捷方式对话框() { process.start("rundll32.exe", " appwiz.cpl,newlinkhere %1"); } public void 打开日期时间选项() { process.start("rundll32.exe", " shell32.dll,control_rundll timedate.cpl,,0"); } public void 打开时区选项() { process.start("rundll32.exe", " shell32.dll,control_rundll timedate.cpl,,1"); } public void 建立公文包() { process.start("rundll32.exe", " syncui.dll,briefcase_create"); } public void 打开复制软碟窗口() { process.start("rundll32.exe", " diskcopy.dll,diskcopyrundll"); } public void 打开新建拨号连接() { process.start("rundll32.exe", " rnaui.dll,rnawizard"); } public void 打开显示属性背景() { process.start("rundll32.exe", " shell32.dll,control_rundll desk.cpl,,0"); } public void 打开显示属性屏幕保护() { process.start("rundll32.exe", " shell32.dll,control_rundll desk.cpl,,1"); } public void 打开显示属性外观() { process.start("rundll32.exe", " shell32.dll,control_rundll desk.cpl,,2"); } public void 打开显示属性属性() { process.start("rundll32.exe", " shell32.dll,control_rundll desk.cpl,,3"); } public void 打开格式化对话框() { process.start("rundll32.exe", " shell32.dll,shformatdrive"); } public void 打开控制面板游戏控制器一般() { process.start("rundll32.exe", " shell32.dll,control_rundll joy.cpl,,0"); } 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"); } public void 打开odbc数据源管理器() { process.start("rundll32.exe", " shell32.dll,control_rundll odbccp32.cpl"); } public void 打开控制面板系统属性常规() { process.start("rundll32.exe", " shell32.dll,control_rundll sysdm.cpl,,0"); } public void 打开控制面板系统属性设备管理器() { process.start("rundll32.exe", " shell32.dll,control_rundll sysdm.cpl,,1"); } public void 打开控制面板系统属性硬件配置() { process.start("rundll32.exe", " shell32.dll,control_rundll sysdm.cpl,,2"); } public void 打开控制面板系统属性性能() { process.start("rundll32.exe", " shell32.dll,control_rundll sysdm.cpl,,3"); } /*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 打开桌面主旨面板() { process.start("rundll32.exe", " shell32.dll,control_rundll themes.cpl"); } public void 打开网址(string address) { process.start(address); } public void 运行程序(string name) { process.start(name); } public void 显示任务栏() { showwindow(findwindow("shell_traywnd", null), sw_show); } public void 隐藏任务栏() { showwindow(findwindow("shell_traywnd", null), sw_hide); } public void 发送邮件(string address) { string s = "mailto:" + address; process.start(s); } public void 发送邮件() { process.start("mailto:80368704@qq.com"); } public string 获取系统文件夹() { string s = environment.getfolderpath(environment.specialfolder.system); return s; } public void 打开系统文件夹() { string s = environment.getfolderpath(environment.specialfolder.system); process.start(s); } public string 获取programfiles目录() { string s = environment.getfolderpath(environment.specialfolder.programfiles); return s; } public void 打开programfiles目录() { string s = environment.getfolderpath(environment.specialfolder.programfiles); process.start(s); } public string 获取逻辑桌面() { string s = environment.getfolderpath(environment.specialfolder.desktop); return s; } public void 打开逻辑桌面() { string s = environment.getfolderpath(environment.specialfolder.desktop); process.start(s); } public string 获取启动程序组() { string s = environment.getfolderpath(environment.specialfolder.startup); return s; } public void 打开启动程序组() { string s = environment.getfolderpath(environment.specialfolder.startup); process.start(s); } public string 获取cookies文件夹() { string s = environment.getfolderpath(environment.specialfolder.cookies); return s; } public void 打开cookies文件夹() { string s = environment.getfolderpath(environment.specialfolder.cookies); process.start(s); } public string 获取internet历史文件夹() { string s = environment.getfolderpath(environment.specialfolder.history); return s; } public void 打开internet历史文件夹() { string s = environment.getfolderpath(environment.specialfolder.history); process.start(s); } public string 获取我的电脑文件夹() { string s = environment.getfolderpath(environment.specialfolder.mycomputer); return s; } public void 打开我的电脑文件夹() { string s = environment.getfolderpath(environment.specialfolder.mycomputer); process.start(s); } public string 获取mymusic文件夹() { string s = environment.getfolderpath(environment.specialfolder.mymusic); return s; } public void 打开mymusic文件夹() { string s = environment.getfolderpath(environment.specialfolder.mymusic); process.start(s); } public string 获取mypictures文件夹() { string s = environment.getfolderpath(environment.specialfolder.mypictures); return s; } public void 打开mypictures文件夹() { string s = environment.getfolderpath(environment.specialfolder.mypictures); process.start(s); } public string 获取startmenu文件夹() { string s = environment.getfolderpath(environment.specialfolder.startmenu); return s; } public void 打开startmenu文件夹() { string s = environment.getfolderpath(environment.specialfolder.startmenu); process.start(s); } } }
希望本文所述对大家的c#程序设计有所帮助。
上一篇: C#图像处理之木刻效果实现方法
下一篇: C#生成指定范围内的不重复随机数