简体   繁体   English

开始一个过程

[英]Starting a process

As part of SharePoint automation testing, I am trying to open Internet Explorer as another user by using the System.Diagnostics.Process . 作为SharePoint自动化测试的一部分,我试图通过使用System.Diagnostics.Process以另一个用户身份打开Internet Explorer。 Here is the following C# code 这是下面的C#代码

System.Diagnostics.Process p = new System.Diagnostics.Process();

// Domain and User Name:
p.StartInfo.Domain = "MYDOMAIN";
p.StartInfo.UserName = "myusername";

// Command to execute and arguments:
p.StartInfo.FileName = "C:\\Program Files (x86)\\Internet Explorer\\iexplore.exe";
p.StartInfo.Arguments = "http://url/AllItems.aspx";

// Build the SecureString password...
System.String rawPassword = "thepassword";
System.Security.SecureString encPassword = new System.Security.SecureString();
foreach (System.Char c in rawPassword)
{
    encPassword.AppendChar(c);
}

p.StartInfo.Password = encPassword;

// The UseShellExecute flag must be turned off in order to supply a password:
p.StartInfo.UseShellExecute = false;
p.StartInfo.CreateNoWindow = false;

p.Start();

When I run this automated test Visual Studio returns informing me that the test was successful, however Internet Explorer does not open. 当我运行此自动化测试时,Visual Studio返回通知我测试成功,但是Internet Explorer无法打开。

Is there something in my code I am missing in order for a window to appear? 为了使窗口出现,我的代码中缺少某些内容吗? There is no iexplore process running prior to the test being run. 在运行测试之前,没有iexplore进程正在运行。

putting double quotes around the file path (since it contains spaces) may help: 在文件路径两边加上双引号(因为它包含空格)可能会有所帮助:

p.StartInfo.FileName = "\"C:\\Program Files (x86)\\Internet Explorer\\iexplore.exe\""
                        ^^                                                        ^^

In addition, if your intention is to start this from a service process or dll running in a service such as "SharePoint", then this code will probably not launch the process in the desktop desired. 另外,如果您打算从服务进程或运行在诸如“ SharePoint”之类的服务中的dll启动此进程,则此代码可能不会在所需的桌面上启动该进程。 You'll need to set the desktop to "winsta0\\\\default" in the startup info. 您需要在启动信息中将桌面设置为"winsta0\\\\default"

To run a process the worker process should have high privileges and this is not an ideal case in any web application. 要运行进程,辅助进程应具有较高的特权,这在任何Web应用程序中都不是理想的情况。 If your purpose is to use IE for unit testing then I would consider using something like WaitIN . 如果您的目的是使用IE进行单元测试,那么我会考虑使用类似WaitIN的方法 If your purpose is for application logic to access a URL and do something then consider using HttpWebRequest . 如果您的目的是让应用程序逻辑访问URL并执行某些操作,则可以考虑使用HttpWebRequest If you still need a process to be started then create a Windows Service and then expose a web call so in Share Point you can just make a call and your Windows Service can run on local account or some other high privilege account. 如果仍然需要启动某个过程,则创建一个Windows服务,然后公开一个Web呼叫,以便在Share Point中可以进行呼叫,并且Windows Service可以在本地帐户或其他一些高特权帐户上运行。

Hope this helps and please provide the scenario why you want to start the IE and that can give you a better answer in the forum. 希望这会有所帮助,并请提供您为什么要启动IE的方案,并在论坛中为您提供更好的答案。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM