简体   繁体   English

Powershell:如何从单独的窗口打开文件

[英]Powershell: How to open a file from a separate window

I'm using PowerShell for about a week now. 我现在使用PowerShell大约一周了。 I am able to open a specific URL and fill in my username and password automatically. 我可以打开一个特定的URL并自动填写我的用户名和密码。 I can also navigate to a certain page where multiple files can be found to download. 我还可以导航到某个页面,在该页面上可以找到多个文件进行下载。

I use the following command to select a certain file to download: 我使用以下命令选择要下载的特定文件:

$ie.navigate2('http://www.example.com/resource.aspx?ResourceID=GetDocStoreFile&EntryID=1234')

What happens next is that a second window will open, named "file download". 接下来发生的是将打开第二个窗口,名为“文件下载”。 There are three buttons: open, save and close. 有三个按钮:打开,保存和关闭。

I don't want to press the "open" button manually, but would like the script to do that for me and then goes back to the original window to select another file. 我不想手动按下“打开”按钮,但是希望脚本为我执行此操作,然后返回到原始窗口以选择另一个文件。 Any suggestions? 有什么建议么?

If you use a download URL, I don't think you can interact directly with IE using the COM object, because there's no document. 如果您使用下载URL,我认为您无法使用COM对象直接与IE进行交互,因为没有文档。 Once the dialog box opens, all of the object's properties become null. 对话框打开后,对象的所有属性都将变为空。 You can use the method I posted here: How to perform keystroke inside powershell? 您可以使用我在这里发布的方法: 如何在Powershell中执行击键? AppActivate will work to activate a dialog box by title. AppActivate将通过标题激活一个对话框。

The % represents the the ALT key, so if the underlined letter of the button you want to click is O, you'd invoke SendKeys like this: 表示ALT键,因此,如果要单击的按钮的带下划线的字母是O,则可以像下面这样调用SendKeys

$wshell.SendKeys('%O')

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM