Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/shell/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
使用powershell处理弹出框_Shell_Powershell_Popup_Automation - Fatal编程技术网

使用powershell处理弹出框

使用powershell处理弹出框,shell,powershell,popup,automation,Shell,Powershell,Popup,Automation,有人能告诉我如何使用powershell在弹出窗口中单击“确定”或“取消”吗? 我正在尝试使用powershell自动化一个网站,但我是powershell新手。我必须点击弹出框中的OK按钮才能继续。我知道VBscript,因为我可以使用它 set obj0 = createobject("wscript.shell") count = 0 do while count = 0 if obj0.appactivate "Popupboxname" then ----perform require

有人能告诉我如何使用powershell在弹出窗口中单击“确定”或“取消”吗? 我正在尝试使用powershell自动化一个网站,但我是powershell新手。我必须点击弹出框中的OK按钮才能继续。我知道VBscript,因为我可以使用它

set obj0 = createobject("wscript.shell")
count = 0
do while count = 0
if obj0.appactivate "Popupboxname" then
----perform required action---
count = 1
else
wscript.sleep(2000)
end if
loop

有人能告诉我如何在powershell中做同样的事情吗?如果我可以访问弹出窗口,至少我可以使用sendkeys命令发送回车键。请让我知道如何处理弹出窗口。提前感谢。

您可能想从CodePlex调查WASP管理单元:


您可能想从CodePlex调查黄蜂管理单元:


使用Powershell v2,您可以使用PInvoke访问正常的Win32 API,从而访问
FindWindow
SetForegroundWindow
。然后使用
SendKeys
发送
Enter

类似于下面的内容来注册方法:

$pinvokes = @'
    [DllImport("user32.dll", CharSet=CharSet.Auto)]
    public static extern IntPtr FindWindow(string className, string windowName);

    [DllImport("user32.dll")]
    [return: MarshalAs(UnmanagedType.Bool)]
    public static extern bool SetForegroundWindow(IntPtr hWnd);
'@

Add-Type -AssemblyName System.Windows.Forms
Add-Type -MemberDefinition $pinvokes -Name NativeMethods -Namespace MyUtils
现在,您可以找到所需的窗口:

$hwnd = [MyUtils.NativeMethods]::FindWindow(null, "Popupboxname")
重点关注:

[MyUtils.NativeMethods]::SetForegroundWindow($hwnd)
然后发送
Enter
键:

[System.Windows.Forms.SendKeys]::SendWait("{ENTER}")

来源/灵感:


使用Powershell v2,您可以使用PInvoke访问正常的Win32 API,从而访问
FindWindow
SetForegroundWindow
。然后使用
SendKeys
发送
Enter

类似于下面的内容来注册方法:

$pinvokes = @'
    [DllImport("user32.dll", CharSet=CharSet.Auto)]
    public static extern IntPtr FindWindow(string className, string windowName);

    [DllImport("user32.dll")]
    [return: MarshalAs(UnmanagedType.Bool)]
    public static extern bool SetForegroundWindow(IntPtr hWnd);
'@

Add-Type -AssemblyName System.Windows.Forms
Add-Type -MemberDefinition $pinvokes -Name NativeMethods -Namespace MyUtils
现在,您可以找到所需的窗口:

$hwnd = [MyUtils.NativeMethods]::FindWindow(null, "Popupboxname")
重点关注:

[MyUtils.NativeMethods]::SetForegroundWindow($hwnd)
然后发送
Enter
键:

[System.Windows.Forms.SendKeys]::SendWait("{ENTER}")

来源/灵感:


试试这样的方法:

$wshell = New-Object -ComObject wscript.shell; 
$wshell.AppActivate('Vector RP1210 API Setup') 
Sleep 1 
$wshell.SendKeys('%C')
$wshell.AppActivate('Vector RP1210 API') 
Sleep 1 
$wshell.SendKeys('{ENTER}')

试着这样做:

$wshell = New-Object -ComObject wscript.shell; 
$wshell.AppActivate('Vector RP1210 API Setup') 
Sleep 1 
$wshell.SendKeys('%C')
$wshell.AppActivate('Vector RP1210 API') 
Sleep 1 
$wshell.SendKeys('{ENTER}')