c# Process类使用小例

  公司为了安全方面的考虑,对员工使用的window操作系统做了权限限制。如果我们想在自己使用的机器上安装额外的软件,就需要找系统管理员!感觉是相当的不爽啊!

  但是为了我们这些程序员正常工作,允许我们用管理员的权限运行vs2010,这就为我们间接获得管理员权限安装自己想要的软件留下了后门。对了,我们要做的就是用管理员权限登录vs2010,通过process类打开所需的exe文件即可。

 

代码比较简单,可以创建一个winform项目,添加一个按钮控件,添加一个OpenFileDialog控件。

 

private void runBtn_Click(object sender, EventArgs e)         
{   DialogResult dialogResult
= openFile.ShowDialog();   openFile.InitialDirectory = "d:\\";   //注意这里写路径时要用c:\\而不是c:\   openFile.Filter = "文本文件|*.*|所有文件|*.*";   openFile.RestoreDirectory = true;   openFile.FilterIndex = 1;   if (openFile.ShowDialog() == DialogResult.OK)   {     string fileName = openFile.FileName;     Process myProcess = new Process();     try     {       myProcess.StartInfo.UseShellExecute = false; myProcess.StartInfo.FileName=openFile.FileName;       myProcess.StartInfo.CreateNoWindow = true;       myProcess.Start();     }     catch (Exception ex)     {       Console.WriteLine(ex.Message);     }   } }

 

posted @ 2012-07-17 15:31  下一站永远  阅读(1941)  评论(5编辑  收藏  举报