Micro Focus QTP (UFT) Forums
How to RunAs different users with Internet Explorer - Printable Version

+- Micro Focus QTP (UFT) Forums (https://www.learnqtp.com/forums)
+-- Forum: Micro Focus UFT (earlier known as QTP) (https://www.learnqtp.com/forums/Forum-Micro-Focus-UFT-earlier-known-as-QTP)
+--- Forum: VB Scripting/Descriptive Programming (https://www.learnqtp.com/forums/Forum-VB-Scripting-Descriptive-Programming)
+--- Thread: How to RunAs different users with Internet Explorer (/Thread-How-to-RunAs-different-users-with-Internet-Explorer)



How to RunAs different users with Internet Explorer - Debby Browne - 03-30-2011

We need to test our website as different users, so want to open Internet Explorer with "RunAs".

When I use this (on Windows XP):
SystemUtil.Run "C:\Program Files\Internet Explorer\iexplore.exe","","C:\Program Files\Internet Explorer","runas"
the RunAs dialog window opens but QTP just hangs there until that the user info is filled in manually. I want to be able to fill it in from QTP. I have added the RunAs dialog (and it's controls) to the object repository and want to set the User Name and password from QTP, but apparently that SystemUtil.Run statement doesn't complete until the browser is open.

Is there another way to do this, possible with a script (which would include the user name and password passed in as parameters)? If so, how? If not, what do others do to test as different users?


RE: How to RunAs different users with Internet Explorer - JyotiRanjan - 03-30-2011

Hi ,

Use the below Code,


Code:
Dim objShell, objNetwork
Dim domain, program, domainUser

Set objShell = CreateObject("WScript.Shell")
Set objNetwork = WScript.CreateObject("WScript.Network")
domain = objNetwork.ComputerName
program = "notepad.exe"
domainUser = getUserName
WScript.Sleep 1000
runAsDomainUser domain, domainUser, program


Function runAsDomainUser(fxDom, fxUser, fxProgram)

   MsgBox "runas /env /user:" & fxDom & "\" & fxUser & " " & Chr(34) & fxProgram & Chr(34) & "",0,"This is what is being passed to RUNAS"
   objShell.Run "runas /env /user:" & fxDom & "\" & fxUser & " " & Chr(34) & fxProgram & Chr(34) & "",1,False
  
End Function


Function getUserName

  getUserName = InputBox("Enter your Domain or Local Computer UserName")
  If getUserName = "" Then
    WScript.Quit
  End If
End Function