使用powershell处理弹出框
有人能告诉我如何使用powershell在弹出窗口中单击“确定”或“取消”吗? 我正在尝试使用powershell自动化一个网站,但我是powershell新手。我必须点击弹出框中的OK按钮才能继续。我知道VBscript,因为我可以使用它使用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
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}")
来源/灵感:
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}')