Automate Internet Explorer running as different user with VBA RRS feed

  • Question

  • My Windows is logged-in as user1. I have to launch Internet Explorer via runas command as user2user1 executes the cmd line: runas /user:user2 "C:\Program Files\Internet Explorer\iexplore.exe". Once IE(user2) is running, with VBA(user1) I am not able to find shell application of IE(user2) with this snippet.

    Set objShell = CreateObject("Shell.Application")
    Set objShellWindows = objShell.Windows
    For Each obj In objShellWindows
    next obj

    Also I am not able to do this with Windows(user1), IE(user2) and VBA(user2).

    When the IE is launched as user1, this code works perfectly.

    How to manipulate IE(user2) with VBA(user1)? Thx

    • Edited by kabarto1986 Monday, September 9, 2019 9:16 AM
    Monday, September 9, 2019 6:59 AM

All replies

  • When you launch a program as a different user, the program is (understandably) running as that other user.

    The fact that the program is visible in the current logon session doesn't mean it's accessible to you programmatically.

    What problem are you trying to solve?

    -- Bill Stewart [Bill_Stewart]

    Monday, September 9, 2019 2:06 PM
  • I have dedicated server running for ID user1. I am doing the automation of website where users are verified based on their IDs (guessing... Single Sign-On mechanism). There is no chance to obtain credentials for user1. What I have are credentials of user2 who is capable to access the web site. There is any way (workaround) how to force system to control IE programmatically? Or somehow tell to website that user2 is comming...
    • Edited by kabarto1986 Monday, September 9, 2019 7:34 PM
    Monday, September 9, 2019 7:28 PM
  • Normally web-based single-sign on (SSO), in a Windows environment, is accomplished using integrated Windows authentication on the browser side. If you want to authenticate using a different user, start the browser using the other user's account.

    But this is an application architecture question that's not really suitable for a scripting forum.

    -- Bill Stewart [Bill_Stewart]

    Tuesday, September 10, 2019 2:03 PM
  • Use Powershell.

    function wait {
      param([int]$stop = 3)
      Start-Sleep -seconds $stop
    function SendWait {
    'Launching IE as my test account.'
    $userid = 'admin'
    $pswd = 'password'
    $secpswd = ConvertTo-SecureString $pswd -AsPlainText -Force
    $Cred = New-Object System.Management.Automation.PSCredential ($userid, $secpswd)
    start-process -FilePath 'C:\Program Files\Internet Explorer\iexplore.exe'-ArgumentList 'about:blank' -Credential $cred
    wait 10
    'Searching for IE'
    get-process -name iexplore |   foreach {
        "{0} - {1} - {2}" -f $_.Name, $, $_.MainWindowTitle
        if ($_.MainWindowTitle -ne '') {
           $ie = $_
    "I will work with {0}" -f $ie.MainWindowTitle
    [void] [System.Reflection.Assembly]::LoadWithPartialName("'Microsoft.VisualBasic")
    [void] [System.Reflection.Assembly]::LoadWithPartialName("'System.Windows.Forms")

    Tuesday, September 10, 2019 7:55 PM
  • @MotoX80: With your approach am I able to call method like this:
    $ie.document.getelementbyid("select_123").... ? If yes, how exactly?
    Wednesday, September 18, 2019 5:06 AM
  • I don't know. If you are calling document.getelementbyid I believe that you need to use the InternetExplorer.Application object.

    Here's a sample:  

    Your initial question shows a createobject for shell.application and you say that you want to manipulate IE, but you don't explain how. I'm sorry you didn't provide enough of your code for us to know what you are doing. 

    Have you tried setting IE to prompt for ID+pswd. I would expect that that would eliminate the need to launch IE as a different user. 

    Or fix the security on the web site to allow user1 to log on. 

    Wednesday, September 18, 2019 11:40 PM