使用System.Diagnostics.Process的用户名和密码引发异常 [英] A exception is raised on using username and password for System.Diagnostics.Process

查看:236
本文介绍了使用System.Diagnostics.Process的用户名和密码引发异常的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

登录失败类型的异常:如果我使用
将用户名和密码用于System.Diagnostics.Process,则会引发未知的用户名或密码错误

An exception of type logon failure:unknown username or bad password is raised if I use username and password for System.Diagnostics.Process using

static void Main(string[] args)
        {
            Process p=new Process();
            p.StartInfo.UseShellExecute = false;
            p.StartInfo.FileName = @"D:\2011 HOLIDAYS.pdf";
            p.StartInfo.UserName = "hello";
            SecureString ss = new SecureString();
            foreach (char c in "hello")
                ss.AppendChar(c);
            p.StartInfo.Password = ss;
            p.Start();//here exception is raised;
        } 

推荐答案

我认为您对Process.StartInfo的用户名和密码功能有误解:它们与PDF文件无关-它们使该进程以其他用户身份登录运行.因此,除非您的计算机上有一个名为"hello"的用户,其登录密码为"hello",否则该方法将无法正常工作.您还需要指定用于登录用户的域-请参阅 MSDN [^ ]获取信息.

如果您试图打开一个受密码保护的PDF,那么可能会有一个命令行选项来指定启动该过程时的操作,但这取决于所使用的阅读器.
I think you have the wrong idea about the UserName and Password feature of Process.StartInfo: they do not relate to the PDF file - they cause the process to be run logged in as a different user. So, unless you have a user on your machine called "hello" with a login password of "hello", this isn''t going to work. You also need to specify the domain to log the user into - see MSDN[^] for info.

If you are trying to open a password protected PDF, then there is likely to be a command line option to specify that when you start the process, but that will depend on the reader being used.


SecureString建立在用户名字符串上以来,是否设置了密码?!使用调试器并测试ss.呼叫p.Start之前,应该一对一地输入您的密码,没有任何安全性" :-).

您可能完全误解了SecureString的目的.正确阅读: http://msdn.microsoft.com/en-us/library/system .security.securestring.aspx [ ^ ].此页面上有一个带有密码的示例.


我想我知道问题所在:这不是可执行文件,而是数据文件(PDF).用户名和密码不适用于该文档.如果文档受密码保护,则这是不同的用户名/密码,而不是您传递给Process的用户名/密码.

—SA
Since when the SecureString build on the user name string makes the password?! Use debugger and test ss. Before calling p.Start is should be your password, one-to-one, without any "security" :-).

You probably totally misunderstood the purpose of SecureString. Read properly: http://msdn.microsoft.com/en-us/library/system.security.securestring.aspx[^]. There is a sample with the password on this page.


I think I know the problem: this is not executable file but data file, a PDF. A user name and password are not applicable to the document. If the document is password-protected, this is different username/password, not those you pass to Process.

—SA


这篇关于使用System.Diagnostics.Process的用户名和密码引发异常的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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