从c#Web服务触发的IE无法打开UI

时间:2017-08-02 15:39:43

标签: c# web-services powershell internet-explorer

这就是我想要实现的目标:

  1. 我有一个客户端窗口应用程序"触发过程"按钮
  2. 开启"触发过程"单击,它应该调用名为" DataRefresh"
  3. 的Web服务
  4. " DataRefresh" service应该通过批处理文件触发PowerShell脚本。这会打开IE浏览器,然后点击一个按钮。
  5. 出于某些安全原因,我们不会让Windows应用程序打开浏览器。到目前为止,我已经使它工作,直到触发PowerShell脚本。 这是问题我有:

    • 通过Web服务触发的IE无法打开用户界面,但我在任务管理器中看到IE进程。

    PS脚本:

    param ([string]$managerefrehURL)
    $ie = New-Object -ComObject 'internetExplorer.Application'  
    $ie.Navigate($managerefrehURL)
    $ie.Visible= $true
    while ($ie.Busy -eq $true){Start-Sleep -seconds 1;}   
    
    #click Also refresh as soon as possible button, check box ID ends with _cbRunNow
    
    $checkBox = $ie.Document.getElementsByTagName("input") | Where-Object {$_.id -like "*_cbRunNow"}
    $checkBox.click()
    
    #click OK button, id ends with _OK
    
    #OK
    
    $OK = $ie.Document.getElementsByTagName("input") | Where-Object {$_.id -like "*_OK"}
    $OK.click()
    Start-Sleep -seconds 5;
    
    $ie.Quit()
    

    网络服务:

    public string TriggerDataRefresh(string listId, string userId)
    {           
        string status = string.Empty;
        string dataRefreshPSPath = ConfigurationManager.AppSettings["DataRefreshPSPath"];
        string refreshURL = ConfigurationManager.AppSettings["RefreshUrl"];
        refreshURL += "?list=" + listId + "&ID=" + userId;
    
        if (File.Exists(dataRefreshPSPath))
        {
            Process proc = new Process();
            proc.StartInfo.WorkingDirectory = Path.GetDirectoryName(dataRefreshPSPath);
            proc.StartInfo.FileName = dataRefreshPSPath;
            proc.StartInfo.Arguments = string.Format("\"{0}\"", "'" + refreshURL + "'");
            proc.StartInfo.UseShellExecute = true; //tried false also
            proc.StartInfo.WindowStyle = ProcessWindowStyle.Maximized;                    
    
            proc.Start();
            status = proc.Id.ToString();
        }
    }
    

    当我单独运行PS脚本时,它正在打开IE浏览器。不知道为什么在从Web服务触发时不会打开IE UI。

0 个答案:

没有答案