You should handle that:
- The user desktop folder location can be changed
- The desktop a user sees is a virtual view of more than one folder in the filesystem. Directly searching for the folder inside the user desktop will leave out the desktop folder configured for all the users.
So, it is better to ask the OS to retrieve the required information
Option Explicit
' folder in desktop and file in folder
Const FOLDER_NAME = "Folder"
Const FILE_NAME = "myhtml.html"
Dim oFolder
Const ssfDESKTOP = &H00&
' Retrieve a reference to the virtual desktop view and try to retrieve a reference
' to the folder we are searching for
With WScript.CreateObject("Shell.Application").Namespace( ssfDESKTOP )
Set oFolder = .ParseName(FOLDER_NAME)
End With
' If we don't have a folder reference, leave with an error
If oFolder Is Nothing Then
WScript.Echo "ERROR - Folder not found in desktop"
WScript.Quit 1
End If
Dim strFolderPath, strFilePath
' Retrieve the file system path of the requested folder
strFolderPath = oFolder.Path
' Search the required file and leave with an error if it can not be found
With WScript.CreateObject("Scripting.FileSystemObject")
strFilePath = .BuildPath( strFolderPath, FILE_NAME )
If Not .FileExists( strFilePath ) Then
WScript.Echo "ERROR - File not found in desktop folder"
WScript.Quit 1
End If
End With
' We have a valid file reference, navigate to it
With WScript.CreateObject("InternetExplorer.Application")
.statusBar = False
.menubar = False
.toolbar = False
.visible = True
.navigate2 strFilePath
End With
You can find more information on shell scriptable objects here