I've created a program that basically links out to installation files so that my university can distribute antivirus program and spyware scanners. One of the links goes out to Windows Updates. It works fine on my computer, but when I burn all of the files to a CD, the code no longer works. Instead, I get this error:

Run-time error '75':
Path/File access error

[OK]

How can I get this code to work on a CD? Any help at all would be appreciated.

The Windows Update code that is run when the entry is clicked:

LaunchInNewwindow "http://www.windowsupdate.com"

And here's the rest of the code:

Option Explicit

    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 Declare Function FindExecutable Lib "shell32.dll" Alias "FindExecutableA" (ByVal lpFile As String, ByVal lpDirectory As String, ByVal lpResult As String) As Long
    Private Declare Function GetDesktopWindow Lib "user32" () As Long

Public Function LaunchInNewwindow(sURL As String) As Boolean
    Const SW_SHOWNORMAL = 1
    Dim lRetVal As Long
    Dim sTemp   As String
    Dim sBrowserExec As String
    
    sBrowserExec = GetBrowserExe        'get the exe
    sURL = AddHTTP(sURL)

    lRetVal = ShellExecute(GetDesktopWindow(), "open", sBrowserExec, sURL, sTemp, SW_SHOWNORMAL)
'    lRetVal = ShellExecute(frm.hWnd, "open", sURL, "", sTemp, SW_SHOWNORMAL)           '1998/07/31 This works as well
    If lRetVal > 32 Then            ' OK
        LaunchInNewwindow = True
    End If
End Function


Private Function AddHTTP(sURL As String) As String
' 2004/12/16 Function added by Larry Rebich using the DELL8500 while in Fort McDowell, AZ
' 2004/12/16 Add http:// is none
    Dim sTemp As String
    
    sTemp = sURL
    If InStr(LCase$(sTemp), "https://") = 1 Then
        AddHTTP = sTemp
    ElseIf InStr(LCase$(sTemp), "http://") = 1 Then
        AddHTTP = sTemp
    Else
        AddHTTP = "http://" & sTemp
    End If

End Function

Public Function GetBrowserExe() As String
    Dim sFilename   As String
    Dim sBrowserExec As String * 255
    Dim lRetVal     As Long
    Dim iFN         As Integer
    Dim sTemp       As String
    
    sBrowserExec = Space(255)
    sFilename = App.Path & "\temphtm.HTM"
    
    iFN = FreeFile()                    ' Get unused file number
    
    Open sFilename For Output As #iFN   ' Create temp HTML file
    Print #iFN, "<HTML> <\HTML>"        ' Output text
    Close #iFN                          ' Close file
    
    ' Then find the application associated with it.
    lRetVal = FindExecutable(sFilename, sTemp, sBrowserExec)
    ' If an application return the name
    If lRetVal <= 32 Or IsEmpty(sBrowserExec) Then ' Error
    Else
        GetBrowserExe = Trim$(sBrowserExec)
    End If
    Kill sFilename  ' delete temp HTML file

End Function

I'm affraid you're trying to create a HTM file on the CD filesystem (R/O, you know).

It's a strange way to find the default web browser**. However, take present ShellExecute() can find it itself (same for other file formats), so it's safe to use a plain:

ShellExecute GetDesktopWindow(), vbNullString, "http://www.windowsupdate.com", vbNullString, vbNullString, SW_SHOWNORMAL

**Next time, if you want to create a temp file, use the functions GetTempPath() and GetTempFileName(). ;)

commented: Good Response +1

Sure is, plus this aids in clarity of code. I understood your code, but In my opinion it's a lot easier to read without a ton of API calls. GetTemp's are great also, for getting the temporary path on any machine. Let us know how it turns out.

Ah... well, when I look at the code, I think I can see what you're talking about. I have to admit, I am *very* new to object-oriented programming.

The code I was using I found via Google. *hangs his head in shame*

I've removed all of that other code and replaced it with the GetDesktopWindow function and used the code you posted for the click commands. It's working fine.

Now, the only question I have is "how do I get it to open a new window instead of using the current open browser?"

Thank you for all of your help. I really appreciate it. Just having code that will work on a CD is great enough. :)

Now, the only question I have is "how do I get it to open a new window instead of using the current open browser?"

Well, not sure how to do that with ShellExecute. IE has a command line parameter, "-new" that allows you to open a document in a new window. However, we cannot pass parameters when using default actions in ShellExecute. That would mean the full path to the IE executable is required, so the GetBrowserExe function should be rightly implemented. But maybe there's no need to worry about it.

There's another method you can use instead of ShellExecute. You can control more of the IE window you launch. This is IE Automation:

Dim objIE As Object
    Set objIE = CreateObject("InternetExplorer.Application")
    With objIE
        .Navigate "http://www.windowsupdate.com"
        .Visible = True
    End With
    Set objIE = Nothing

Take a look here for more info.

This method does not rely on the fact that IE will be the default browser on your target PCs, but if not, it will be used anyways. Don't forget that.

Thank you very much. This was precisely what I was looking for. With a little bit of code added in to minimize the form after the browser is open, everything is perfect.

I really appreciate all the help I've received. You guys are great. :cheesy:

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.