Launching IE as an Object [RESOLVED]
I'm using the code below to launch IE and navigate to a website. I'm having a problem with it because the site it goes to uses cookies for user sessions. The cookie contains, among other information, the user's login name. There is also another program that uses the same method to launch IE that goes to the same page, however, it requires a different log in to access different parts of the site. Currently people who launch one program first aren't able to login if they try to launch the second program. If they manually go to the website and do it it works though. Anyone have any ideas as to why this is happening?
Code for first app:
VB Code:
Private Sub Form_Load()
Dim objMSIE1
Dim boolFileExists As Boolean
Dim strNotFound As String
Set objMSIE1 = CreateObject("InternetExplorer.Application")
If Err.Number = 0 Then 'No error
boolFileExists = True
outrc = 0
Else
boolFileExists = False
strNotFound = "I cannot find Internet Explorer." & vbCrLf & "Please download Internet Explorer from www.microsoft.com/windows/ie"
MsgBox strNotFound, vbCritical, "Application Error"
outrc = 1
Exit Sub
End If
objMSIE1.Navigate ("https://website/")
objMSIE1.Visible = True
Set objMSIE1 = Nothing
Unload Me
End
End Sub
Code for second app:
VB Code:
Private Sub Form_Load()
Dim objMSIE
Dim boolFileExists As Boolean
Dim strNotFound As String
Set objMSIE = CreateObject("InternetExplorer.Application")
If Err.Number = 0 Then 'No error
boolFileExists = True
outrc = 0
Else
boolFileExists = False
strNotFound = "I cannot find Internet Explorer." & vbCrLf & "Please download Internet Explorer from www.microsoft.com/windows/ie"
MsgBox strNotFound, vbCritical, "Application Error"
outrc = 1
Exit Sub
End If
objMSIE.Navigate ("https://website/")
objMSIE.Visible = True
Set objMSIE = Nothing
Unload Me
End
End Sub
Re: Launching IE as an Object
I'm pretty sure this can be solved by launching IE as separate processes, so that each would have it's own process ID. Is there some way to set it up so that they are unique processes?
It's similar to this posting (unresolved):
http://www.vbforums.com/showthread.php?t=162748
Re: Launching IE as an Object
See Post #4 here by TheVader. Is that what you mean?
Re: Launching IE as an Object
It looks like the same method to start an IE object, it's just that I need each IE to be a separate process. For example, when you use Internet Explorer and use the right-click 'Open in New Window' command it still lists only one 'IExplore.exe' in the Task Manager processes list. However, if you click the IE icon to start a new Internet Explorer it creates a new 'IExplore.exe' process.
Is there a way to launch IE and specify you want it as a new process?
Re: Launching IE as an Object
TheVader's code will launch each instance of IE in a new window. It will not use a previous opened window.
Re: Launching IE as an Object
That's what mine will do as well, the problem is they are all run under the same Process ID. If you launch it to two times it will instantiate two browsers but one process. This becomes a problem when you are working with secure websites.
You can see what I'm talking about if you start Task Manager and go to the processes tab. Launch Internet Explorer to a website with 'TheVader' or my code. You will only see one process of 'IExplore.exe' start up with two instances of the browser windows open (provided you don't have other browsers open besides these two). Now if you launch IE by clicking the icon to start two browsers you will see 'IExplore.exe' listed twice with two unique process ID's.
I guess I could just use Shell instead and see if that brings up two separate processes, which I'm sure it will just a little messier than using objects.
Re: Launching IE as an Object
In case anyone is interested here is a good explanation. It's the third question down:
http://msdn.microsoft.com/msdnmag/issues/04/05/WebQA/
I wish we were using .NET here, this would be so simple...
1 Attachment(s)
Re: Launching IE as an Object
In case anyone else is interested in this problem the only way to resolve it is to call the .EXE directly to create multiple IE processes. Any of the simpler object based ways only create multiple threads and one process.
Below is some code I made for this that finds the location of IExplore.exe through the registry and then launches a website. The registry module is attached.
VB Code:
Option Explicit
Const HKEY_CLASSES_ROOT = &H80000000
Const HKEY_CURRENT_USER = &H80000001
Const HKEY_LOCAL_MACHINE = &H80000002
Const HKEY_USERS = &H80000003
' Reg Key Security Options...
Const READ_CONTROL = &H20000
Const KEY_QUERY_VALUE = &H1
Const KEY_SET_VALUE = &H2
Const KEY_CREATE_SUB_KEY = &H4
Const KEY_ENUMERATE_SUB_KEYS = &H8
Const KEY_NOTIFY = &H10
Const KEY_CREATE_LINK = &H20
Const KEY_ALL_ACCESS = KEY_QUERY_VALUE + KEY_SET_VALUE + _
KEY_CREATE_SUB_KEY + KEY_ENUMERATE_SUB_KEYS + _
KEY_NOTIFY + KEY_CREATE_LINK + READ_CONTROL
Private Sub Form_Load()
Dim strSubKey As String
Dim strValueName As String
Dim AppPath As String
Dim AppPathLen As Integer
'Registry value locations
strSubKey = "SOFTWARE\Classes\Applications\iexplore.exe\shell\open\command"
strValueName = ""
'Returning the application path back from registry
AppPath = RegGetValue$(HKEY_LOCAL_MACHINE, strSubKey, strValueName)
'Determining the length of the path
AppPathLen = Len(AppPath)
'Removing the " %1" from the end of the path
AppPath = Left(AppPath, AppPathLen - 3)
'Adding the site to be navigated to
AppPath = AppPath & " website"
'Launching IE
Shell AppPath, vbNormalFocus
End
End Sub