Right now I'm trying to code a tool that shall be capable of downloading a file from a specific website, beside some other stuff.
My current solution is, that I open the website from where the file shall be downloaded in Internet Explorer, wait some seconds so the website can be loaded and then send a keystroke to Internet Explorer, which is ALT+S, to save the file to the standard download location.
However, my code fails in the line where the keystroke should be sent. You'll find it below of course plus the error it throws.
Some facts I believe you'll find useful to know:
What I specifically like to know is:
And most important: Please note that I'm a hobby programmer and just started with VB a few weeks ago. If I missed out some important information or my code looks weird, well, then that's why :)
Sub Download()
Dim IE As Object
IE = CreateObject("InternetExplorer.Application")
Console.WriteLine("Start Download")
IE.Navigate("https://toolslib.net/downloads/finish/1-adwcleaner/") 'Opens the website in Internet Explorer
Do 'Waits for Internet Explorer to be launched before going on
If CBool(Process.GetProcesses.Where(Function(P As Process) _
P.ProcessName = "iexplore").Count) Then
Exit Do
End If
Threading.Thread.Sleep(100)
Loop
IE.Visible = True
Threading.Thread.Sleep(5000) 'Some time for the website to load
IE.SendKeys("%{S}", True)
End Sub
When running this code it throws the following error.
Note: Line 67 is the line where IE.SendKeys("%{S}", True) stands.
Unhandled Exception: System.ArgumentException: The process {0} wasn't found.
at Microsoft.VisualBasic.CompilerServices.Symbols.Container.InvokeMethod(Method TargetProcedure, Object[] Arguments, Boolean[] CopyBack, BindingFlags Flags)
at Microsoft.VisualBasic.CompilerServices.NewLateBinding.CallMethod(Container BaseReference, String MethodName, Object[] Arguments, String[] ArgumentNames, Type[] TypeArguments, Boolean[] CopyBack, BindingFlags InvocationFlags, Boolean ReportErrors, ResolutionFailure& Failure)
at Microsoft.VisualBasic.CompilerServices.NewLateBinding.ObjectLateCall(Object Instance, Type Type, String MemberName, Object[] Arguments, String[] ArgumentNames, Type[] TypeArguments, Boolean[] CopyBack, Boolean IgnoreReturn)
bei Microsoft.VisualBasic.CompilerServices.NewLateBinding.LateCall(Object Instance, Type Type, String MemberName, Object[] Arguments, String[] ArgumentNames, Type[] TypeArguments, Boolean[] CopyBack, Boolean IgnoreReturn)
at MyApp.Module1.Download() in C:\Users\User\Documents\Visual Studio 2017\Projects\MyApp\MyApp\Module1.vb:Line 67.
I used WebBrowser control in form application and its worked fine me!
SendKeys.Send("+{TAB}")
System.Threading.Thread.Sleep(1000)
SendKeys.Send("{ENTER}")
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.