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#程序设计有所帮助。

(0)

相关推荐

  • c#实现摄像头拍照功能示例

    复制代码 代码如下: using System.Drawing;using System.Drawing.Imaging;using System;using System.Runtime.InteropServices; 复制代码 代码如下: private const int WM_USER = 0x400;private const int WS_CHILD = 0x40000000;private const int WS_VISIBLE = 0x10000000;private con

  • C#实现控制摄像头的类

    本文实例讲述了C#实现控制摄像头的类.分享给大家供大家参考.具体如下: /// <summary> /// 一个控制摄像头的类 /// </summary> public class Pick { private const int WM_USER = 0x400; private const int WS_CHILD = 0x40000000; private const int WS_VISIBLE = 0x10000000; private const int WM_CAP_

  • C#操作ftp类完整实例

    本文实例讲述了C#操作ftp类.分享给大家供大家参考.具体如下: using System; using System.Collections.Generic; using System.Text; using System.IO; using System.Net; using System.Globalization; namespace FtpTest1 { public class FtpWeb { string ftpServerIP; string ftpRemotePath; st

  • C#实现用于操作wav声音文件的类实例

    本文实例讲述了C#实现用于操作wav声音文件的类.分享给大家供大家参考.具体如下: 有了这个C#类,我们可以很轻易的调用本地wav文件进行同步播放或者异步播放,大大简化了对wav文件的操作过程,如果你需要在项目中调用wav文件进行声音播放,可以使用这个C#类. using System; using System.Media; namespace DotNet.Utilities { /// <summary> /// 处理多媒体的公共类 /// </summary> public

  • C#操作Access通用类实例

    本文实例讲述了C#操作Access通用类.分享给大家供大家参考.具体如下: using System; using System.Data; using System.Configuration; using System.Web; using System.Web.Security; using System.Web.UI; using System.Web.UI.WebControls; using System.Web.UI.WebControls.WebParts; using Syst

  • C#实现IP摄像头的方法

    本文实例讲述了C#实现IP摄像头的方法.分享给大家供大家参考.具体实现方法如下: #region IP摄像头代码 /// <summary> /// ip摄像头代码 /// </summary> //视频 private IntPtr m_hChannel; private IntPtr m_hServer, phPlay; public delegate void MyInvoke(string str); public delegate void OutDelegate(Int

  • C#实现操作MySql数据层类MysqlHelper实例

    本文实例讲述了C#实现操作MySql数据层类MysqlHelper.分享给大家供大家参考.具体如下: using System; using System.Data; using System.Configuration; using System.Collections.Generic; using System.Linq; using System.Text; using System.Xml.Linq; using MySql.Data; using MySql.Data.MySqlCli

  • C#实现调用本机摄像头实例

    本文实例源自一个项目,其中需要调用本机的摄像头进行拍照,分享给大家供大家参考之用.具体步骤如下: 硬件环境:联想C360一体机,自带摄像头 编写环境:vs2010 语言:C# WPF 实现步骤: 下载AForge类库,并添加引用: using AForge; using AForge.Controls; using AForge.Video; using AForge.Video.DirectShow; using Size = System.Drawing.Size; 在xaml界面中添加Vi

  • C#实现的调用DOS命令操作类实例

    本文实例讲述了C#实现的调用DOS命令操作类.分享给大家供大家参考.具体如下: /*********************************** * All Rights Reserved , Copyright (C) 2012 , EricHu. * 作 者: EricHu * 创建时间: 2012-5-4 15:29:35 ***********************************/ using System; using System.Diagnostics; usi

  • Asp.Net中Cache操作类实例详解

    本文以一个Asp.Net的Cache操作类实例代码来详细描述了cache缓存的结构及实现方法,完整代码如下所示: /// <head> /// <function> /// 存储类(存储UserInfo信息) /// </function> /// <description> /// 用Cache存储用户信息 /// 在指定间隔(TimeOut)内取,则可以从Cache中取, /// 如果超出存储时间,则从数据库取用户信息数据 /// 作為所有用户信息的存儲

  • php针对cookie操作的队列操作类实例

    本文实例讲述了php针对cookie操作的队列操作类.分享给大家供大家参考.具体分析如下: 这里包括了从简单的cookie操作(增加,删除,修改)到我们的cookie队列操作类的操作,对此感兴趣的朋友可以参考一下. 一.PHP 的COOKIE cookie 是一种在远程浏览器端储存数据并以此来跟踪和识别用户的机制. PHP 在http 协议的头信息里发送cookie,因此 setcookie() 函数必须在其它信息被输出到浏览器前调用,这和对  header() 函数的限制类似. 设置cooki

  • php mysql数据库操作类(实例讲解)

    接着稍微说说整体的思路.整个类的封装,包含一个连接数据库的私有属性$conn和若干操作函数.$conn在对象实例化的时候,由构造函数处理传入的参数后返回一个资源型的连接句柄.而后即可通过调用该实例化的对象的相应方法对数据库进行增删查改的操作. talk less and show code: <?php /** *以下代码用于数据库操作类的封装 * * @author rex<rex.sp.li@aliyun.com> * @version 1.0 * @since 2015 */ cl

  • C#封装的常用文件操作类实例

    本文实例讲述了C#封装的常用文件操作类.分享给大家供大家参考.具体如下: 这个C#类封装了我们经常能用到的文件操作方法,包括读写文件.获取文件扩展名.复制文件.追加内容到文件.删除文件.移动文件.创建目录.递归删除文件及目录.列目录.列文件等,不可多得. using System; using System.Text; using System.Web; using System.IO; namespace DotNet.Utilities { public class FileOperate

  • C#实现的sqlserver操作类实例

    本文实例讲述了C#实现的sqlserver操作类.分享给大家供大家参考,具体如下: using System; using System.Collections.Generic; using System.Web; using System.Data.OleDb; using System.Data; using System.Data.SqlClient; /// <summary> ///SqlConnDb类,适用于Sql数据库操作 /// </summary> public

  • php实现的debug log日志操作类实例

    本文实例讲述了php实现的debug log日志操作类.分享给大家供大家参考,具体如下: <?php class Tool { public static function log($info) { $time = date('m-d H:i:s'); $backtrace = debug_backtrace(); $backtrace_line = array_shift($backtrace); // 哪一行调用的log方法 $backtrace_call = array_shift($ba

  • C# Oracle数据库操作类实例详解

    本文所述为C#实现的Oracle数据库操作类,可执行超多常用的Oracle数据库操作,包含了基础数据库连接.关闭连接.输出记录集.执行Sql语句,返回带分页功能的dataset .取表里字段的类型和长度等,同时还有哈稀表自动插入数据库等高级任务.需要特别指出的是:在执行SQL语句,返回 DataReader之前一定要先用.read()打开,然后才能读到数据,再用hashTable对数据库进行insert,update,del操作,注意此时只能用默认的数据库连接"connstr". 完整

  • C#之Socket操作类实例解析

    本文展示了一个C#的Socket操作类的完整实例,并附带了用法说明,分享给大家供大家参考之用.具体方法如下: 主要功能代码如下: using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Net.Sockets; using System.Collections; using System.Net; using System.Runtime.Serializ

  • C#的SQL操作类实例

    本文实例讲述了C#的SQL操作类,分享给大家供大家参考.具体方法如下: 复制代码 代码如下: using System; using System.Collections.Generic; using System.Text; using System.Data; using System.Data.SqlClient; using System.Windows.Forms; namespace yjgl {     /// <summary>        /// 数据访问基础类(SQL) 

随机推荐