0

Is there a way to open a URL in VB6 application without using Webbrowser or MSInet components? thanks

StayOnTarget
  • 11,743
  • 10
  • 52
  • 81
astralmaster
  • 2,344
  • 11
  • 50
  • 84

2 Answers2

7

If you just want to open the URL in a browser window, then use ShellExecute: http://support.microsoft.com/kb/224816

Private Declare Function ShellExecute _
                            Lib "shell32.dll" _
                            Alias "ShellExecuteA"( _
                            ByVal hwnd As Long, _
                            ByVal lpOperation As String, _
                            ByVal lpFile As String, _
                            ByVal lpParameters As String, _
                            ByVal lpDirectory As String, _
                            ByVal nShowCmd As Long) _
                            As Long

Private Sub Command1_Click()
   Dim r As Long
   r = ShellExecute(0, "open", "http://www.microsoft.com", 0, 0, 1)
End Sub

This will open the URL in the default browser.

Otherwise, if you need to display the webpage inside your app, use the WebBrowser control.

Akhilesh B Chandran
  • 6,523
  • 7
  • 28
  • 55
  • thansks, as I stated in question I want to open a web page in VB6 application and without using WebBrowser, as it would require me to redistribute this .ocx with my executable which I'm currently forbidden to do.(project management stuff) – astralmaster Jul 30 '12 at 05:41
  • I don't think that OCX(for WebBrowser control) needs to be distributed along with your app. PC with IE installed would have that OCX, I believe. My VB is a bit rusty. So, do a test run. What kind of operation are you doing with the app? If you don't like the classic Package&Deployment of VB, then you could make use of the free Inno Setup compiler to create the setup file for your app. – Akhilesh B Chandran Jul 30 '12 at 06:33
  • It needs the OCX to be distributed. Unfortunately I am allowed to place only single file (be it .exe or other) as my application on a virtual server where it's going to be used. – astralmaster Jul 30 '12 at 08:45
  • 1
    The control does need the OCX to be redistributed but `ShellExecute()` does not need the control. It just needs some web browser installed on the computer. The "single file" is a pretty arbitrary and stupid restriction though, epsecially as any VB6 apps need at least 5 other runtime DLLs to be installed. – Deanna Jul 30 '12 at 11:04
  • @Deanna it is something to be used for penetration testing, and is very much reasonable restriction. I don't want to go into details, but that's just how it is. – astralmaster Jul 31 '12 at 12:04
  • @Deanna and I need the web page to be displayed inside the VB6 application, not in a web browser as I already mentioned twice. – astralmaster Jul 31 '12 at 12:06
  • @Deanna oh and all the dll-s VB6 app needs to execute are already bundled with windows unless you use other controls from within VB6 like WebBrowser. – astralmaster Jul 31 '12 at 12:49
  • @astralmaster Only since Vista. All previous versions may have had them by luck but there is no guarantee. – Deanna Jul 31 '12 at 14:51
  • @ I have them on MS WinXP SP2 and MS Server 2003 R2. – astralmaster Jul 31 '12 at 14:54
  • @astralmaster You may well do. Doesn't mean they are part of the OS. – Deanna Aug 01 '12 at 07:56
  • @Deanna Actually I meant they are part of the OS. Even Windows 98 contains VB runtime libraries just of older version (not MSVBVM6) http://msdn.microsoft.com/en-us/vstudio/ms788708.aspx – astralmaster Aug 01 '12 at 18:06
  • @astralmaster So did I. Nothing in that article says the (the VB6 runtimes) are explicitly preinstalled on pre Vista. It was used by some optional components of XP so it may well have been included, but is far form guaranteed. See [this article](http://blogs.msdn.com/b/oldnewthing/archive/2008/01/11/7065021.aspx) for the same situation with MFC. – Deanna Aug 02 '12 at 08:45
  • @Deanna It does but 'between the lines'. very well, read here: http://support.microsoft.com/kb/314720 and here: http://support.microsoft.com/kb/823746 Notice that these versions of windows do NOT even have service packs installed. and Finally read here: http://discuss.fogcreek.com/joelonsoftware/default.asp?cmd=show&ixPost=125561 – astralmaster Aug 16 '12 at 15:02
1

No. VB6 does not have any intrinsic means of displaying a web page in an application. You have to use a third party control. On the other hand, this shouldn't be a problem, because you are essentially using a component of Microsoft Internet Explorer. In fact, you should not be distributing this control, because you would likely damage the end user's Windows installation.

Mark Bertenshaw
  • 5,594
  • 2
  • 27
  • 40