这就是我想要实现的目标:
出于某些安全原因,我们不会让Windows应用程序打开浏览器。到目前为止,我已经使它工作,直到触发PowerShell脚本。 这是问题我有:
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。