C#实现的调用DOS命令操作类实例
本文实例讲述了C#实现的调用DOS命令操作类。分享给大家供大家参考。具体如下:
/*********************************** *AllRightsReserved,Copyright(C)2012,EricHu. *作者:EricHu *创建时间:2012-5-415:29:35 ***********************************/ usingSystem; usingSystem.Diagnostics; usingSystem.Runtime.InteropServices; namespacePlatForm.Utilities { ///<summary> /// ///DosHelper ///Dos常用操作类 /// ///</summary> publicclassDosHelper { //引入API函数 [DllImportAttribute("user32.dll")] privatestaticexternintFindWindow(stringClassName,stringWindowName); [DllImport("user32.dll")] privatestaticexternintShowWindow(inthandle,intcmdShow); [DllImport("winmm.dll",EntryPoint="mciSendString",CharSet=CharSet.Auto)] privatestaticexternintmciSendString(stringlpstrCommand,stringlpstrReturnstring,intuReturnLength,inthwndCallback); privateconstintSW_HIDE=0;//API参数表示隐藏窗口 privateconstintSW_SHOW=5;//API参数表示用当前的大小和位置显示窗口 publicvoid弹出光驱() { mciSendString("setCDAudiodooropen",null,127,0); } publicvoid关闭光驱() { mciSendString("setCDAudiodoorclosed",null,127,0); } publicvoid打开C盘() { Process.Start("c:\"); } publicvoid打开D盘() { Process.Start("d:\"); } publicvoid打开E盘() { Process.Start("e:\"); } publicvoid打开F盘() { Process.Start("f:\"); } publicvoid打开指定盘(stringhardpath) { Process.Start(hardpath); } publicvoid打开Word() { Process.Start(@"C:ProgramFilesMicrosoftOfficeOFFICE11winword.exe"); } publicvoid打开Excel() { Process.Start(@"C:ProgramFilesMicrosoftOfficeOFFICE11excel.exe"); } publicvoid打开Access() { Process.Start(@"C:ProgramFilesMicrosoftOfficeOFFICE11msaccess.exe"); } publicvoid打开PowerPoint() { Process.Start(@"C:ProgramFilesMicrosoftOfficeOFFICE11powerpnt.exe"); } publicvoid打开OutLook() { Process.Start(@"C:ProgramFilesMicrosoftOfficeOFFICE11outlook.exe"); } publicvoid打开记事本() { Process.Start("notepad.exe"); } publicvoid打开计算器() { Process.Start("calc.exe"); } publicvoid打开DOS命令窗口() { Process.Start("cmd.exe"); } publicvoid打开注册表() { Process.Start("regedit.exe"); } publicvoid打开画图板() { Process.Start("mspaint.exe"); } publicvoid打开写字板() { Process.Start("write.exe"); } publicvoid打开播放器() { Process.Start("mplayer2.exe"); } publicvoid打开资源管理器() { Process.Start("explorer.exe"); } publicvoid打开任务管理器() { Process.Start("taskmgr.exe"); } publicvoid打开事件查看器() { Process.Start("eventvwr.exe"); } publicvoid打开系统信息() { Process.Start("winmsd.exe"); } publicvoid打开备份还原() { Process.Start("ntbackup.exe"); } publicvoid打开Windows版本() { Process.Start("winver.exe"); } publicvoid打开控制面板() { Process.Start("rundll32.exe","shell32.dll,Control_RunDLL"); } publicvoid打开控制面板辅助选项键盘() { Process.Start("rundll32.exe","shell32.dll,Control_RunDLLaccess.cpl,,1"); } publicvoid打开控制面板辅助选项声音() { Process.Start("rundll32.exe","shell32.dll,Control_RunDLLaccess.cpl,,2"); } publicvoid打开控制面板辅助选项显示() { Process.Start("rundll32.exe","shell32.dll,Control_RunDLLaccess.cpl,,3"); } publicvoid打开控制面板辅助选项鼠标() { Process.Start("rundll32.exe","shell32.dll,Control_RunDLLaccess.cpl,,4"); } publicvoid打开控制面板辅助选项常规() { Process.Start("rundll32.exe","shell32.dll,Control_RunDLLaccess.cpl,,5"); } publicvoid打开控制面板添加新硬件向导() { Process.Start("rundll32.exe","shell32.dll,Control_RunDLLsysdm.cpl@1"); } publicvoid打开控制面板添加新打印机向导() { Process.Start("rundll32.exe","shell32.dll,SHHelpShortcuts_RunDLLAddPrinter"); } publicvoid打开控制面板添加删除程序安装卸载面板() { Process.Start("rundll32.exe","shell32.dll,shell32.dll,Control_RunDLLappwiz.cpl,,1"); } publicvoid打开控制面板添加删除程序安装Windows面板() { Process.Start("rundll32.exe","shell32.dll,shell32.dll,Control_RunDLLappwiz.cpl,,2"); } publicvoid打开控制面板添加删除程序启动盘面板() { Process.Start("rundll32.exe","shell32.dll,shell32.dll,Control_RunDLLappwiz.cpl,,3"); } publicvoid打开建立快捷方式对话框() { Process.Start("rundll32.exe","appwiz.cpl,NewLinkHere%1"); } publicvoid打开日期时间选项() { Process.Start("rundll32.exe","shell32.dll,Control_RunDLLtimedate.cpl,,0"); } publicvoid打开时区选项() { Process.Start("rundll32.exe","shell32.dll,Control_RunDLLtimedate.cpl,,1"); } publicvoid建立公文包() { Process.Start("rundll32.exe","syncui.dll,Briefcase_Create"); } publicvoid打开复制软碟窗口() { Process.Start("rundll32.exe","diskcopy.dll,DiskCopyRunDll"); } publicvoid打开新建拨号连接() { Process.Start("rundll32.exe","rnaui.dll,RnaWizard"); } publicvoid打开显示属性背景() { Process.Start("rundll32.exe","shell32.dll,Control_RunDLLdesk.cpl,,0"); } publicvoid打开显示属性屏幕保护() { Process.Start("rundll32.exe","shell32.dll,Control_RunDLLdesk.cpl,,1"); } publicvoid打开显示属性外观() { Process.Start("rundll32.exe","shell32.dll,Control_RunDLLdesk.cpl,,2"); } publicvoid打开显示属性属性() { Process.Start("rundll32.exe","shell32.dll,Control_RunDLLdesk.cpl,,3"); } publicvoid打开格式化对话框() { Process.Start("rundll32.exe","shell32.dll,SHFormatDrive"); } publicvoid打开控制面板游戏控制器一般() { Process.Start("rundll32.exe","shell32.dll,Control_RunDLLjoy.cpl,,0"); } publicvoid打开控制面板游戏控制器进阶() { Process.Start("rundll32.exe","shell32.dll,Control_RunDLLjoy.cpl,,1"); } publicvoid打开控制面板键盘属性速度() { Process.Start("rundll32.exe","shell32.dll,Control_RunDLLmain.cpl@1"); } publicvoid打开控制面板键盘属性语言() { Process.Start("rundll32.exe","shell32.dll,Control_RunDLLmain.cpl@1,,1"); } publicvoid打开Windows打印机档案夹() { Process.Start("rundll32.exe","shell32.dll,Control_RunDLLmain.cpl@2"); } publicvoid打开Windows字体档案夹() { Process.Start("rundll32.exe","shell32.dll,Control_RunDLLmain.cpl@3"); } publicvoid打开控制面板输入法属性() { Process.Start("rundll32.exe","shell32.dll,Control_RunDLLmain.cpl@4"); } publicvoid打开添加新调制解调器向导() { Process.Start("rundll32.exe","shell32.dll,Control_RunDLLmodem.cpl,,add"); } publicvoid打开控制面板多媒体属性音频() { Process.Start("rundll32.exe","shell32.dll,Control_RunDLLmmsys.cpl,,0"); } publicvoid打开控制面板多媒体属性视频() { Process.Start("rundll32.exe","shell32.dll,Control_RunDLLmmsys.cpl,,1"); } publicvoid打开控制面板多媒体属性MIDI() { Process.Start("rundll32.exe","shell32.dll,Control_RunDLLmmsys.cpl,,2"); } publicvoid打开控制面板多媒体属性CD音乐() { Process.Start("rundll32.exe","shell32.dll,Control_RunDLLmmsys.cpl,,3"); } publicvoid打开控制面板多媒体属性设备() { Process.Start("rundll32.exe","shell32.dll,Control_RunDLLmmsys.cpl,,4"); } publicvoid打开控制面板声音() { Process.Start("rundll32.exe","shell32.dll,Control_RunDLLmmsys.cpl@1"); } publicvoid打开控制面板网络() { Process.Start("rundll32.exe","shell32.dll,Control_RunDLLnetcpl.cpl"); } publicvoid打开控制面板密码() { Process.Start("rundll32.exe","shell32.dll,Control_RunDLLpassword.cpl"); } publicvoid打开控制面板电源管理() { Process.Start("rundll32.exe","shell32.dll,Control_RunDLLpowercfg.cpl"); } publicvoid打开控制面板区域设置属性区域设置() { Process.Start("rundll32.exe","shell32.dll,Control_RunDLLintl.cpl,,0"); } publicvoid打开控制面板区域设置属性数字选项() { Process.Start("rundll32.exe","shell32.dll,Control_RunDLLintl.cpl,,1"); } publicvoid打开控制面板区域设置属性货币选项() { Process.Start("rundll32.exe","shell32.dll,Control_RunDLLintl.cpl,,2"); } publicvoid打开控制面板区域设置属性时间选项() { Process.Start("rundll32.exe","shell32.dll,Control_RunDLLintl.cpl,,3"); } publicvoid打开控制面板区域设置属性日期选项() { Process.Start("rundll32.exe","shell32.dll,Control_RunDLLintl.cpl,,4"); } publicvoid打开ODBC数据源管理器() { Process.Start("rundll32.exe","shell32.dll,Control_RunDLLodbccp32.cpl"); } publicvoid打开控制面板系统属性常规() { Process.Start("rundll32.exe","shell32.dll,Control_RunDLLsysdm.cpl,,0"); } publicvoid打开控制面板系统属性设备管理器() { Process.Start("rundll32.exe","shell32.dll,Control_RunDLLsysdm.cpl,,1"); } publicvoid打开控制面板系统属性硬件配置() { Process.Start("rundll32.exe","shell32.dll,Control_RunDLLsysdm.cpl,,2"); } publicvoid打开控制面板系统属性性能() { Process.Start("rundll32.exe","shell32.dll,Control_RunDLLsysdm.cpl,,3"); } /*shutdown-s-t3600-f 一小时后强行关机用强行主要怕有些程序卡住关不了机 -s关机 -r重启 -f强行 -t时间 -a取消关机 -l注销 -i显示用户界面具体是什么试试就知道了*/ publicvoid关闭并重启计算机() { Process.Start("shutdown.exe","-r"); } publicvoid关闭计算机() { Process.Start("shutdown.exe","-s-f"); } //重载关闭计算机函数,可以设定倒计时 publicvoid关闭计算机(stringtime) { strings="-s-t"+time; Process.Start("shutdown.exe",s); } publicvoid注销计算机() { Process.Start("shutdown.exe","-l"); } publicvoid撤销关闭计算机() { Process.Start("shutdown.exe","-a"); } publicvoid打开桌面主旨面板() { Process.Start("rundll32.exe","shell32.dll,Control_RunDLLthemes.cpl"); } publicvoid打开网址(stringaddress) { Process.Start(address); } publicvoid运行程序(stringname) { Process.Start(name); } publicvoid显示任务栏() { ShowWindow(FindWindow("Shell_TrayWnd",null),SW_SHOW); } publicvoid隐藏任务栏() { ShowWindow(FindWindow("Shell_TrayWnd",null),SW_HIDE); } publicvoid发送邮件(stringaddress) { strings="mailto:"+address; Process.Start(s); } publicvoid发送邮件() { Process.Start("mailto:80368704@qq.com"); } publicstring获取系统文件夹() { strings=Environment.GetFolderPath(Environment.SpecialFolder.System); returns; } publicvoid打开系统文件夹() { strings=Environment.GetFolderPath(Environment.SpecialFolder.System); Process.Start(s); } publicstring获取ProgramFiles目录() { strings=Environment.GetFolderPath(Environment.SpecialFolder.ProgramFiles); returns; } publicvoid打开ProgramFiles目录() { strings=Environment.GetFolderPath(Environment.SpecialFolder.ProgramFiles); Process.Start(s); } publicstring获取逻辑桌面() { strings=Environment.GetFolderPath(Environment.SpecialFolder.Desktop); returns; } publicvoid打开逻辑桌面() { strings=Environment.GetFolderPath(Environment.SpecialFolder.Desktop); Process.Start(s); } publicstring获取启动程序组() { strings=Environment.GetFolderPath(Environment.SpecialFolder.Startup); returns; } publicvoid打开启动程序组() { strings=Environment.GetFolderPath(Environment.SpecialFolder.Startup); Process.Start(s); } publicstring获取Cookies文件夹() { strings=Environment.GetFolderPath(Environment.SpecialFolder.Cookies); returns; } publicvoid打开Cookies文件夹() { strings=Environment.GetFolderPath(Environment.SpecialFolder.Cookies); Process.Start(s); } publicstring获取Internet历史文件夹() { strings=Environment.GetFolderPath(Environment.SpecialFolder.History); returns; } publicvoid打开Internet历史文件夹() { strings=Environment.GetFolderPath(Environment.SpecialFolder.History); Process.Start(s); } publicstring获取我的电脑文件夹() { strings=Environment.GetFolderPath(Environment.SpecialFolder.MyComputer); returns; } publicvoid打开我的电脑文件夹() { strings=Environment.GetFolderPath(Environment.SpecialFolder.MyComputer); Process.Start(s); } publicstring获取MyMusic文件夹() { strings=Environment.GetFolderPath(Environment.SpecialFolder.MyMusic); returns; } publicvoid打开MyMusic文件夹() { strings=Environment.GetFolderPath(Environment.SpecialFolder.MyMusic); Process.Start(s); } publicstring获取MyPictures文件夹() { strings=Environment.GetFolderPath(Environment.SpecialFolder.MyPictures); returns; } publicvoid打开MyPictures文件夹() { strings=Environment.GetFolderPath(Environment.SpecialFolder.MyPictures); Process.Start(s); } publicstring获取StartMenu文件夹() { strings=Environment.GetFolderPath(Environment.SpecialFolder.StartMenu); returns; } publicvoid打开StartMenu文件夹() { strings=Environment.GetFolderPath(Environment.SpecialFolder.StartMenu); Process.Start(s); } } }
希望本文所述对大家的C#程序设计有所帮助。