[C#] 一个用来调用DOS命令的C#操作类 →→→→→进入此内容的聊天室

来自 , 2020-04-10, 写在 C#, 查看 110 次.
URL http://www.code666.cn/view/e661551c
  1. /******************************************************************************
  2.  *  All Rights Reserved , Copyright (C) 2012 , EricHu.
  3.  *  作    者: EricHu
  4.  *  创建时间: 2012-5-4 15:29:35
  5.  ******************************************************************************/
  6.  
  7. using System;
  8. using System.Diagnostics;
  9. using System.Runtime.InteropServices;
  10.  
  11. namespace PlatForm.Utilities
  12. {
  13.     /// <summary>
  14.     ///
  15.     /// DosHelper
  16.     /// Dos常用操作类
  17.     ///
  18.     /// </summary>
  19.     public class DosHelper
  20.     {
  21.         //引入API函数
  22.         [DllImportAttribute("user32.dll")]
  23.         private static extern int FindWindow(string ClassName, string WindowName);
  24.         [DllImport("user32.dll")]
  25.         private static extern int ShowWindow(int handle, int cmdShow);
  26.         [DllImport("winmm.dll", EntryPoint = "mciSendString", CharSet = CharSet.Auto)]
  27.         private static extern int mciSendString(string lpstrCommand, string lpstrReturnstring, int uReturnLength, int hwndCallback);
  28.  
  29.         private const int SW_HIDE = 0;//API参数表示隐藏窗口
  30.         private const int SW_SHOW = 5;//API参数表示用当前的大小和位置显示窗口
  31.  
  32.         public void 弹出光驱()
  33.         {
  34.             mciSendString("set CDAudio door open", null, 127, 0);
  35.         }
  36.  
  37.         public void 关闭光驱()
  38.         {
  39.             mciSendString("set CDAudio door closed", null, 127, 0);
  40.         }
  41.  
  42.         public void 打开C盘()
  43.         {
  44.             Process.Start("c:\");
  45.        }
  46.  
  47.        public void 打开D盘()
  48.        {
  49.            Process.Start("d:\");
  50.        }
  51.  
  52.        public void 打开E盘()
  53.        {
  54.            Process.Start("e:\");
  55.        }
  56.  
  57.        public void 打开F盘()
  58.        {
  59.            Process.Start("f:\");
  60.        }
  61.  
  62.        public void 打开指定盘(string hardpath)
  63.        {
  64.            Process.Start(hardpath);
  65.        }
  66.  
  67.        public void 打开Word()
  68.        {
  69.            Process.Start(@"C:Program FilesMicrosoft OfficeOFFICE11winword.exe");
  70.        }
  71.  
  72.        public void 打开Excel()
  73.        {
  74.            Process.Start(@"C:Program FilesMicrosoft OfficeOFFICE11excel.exe");
  75.        }
  76.  
  77.        public void 打开Access()
  78.        {
  79.            Process.Start(@"C:Program FilesMicrosoft OfficeOFFICE11msaccess.exe");
  80.        }
  81.  
  82.        public void 打开PowerPoint()
  83.        {
  84.            Process.Start(@"C:Program FilesMicrosoft OfficeOFFICE11powerpnt.exe");
  85.        }
  86.  
  87.        public void 打开OutLook()
  88.        {
  89.            Process.Start(@"C:Program FilesMicrosoft OfficeOFFICE11outlook.exe");
  90.        }
  91.  
  92.        public void 打开记事本()
  93.        {
  94.            Process.Start("notepad.exe");
  95.        }
  96.  
  97.        public void 打开计算器()
  98.        {
  99.            Process.Start("calc.exe");
  100.        }
  101.  
  102.        public void 打开DOS命令窗口()
  103.        {
  104.            Process.Start("cmd.exe");
  105.        }
  106.  
  107.        public void 打开注册表()
  108.        {
  109.            Process.Start("regedit.exe");
  110.        }
  111.  
  112.        public void 打开画图板()
  113.        {
  114.            Process.Start("mspaint.exe");
  115.        }
  116.  
  117.        public void 打开写字板()
  118.        {
  119.            Process.Start("write.exe");
  120.        }
  121.  
  122.        public void 打开播放器()
  123.        {
  124.            Process.Start("mplayer2.exe");
  125.        }
  126.  
  127.        public void 打开资源管理器()
  128.        {
  129.            Process.Start("explorer.exe");
  130.        }
  131.  
  132.        public void 打开任务管理器()
  133.        {
  134.            Process.Start("taskmgr.exe");
  135.        }
  136.  
  137.        public void 打开事件查看器()
  138.        {
  139.            Process.Start("eventvwr.exe");
  140.        }
  141.  
  142.        public void 打开系统信息()
  143.        {
  144.            Process.Start("winmsd.exe");
  145.        }
  146.  
  147.        public void 打开备份还原()
  148.        {
  149.            Process.Start("ntbackup.exe");
  150.        }
  151.  
  152.        public void 打开Windows版本()
  153.        {
  154.            Process.Start("winver.exe");
  155.        }
  156.  
  157.        public void 打开控制面板()
  158.        {
  159.            Process.Start("rundll32.exe", "shell32.dll,Control_RunDLL");
  160.        }
  161.  
  162.        public void 打开控制面板辅助选项键盘()
  163.        {
  164.            Process.Start("rundll32.exe", "shell32.dll,Control_RunDLL access.cpl,,1");
  165.        }
  166.  
  167.        public void 打开控制面板辅助选项声音()
  168.        {
  169.            Process.Start("rundll32.exe", "shell32.dll,Control_RunDLL access.cpl,,2");
  170.        }
  171.  
  172.        public void 打开控制面板辅助选项显示()
  173.        {
  174.            Process.Start("rundll32.exe", "shell32.dll,Control_RunDLL access.cpl,,3");
  175.        }
  176.  
  177.        public void 打开控制面板辅助选项鼠标()
  178.        {
  179.            Process.Start("rundll32.exe", "shell32.dll,Control_RunDLL access.cpl,,4");
  180.        }
  181.  
  182.        public void 打开控制面板辅助选项常规()
  183.        {
  184.            Process.Start("rundll32.exe", "shell32.dll,Control_RunDLL access.cpl,,5");
  185.        }
  186.  
  187.        public void 打开控制面板添加新硬件向导()
  188.        {
  189.            Process.Start("rundll32.exe", "shell32.dll,Control_RunDLL sysdm.cpl @1");
  190.        }
  191.  
  192.        public void 打开控制面板添加新打印机向导()
  193.        {
  194.            Process.Start("rundll32.exe", "shell32.dll,SHHelpShortcuts_RunDLL AddPrinter");
  195.        }
  196.  
  197.        public void 打开控制面板添加删除程序安装卸载面板()
  198.        {
  199.            Process.Start("rundll32.exe", "shell32.dll,shell32.dll,Control_RunDLL appwiz.cpl,,1");
  200.        }
  201.  
  202.        public void 打开控制面板添加删除程序安装Windows面板()
  203.        {
  204.            Process.Start("rundll32.exe", "shell32.dll,shell32.dll,Control_RunDLL appwiz.cpl,,2");
  205.        }
  206.  
  207.        public void 打开控制面板添加删除程序启动盘面板()
  208.        {
  209.            Process.Start("rundll32.exe", "shell32.dll,shell32.dll,Control_RunDLL appwiz.cpl,,3");
  210.        }
  211.  
  212.        public void 打开建立快捷方式对话框()
  213.        {
  214.            Process.Start("rundll32.exe", " appwiz.cpl,NewLinkHere %1");
  215.        }
  216.  
  217.        public void 打开日期时间选项()
  218.        {
  219.            Process.Start("rundll32.exe", " shell32.dll,Control_RunDLL timedate.cpl,,0");
  220.        }
  221.  
  222.        public void 打开时区选项()
  223.        {
  224.            Process.Start("rundll32.exe", " shell32.dll,Control_RunDLL timedate.cpl,,1");
  225.        }
  226.  
  227.        public void 建立公文包()
  228.        {
  229.            Process.Start("rundll32.exe", " syncui.dll,Briefcase_Create");
  230.        }
  231.  
  232.        public void 打开复制软碟窗口()
  233.        {
  234.            Process.Start("rundll32.exe", " diskcopy.dll,DiskCopyRunDll");
  235.        }
  236.  
  237.        public void 打开新建拨号连接()
  238.        {
  239.            Process.Start("rundll32.exe", " rnaui.dll,RnaWizard");
  240.        }
  241.  
  242.        public void 打开显示属性背景()
  243.        {
  244.            Process.Start("rundll32.exe", " shell32.dll,Control_RunDLL desk.cpl,,0");
  245.        }
  246.  
  247.        public void 打开显示属性屏幕保护()
  248.        {
  249.            Process.Start("rundll32.exe", " shell32.dll,Control_RunDLL desk.cpl,,1");
  250.        }
  251.  
  252.        public void 打开显示属性外观()
  253.        {
  254.            Process.Start("rundll32.exe", " shell32.dll,Control_RunDLL desk.cpl,,2");
  255.        }
  256.  
  257.        public void 打开显示属性属性()
  258.        {
  259.            Process.Start("rundll32.exe", " shell32.dll,Control_RunDLL desk.cpl,,3");
  260.        }
  261.  
  262.        public void 打开格式化对话框()
  263.        {
  264.            Process.Start("rundll32.exe", " shell32.dll,SHFormatDrive");
  265.        }
  266.  
  267.        public void 打开控制面板游戏控制器一般()
  268.        {
  269.            Process.Start("rundll32.exe", " shell32.dll,Control_RunDLL joy.cpl,,0");
  270.        }
  271.  
  272.        public void 打开控制面板游戏控制器进阶()
  273.        {
  274.            Process.Start("rundll32.exe", " shell32.dll,Control_RunDLL joy.cpl,,1");
  275.        }
  276.  
  277.        public void 打开控制面板键盘属性速度()
  278.        {
  279.            Process.Start("rundll32.exe", " shell32.dll,Control_RunDLL main.cpl @1");
  280.        }
  281.  
  282.        public void 打开控制面板键盘属性语言()
  283.        {
  284.            Process.Start("rundll32.exe", " shell32.dll,Control_RunDLL main.cpl @1,,1");
  285.        }
  286.  
  287.        public void 打开Windows打印机档案夹()
  288.        {
  289.            Process.Start("rundll32.exe", " shell32.dll,Control_RunDLL main.cpl @2");
  290.        }
  291.  
  292.        public void 打开Windows字体档案夹()
  293.        {
  294.            Process.Start("rundll32.exe", " shell32.dll,Control_RunDLL main.cpl @3");
  295.        }
  296.  
  297.        public void 打开控制面板输入法属性()
  298.        {
  299.            Process.Start("rundll32.exe", " shell32.dll,Control_RunDLL main.cpl @4");
  300.        }
  301.  
  302.        public void 打开添加新调制解调器向导()
  303.        {
  304.            Process.Start("rundll32.exe", " shell32.dll,Control_RunDLL modem.cpl,,add");
  305.        }
  306.  
  307.        public void 打开控制面板多媒体属性音频()
  308.        {
  309.            Process.Start("rundll32.exe", " shell32.dll,Control_RunDLL mmsys.cpl,,0");
  310.        }
  311.  
  312.        public void 打开控制面板多媒体属性视频()
  313.        {
  314.            Process.Start("rundll32.exe", " shell32.dll,Control_RunDLL mmsys.cpl,,1");
  315.        }
  316.  
  317.        public void 打开控制面板多媒体属性MIDI()
  318.        {
  319.            Process.Start("rundll32.exe", " shell32.dll,Control_RunDLL mmsys.cpl,,2");
  320.        }
  321.  
  322.        public void 打开控制面板多媒体属性CD音乐()
  323.        {
  324.            Process.Start("rundll32.exe", " shell32.dll,Control_RunDLL mmsys.cpl,,3");
  325.        }
  326.  
  327.        public void 打开控制面板多媒体属性设备()
  328.        {
  329.            Process.Start("rundll32.exe", " shell32.dll,Control_RunDLL mmsys.cpl,,4");
  330.        }
  331.  
  332.        public void 打开控制面板声音()
  333.        {
  334.            Process.Start("rundll32.exe", " shell32.dll,Control_RunDLL mmsys.cpl @1");
  335.        }
  336.  
  337.        public void 打开控制面板网络()
  338.        {
  339.            Process.Start("rundll32.exe", " shell32.dll,Control_RunDLL netcpl.cpl");
  340.        }
  341.  
  342.        public void 打开控制面板密码()
  343.        {
  344.            Process.Start("rundll32.exe", " shell32.dll,Control_RunDLL password.cpl");
  345.        }
  346.  
  347.        public void 打开控制面板电源管理()
  348.        {
  349.            Process.Start("rundll32.exe", " shell32.dll,Control_RunDLL powercfg.cpl");
  350.        }
  351.  
  352.        public void 打开控制面板区域设置属性区域设置()
  353.        {
  354.            Process.Start("rundll32.exe", " shell32.dll,Control_RunDLL intl.cpl,,0");
  355.        }
  356.  
  357.        public void 打开控制面板区域设置属性数字选项()
  358.        {
  359.            Process.Start("rundll32.exe", " shell32.dll,Control_RunDLL intl.cpl,,1");
  360.        }
  361.  
  362.        public void 打开控制面板区域设置属性货币选项()
  363.        {
  364.            Process.Start("rundll32.exe", " shell32.dll,Control_RunDLL intl.cpl,,2");
  365.        }
  366.  
  367.        public void 打开控制面板区域设置属性时间选项()
  368.        {
  369.            Process.Start("rundll32.exe", " shell32.dll,Control_RunDLL intl.cpl,,3");
  370.        }
  371.  
  372.        public void 打开控制面板区域设置属性日期选项()
  373.        {
  374.            Process.Start("rundll32.exe", " shell32.dll,Control_RunDLL intl.cpl,,4");
  375.        }
  376.  
  377.        public void 打开ODBC数据源管理器()
  378.        {
  379.            Process.Start("rundll32.exe", " shell32.dll,Control_RunDLL odbccp32.cpl");
  380.        }
  381.  
  382.        public void 打开控制面板系统属性常规()
  383.        {
  384.            Process.Start("rundll32.exe", " shell32.dll,Control_RunDLL sysdm.cpl,,0");
  385.        }
  386.  
  387.        public void 打开控制面板系统属性设备管理器()
  388.        {
  389.            Process.Start("rundll32.exe", " shell32.dll,Control_RunDLL sysdm.cpl,,1");
  390.        }
  391.  
  392.        public void 打开控制面板系统属性硬件配置()
  393.        {
  394.            Process.Start("rundll32.exe", " shell32.dll,Control_RunDLL sysdm.cpl,,2");
  395.        }
  396.  
  397.        public void 打开控制面板系统属性性能()
  398.        {
  399.            Process.Start("rundll32.exe", " shell32.dll,Control_RunDLL sysdm.cpl,,3");
  400.        }
  401.  
  402.        /*shutdown -s -t 3600 -f
  403.        一小时后强行关机 用强行主要怕有些程序卡住 关不了机
  404.        -s 关机
  405.        -r重启
  406.        -f强行
  407.        -t 时间
  408.        -a 取消关机
  409.        -l 注销
  410.        -i 显示用户界面 具体是什么试试就知道了*/
  411.  
  412.        public void 关闭并重启计算机()
  413.        {
  414.            Process.Start("shutdown.exe", "-r");
  415.        }
  416.  
  417.        public void 关闭计算机()
  418.        {
  419.            Process.Start("shutdown.exe", "-s -f");
  420.        }
  421.        //重载关闭计算机函数,可以设定倒计时
  422.        public void 关闭计算机(string time)
  423.        {
  424.            string s = "-s -t " + time;
  425.            Process.Start("shutdown.exe", s);
  426.        }
  427.  
  428.        public void 注销计算机()
  429.        {
  430.            Process.Start("shutdown.exe", "-l");
  431.        }
  432.  
  433.        public void 撤销关闭计算机()
  434.        {
  435.            Process.Start("shutdown.exe", "-a");
  436.        }
  437.  
  438.        public void 打开桌面主旨面板()
  439.        {
  440.            Process.Start("rundll32.exe", " shell32.dll,Control_RunDLL themes.cpl");
  441.        }
  442.  
  443.        public void 打开网址(string address)
  444.        {
  445.            Process.Start(address);
  446.        }
  447.  
  448.        public void 运行程序(string name)
  449.        {
  450.            Process.Start(name);
  451.        }
  452.  
  453.        public void 显示任务栏()
  454.        {
  455.            ShowWindow(FindWindow("Shell_TrayWnd", null), SW_SHOW);
  456.        }
  457.  
  458.        public void 隐藏任务栏()
  459.        {
  460.            ShowWindow(FindWindow("Shell_TrayWnd", null), SW_HIDE);
  461.        }
  462.  
  463.        public void 发送邮件(string address)
  464.        {
  465.            string s = "mailto:" + address;
  466.            Process.Start(s);
  467.        }
  468.  
  469.        public void 发送邮件()
  470.        {
  471.            Process.Start("mailto:80368704@qq.com");
  472.        }
  473.  
  474.        public string 获取系统文件夹()
  475.        {
  476.            string s = Environment.GetFolderPath(Environment.SpecialFolder.System);
  477.            return s;
  478.        }
  479.  
  480.        public void 打开系统文件夹()
  481.        {
  482.            string s = Environment.GetFolderPath(Environment.SpecialFolder.System);
  483.            Process.Start(s);
  484.        }
  485.  
  486.        public string 获取ProgramFiles目录()
  487.        {
  488.            string s = Environment.GetFolderPath(Environment.SpecialFolder.ProgramFiles);
  489.            return s;
  490.        }
  491.  
  492.        public void 打开ProgramFiles目录()
  493.        {
  494.            string s = Environment.GetFolderPath(Environment.SpecialFolder.ProgramFiles);
  495.            Process.Start(s);
  496.        }
  497.  
  498.        public string 获取逻辑桌面()
  499.        {
  500.            string s = Environment.GetFolderPath(Environment.SpecialFolder.Desktop);
  501.            return s;
  502.        }
  503.  
  504.        public void 打开逻辑桌面()
  505.        {
  506.            string s = Environment.GetFolderPath(Environment.SpecialFolder.Desktop);
  507.            Process.Start(s);
  508.        }
  509.  
  510.        public string 获取启动程序组()
  511.        {
  512.            string s = Environment.GetFolderPath(Environment.SpecialFolder.Startup);
  513.            return s;
  514.        }
  515.  
  516.        public void 打开启动程序组()
  517.        {
  518.            string s = Environment.GetFolderPath(Environment.SpecialFolder.Startup);
  519.            Process.Start(s);
  520.        }
  521.  
  522.        public string 获取Cookies文件夹()
  523.        {
  524.            string s = Environment.GetFolderPath(Environment.SpecialFolder.Cookies);
  525.            return s;
  526.        }
  527.  
  528.        public void 打开Cookies文件夹()
  529.        {
  530.            string s = Environment.GetFolderPath(Environment.SpecialFolder.Cookies);
  531.            Process.Start(s);
  532.        }
  533.  
  534.        public string 获取Internet历史文件夹()
  535.        {
  536.            string s = Environment.GetFolderPath(Environment.SpecialFolder.History);
  537.            return s;
  538.        }
  539.  
  540.        public void 打开Internet历史文件夹()
  541.        {
  542.            string s = Environment.GetFolderPath(Environment.SpecialFolder.History);
  543.            Process.Start(s);
  544.        }
  545.  
  546.        public string 获取我的电脑文件夹()
  547.        {
  548.            string s = Environment.GetFolderPath(Environment.SpecialFolder.MyComputer);
  549.            return s;
  550.        }
  551.  
  552.        public void 打开我的电脑文件夹()
  553.        {
  554.            string s = Environment.GetFolderPath(Environment.SpecialFolder.MyComputer);
  555.            Process.Start(s);
  556.        }
  557.  
  558.        public string 获取MyMusic文件夹()
  559.        {
  560.            string s = Environment.GetFolderPath(Environment.SpecialFolder.MyMusic);
  561.            return s;
  562.        }
  563.  
  564.        public void 打开MyMusic文件夹()
  565.        {
  566.            string s = Environment.GetFolderPath(Environment.SpecialFolder.MyMusic);
  567.            Process.Start(s);
  568.        }
  569.  
  570.        public string 获取MyPictures文件夹()
  571.        {
  572.            string s = Environment.GetFolderPath(Environment.SpecialFolder.MyPictures);
  573.            return s;
  574.        }
  575.  
  576.        public void 打开MyPictures文件夹()
  577.        {
  578.            string s = Environment.GetFolderPath(Environment.SpecialFolder.MyPictures);
  579.            Process.Start(s);
  580.        }
  581.  
  582.        public string 获取StartMenu文件夹()
  583.        {
  584.            string s = Environment.GetFolderPath(Environment.SpecialFolder.StartMenu);
  585.            return s;
  586.        }
  587.  
  588.        public void 打开StartMenu文件夹()
  589.        {
  590.            string s = Environment.GetFolderPath(Environment.SpecialFolder.StartMenu);
  591.            Process.Start(s);
  592.        }  
  593.    }
  594. }
  595. //csharp/6782

回复 "一个用来调用DOS命令的C#操作类"

这儿你可以回复上面这条便签

captcha