想用cmd进行一些用户设置,但是system身份 new process搞出来的cmd也都是system身份的设置的不是当前用户的,很苦恼怎么搞呢?

解决方案 »

  1.   

    知道vc里面用runas,createprocessasuser好像都可以,但是c#不知道怎么搞阿
      

  2.   

    参考这个
                                  string   sUsername   =   "user";   
                              string   sPassword   =   "123";   
        
                              Process   updateProcess   =   new   Process();   
                              //updateProcess.StartInfo.ErrorDialog   =   false;   
                              updateProcess.StartInfo.UseShellExecute   =   false;   
                              updateProcess.StartInfo.RedirectStandardOutput   =   true;   
        
                              updateProcess.StartInfo.UserName   =   sUsername;   
                              SecureString   password   =   new   SecureString();   
                              for   (int   i   =   0;   i   <   sPassword.Length;   i++)   
                              {   
                                      password.AppendChar(sPassword[i]);   
                              }   
        
                              updateProcess.StartInfo.Password   =   password;   
        
                              updateProcess.StartInfo.FileName   =   @"d:\test\update\update.bat";   
                              updateProcess.StartInfo.WorkingDirectory   =   @"d:\test\update";   
        
                              updateProcess.Start();
      

  3.   

    当前的用户名和密码  那个“user”和“123”如何获得呢?
      

  4.   

    用户名就是Environment.UserName
    密码获取不了,得自己设定
      

  5.   

    恩比方os以用户test登录我想在系统服务中打开一个cmd,如果直接用process出来cmd是以system运行,在当前桌面也看不到cmd,我现在就想让这个cmd运行到当前的test的桌面那么必须得弹出一个要求输入test密码的框才能实现么?这个时候test用户不是都已经登陆了么?