Process.Start不使用本地帐户 [英] Process.Start not working using a local account

查看:64
本文介绍了Process.Start不使用本地帐户的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

嗨专家,

我正在使用以下代码来启动流程。它适用于域用户,但对本地用户不起作用。



Hi experts,
I'm using the following code to start a process. It works perfect for a domain user, but it does not work for a local user.

using (SecureString password = new SecureString())
{
    string path = @"c:\temp\test\mytest.exe";

    foreach (char c in "test@mycomputer")
        password.AppendChar(c);
    string uname = "test";
    string domain = Environment.MachineName;
    Process.Start(path, uname, password, domain);
}





错误信息是:目录无效。



如果我作为域用户加入并尝试执行上述操作,则会发生这种情况...但是runas / user:test c:\ temp \ test \ mytest.exe可以正常工作。

[/ EDIT]





有什么想法吗?



提前谢谢。

Bruno



The error message is: Invalid Directory.

This happens if I'm loged in as domain user and try to do the above...but runas /user:test c:\temp\test\mytest.exe works.
[/EDIT]


Any idea?

Thank you in advance.
Bruno

推荐答案

最有可能是访问权限。确保您的本地用户可以读取目录及其内容。
Most probably access rights. Ensure that your local user can read the directory and its content.


尝试将空字符串作为参数传递:

Try passing an empty string as the domain parameter:
Process.Start(path, uname, password, string.Empty);



文档 [ ^ ]并不完全清楚,但它确实说域是启动进程时使用的 Active Directory域。您的计算机名称不是Active Directory域的名称。


The documentation[^] isn't entirely clear, but it does say the the domain is the "Active Directory domain to use when starting the process". Your computer name isn't the name of an Active Directory domain.


我不愿发布解决方案,因为这只是猜测。我认为命令提示符RunAs和Process.Start之间的区别在于用户配置文件的处理。 RunAs默认加载目标用户配置文件,而Process.Start则不加载。这可能意味着将加载默认用户配置文件。



要测试假设,请使用/ Noprofile开关尝试RunAs或提供带有LoadUserProfile = true的ProcessStartInfo你的Process.Start。



Alan。
I hesitate to post as a solution as this is only a guess. I think the difference between the command prompt "RunAs" and Process.Start is the handling of the user profile. RunAs loads the target user profile by default whereas the Process.Start does not. This probably means that the "Default User" profile will be loaded.

To test the hypothesis try RunAs with the /Noprofile switch or provide a ProcessStartInfo with LoadUserProfile = true for your Process.Start.

Alan.


这篇关于Process.Start不使用本地帐户的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆