这是调用外部程序的代码:            string domain = "mtkflash.com";
            string userName = "jasonmeng";
            string password = "mjx1023*+";
            try
            {
                Process process = new Process();
                SecureString passSecure = new SecureString();
                char[] passwordChars = password.ToCharArray();
                foreach (char c in passwordChars)
                {
                    passSecure.AppendChar(c);
                }
                process.StartInfo.FileName = "c:\\windows\\system32\\notepad.exe";
                process.StartInfo.UseShellExecute = false;
                process.StartInfo.CreateNoWindow = true;
                process.StartInfo.UserName = userName;
                process.StartInfo.Password = passSecure;
                process.StartInfo.Domain = domain;
                process.StartInfo.WindowStyle = ProcessWindowStyle.Normal;
                process.StartInfo.LoadUserProfile = true;
                process.StartInfo.RedirectStandardError = true;
                process.StartInfo.RedirectStandardOutput = true;
                process.StartInfo.RedirectStandardInput = true;
                process.Start();
                string resultString = process.StandardError.ReadToEnd();
                resultString = resultString + process.StandardOutput.ReadToEnd();
                resultString = resultString.Replace("'", "");
                MessageBox.Show(resultString);
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);       
            }
运行下来,不出错,但就是调不出来,报的错误是:
无法启动服务,原因可能是已被禁用或与其相关联的设备没有启动。
即使我把用户名和密码换成最简单的样式,依然如故!可是当我把这三句process.StartInfo.UserName = userName;
                process.StartInfo.Password = passSecure;
                process.StartInfo.Domain = domain;去掉以后,就能运行了?毛病到底出在哪里呢。请高手支个招【我的想法是这样,做一个服务,服务启动时启动一个有界面的程序,如果不能其他身份运行,那就看不到那个界面,所以必须以那个人的身份运行】

解决方案 »

  1.   

    你想当然了...StartInfo.Domain属性是为登录域用的,计算机必须加入AD才行,不是随便设置的...
      

  2.   

    回2位:我的计算机已经加入了域,我的电脑的完全的计算机名为:
    pc02.mtkflash.com
    没错了吧。
    string domain = "mtkflash.com";
    我把这个值,分别赋值为
    string domain = "pc02.mtkflash.com";
    string domain = "mtkflash.com";
    string domain = "mtkflash";
    都还是不对啊~~ 奇怪。
      

  3.   

    那是很奇怪...代码看起来没问题...把process.StartInfo.LoadUserProfile改为false,不要加载用户配置试一下...
      

  4.   

    不是吧...你这段代码在Windows服务里?真是无语了...
      

  5.   

    各位,我从网上扒来一段代码,来证明我的域账户是没问题的
    DirectoryEntry ads = new DirectoryEntry("WinNT://mtkflash.com", "jasonmeng", "mjx1023*+");
                try
                {
                    if (ads.Name == "mtkflash.com")
                    {
                        MessageBox.Show("ok");
                    }
                    else
                        MessageBox.Show("bad");
                }
                catch (Exception e1)
                {
                    MessageBox.Show("Err:"+e1.Message);
                }
                finally
                {
                    ads.Close();
                    ads.Dispose();
                }
    说明账户是没问题的。
    我把一楼我帖的代码中
     string domain = "mtkflash.com";
    改成  string domain = "WinNT://mtkflash.com";
    可结果还是那样,汗~~~~ 到底要怎么着呢。。