VBScript - 将 Microsoft Edge window 置于前台
VBScript - Bring Microsoft Edge window to foreground
我的脚本启动了 MS Edge window,然后尝试使用我的凭据登录 Netflix。问题是,有时,浏览器 window 在 CMD 控制台后面出现,脚本无法运行。
如何在前台启动浏览器或在启动后将其置于前台?
<!-- :
rem @Echo Off
Set "usr_name=#####"
Set "usr_pass=#####"
%SystemRoot%\System32\cscript.exe //NoLogo "%~f0?.wsf" "%browser%" "%usr_name%" "%usr_pass%"
Exit /B
-->
<Job>
<Script Language="VBScript">
Dim ObjShell, MyChrome
Set ObjShell = WScript.CreateObject("WScript.Shell")
MyChrome = Chr(34) & WScript.Arguments(0) & Chr(34)
ObjShell.Run MyChrome & "--app=""https://www.netflix.com/login""", 1
WScript.Sleep 5000
ObjShell.SendKeys "{TAB}"
ObjShell.SendKeys "{TAB}"
ObjShell.SendKeys(WScript.Arguments(1))
ObjShell.SendKeys "{TAB}"
ObjShell.SendKeys(WScript.Arguments(2))
ObjShell.SendKeys "{ENTER}"
WScript.Sleep 6000
ObjShell.SendKeys "{ESCAPE}"
ObjShell.SendKeys "{TAB}"
WScript.Sleep 1000
ObjShell.SendKeys "{TAB}"
WScript.Sleep 1000
ObjShell.SendKeys "{ENTER}"
WScript.Sleep 6000
ObjShell.SendKeys "%{F4}"
</Script>
</Job>
依赖于 SendKeys
的脚本是出了名的不可靠。比较靠谱的做法是用Seleniumbasic and Chrome driver or use WebView2 in a C# program. Barring that, one option for adding window control functionality to your existing script is to use the command line tool Cmdow来控制浏览器。例如:
ObjShell.Run "cmdow ""Netflix*"" /MAX",1,False
更新:
你也可以试试built-inAppActivate
方法:
ObjShell.AppActivate "Netflix"
使用 powershell cmdlet 最小化 运行 启动浏览器的脚本之前的所有 windows 的解决方案。
'''powershell -command "(new-object -com shell.application).minimizeall()'''
我的脚本启动了 MS Edge window,然后尝试使用我的凭据登录 Netflix。问题是,有时,浏览器 window 在 CMD 控制台后面出现,脚本无法运行。
如何在前台启动浏览器或在启动后将其置于前台?
<!-- :
rem @Echo Off
Set "usr_name=#####"
Set "usr_pass=#####"
%SystemRoot%\System32\cscript.exe //NoLogo "%~f0?.wsf" "%browser%" "%usr_name%" "%usr_pass%"
Exit /B
-->
<Job>
<Script Language="VBScript">
Dim ObjShell, MyChrome
Set ObjShell = WScript.CreateObject("WScript.Shell")
MyChrome = Chr(34) & WScript.Arguments(0) & Chr(34)
ObjShell.Run MyChrome & "--app=""https://www.netflix.com/login""", 1
WScript.Sleep 5000
ObjShell.SendKeys "{TAB}"
ObjShell.SendKeys "{TAB}"
ObjShell.SendKeys(WScript.Arguments(1))
ObjShell.SendKeys "{TAB}"
ObjShell.SendKeys(WScript.Arguments(2))
ObjShell.SendKeys "{ENTER}"
WScript.Sleep 6000
ObjShell.SendKeys "{ESCAPE}"
ObjShell.SendKeys "{TAB}"
WScript.Sleep 1000
ObjShell.SendKeys "{TAB}"
WScript.Sleep 1000
ObjShell.SendKeys "{ENTER}"
WScript.Sleep 6000
ObjShell.SendKeys "%{F4}"
</Script>
</Job>
依赖于 SendKeys
的脚本是出了名的不可靠。比较靠谱的做法是用Seleniumbasic and Chrome driver or use WebView2 in a C# program. Barring that, one option for adding window control functionality to your existing script is to use the command line tool Cmdow来控制浏览器。例如:
ObjShell.Run "cmdow ""Netflix*"" /MAX",1,False
更新:
你也可以试试built-inAppActivate
方法:
ObjShell.AppActivate "Netflix"
使用 powershell cmdlet 最小化 运行 启动浏览器的脚本之前的所有 windows 的解决方案。
'''powershell -command "(new-object -com shell.application).minimizeall()'''