SENDKEY does not work well

Asked 5 months ago, Updated 5 months ago, 13 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.



$shell=New-Object-ComObject Shell.Application

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

# visualization

# URL Open (Cache Disabled)

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





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

Press any key to continue.


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

© 2023 OneMinuteCode. All rights reserved.