简体   繁体   中英

How do I pass user/password to navigate method in a InternetExplorer.Application object

I want to automate a thing in IE using power shell , I have the following snippet:

$ie = new-object -com "InternetExplorer.Application";
$ie.navigate('http://urlWithAuthentication.com');

this url has http authentication, so the browser prompts for the user and password, the previous script works fine, but I would like to not interactively set the user and password.

for example:

This does not exist, looking for something similar

$ie.navigate('http://urlWithAuthentication.com','user','password');

there's nothing about authentication in the method documentation http://msdn.microsoft.com/en-us/library/aa752093%28v=vs.85%29.aspx

I've found questions similar but they were targeting when there's a login page (ie user/pass form), in this case I'm targeting to handle the browser's builtin user/pass promt.

I don't believe there is a function within the COM Object because i've also looked for this in the past, my own automation scripts use Wscript.Shell to send the Username, press tab, sent the password and then send the enter key.

# setup ie object and open website
$ie = new-object -com "InternetExplorer.Application";
$ie.navigate('http://urlWithAuthentication.com');
$passwordSent = 0
# wait for website to load
While ($ie.ReadyState -ne 4)
{
    Sleep -Milliseconds 500
        if ($ie.ReadyState -eq 1) {
             if ($passwordSent -eq 0) {
             $comShell = New-Object -com "Wscript.Shell" 
             $comShell.sendkeys($password)
             $comShell.sendkeys("{ENTER}")
             $passwordSent = 1;
        }
}

This is what worked for me. It works, however I receive an error because of the password I used. I think I need to make a new function to pass the password to the login mask,

# setup ie object and open website
$ie = new-object -com "InternetExplorer.Application";
$ie.navigate('http://YOURWEBSITE');
$passwordSent = 0
# wait for website to load
While ($ie.ReadyState -ne 4)
{
 Sleep -Milliseconds 500
  $comShell = New-Object -com "Wscript.Shell" 
  $comShell.sendkeys($username)
  $comShell.sendkeys("{TAB}")
  $comShell.sendkeys($password)
  $comShell.sendkeys("{ENTER}")
  $passwordSent = 1;
}

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.

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