SENDKEY does not work well

Asked 2 months ago, Updated 2 months ago, 3 views

Thank you for your cooperation.

What you want to do
If you request a URL, the file is automatically downloaded.
I would like to automate this process and register with the Windows Task Scheduler.

I wrote the shell below and it worked fine with POWERSHELL ISE, but from the batch file
When I call you, I get an error in the following parts.Similarly, you get the same error when you run from a POWERSHELL command prompt.I have been thinking about it for about 3 days, but I would appreciate it if you could give me a comment asking if you understand the reason.

What I'm doing is trying to process the Save button with SendKey in the IE download dialog box.

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

Script

$url="https://hoge.com/?un=userID&pass=password?file=00O7F00000AnYio?export=1"
$shell=New-Object-ComObject Shell.Application

# IE Boot
$ie = New-Object-ComObject InternetExplorer.Application

# visualization
$ie.Visible=$true

# URL Open (Cache Disabled)
$ie.Navigate($url,4)

While ($ie.Busy)
{ Start-Sleep-s1}                                      

Start-Sleep2 

System.Windows.Forms.SendKeys::SendWait("%({S})")

Start-Sleep2 

$ie.Quit()

Example Execution

 C:\TEST> powershell-ExecutionPolicy Unrestricted-File c:\TEST\sample.ps1
Type [System.Windows.Forms.SendKeys] not found.
Occurrence Location C:\TEST\sample.ps1:21 Characters:1
+ System.Windows.Forms.SendKeys::SendWait("%({S})")
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo: InvalidOperation: (System.Windows.Forms.SendKeys)
   : TypeName) [ ], RuntimeException
    + Fully QualifiedErrorId—TypeNotFound

C:\TEST>pause
Press any key to continue.

powershell

2022-09-30 13:46

1 Answers

Why don't you add the following?

Add-Type-AssemblyName System.Windows.Forms

Note: Tried automating Windows with SendKeys on PowerShell


2022-09-30 13:46

If you have any answers or tips


© 2022 OneMinuteCode. All rights reserved.