' Instantiate needed components Dim fso, shell, shellApplication Set fso = WScript.CreateObject("Scripting.FileSystemObject") Set shell = WScript.CreateObject("WScript.Shell") Set shellApplication = WScript.CreateObject("Shell.Application")
' Locate where NetworkLocations are stored Dim nethoodFolderPath, networkLocationFolder, networkLocationFolderPath nethoodFolderPath = shellApplication.Namespace( ssfNETHOOD ).Self.Path
' Create the folder for our NetworkLocation and set its attributes networkLocationFolderPath = fso.BuildPath( nethoodFolderPath, networkLocationName ) If fso.FolderExists( networkLocationFolderPath ) Then ExitFunction EndIf Set networkLocationFolder = fso.CreateFolder( networkLocationFolderPath ) networkLocationFolder.Attributes = fsATTRIBUTES_READONLY
' Write the desktop.ini inside our NetworkLocation folder and change its attributes Dim desktopINIFilePath desktopINIFilePath = fso.BuildPath( networkLocationFolderPath, "desktop.ini" ) With fso.CreateTextFile(desktopINIFilePath) .Write "[.ShellClassInfo]" & vbCrlf & _ "CLSID2={0AFACED1-E828-11D1-9187-B532F1E9575D}" & vbCrlf & _ "Flags=2" & vbCrlf .Close EndWith With fso.GetFile( desktopINIFilePath ) .Attributes = fsATTRIBUTES_HIDDEN + fsATTRIBUTES_SYSTEM EndWith
' Create the shortcut to the target of our NetworkLocation Dim targetLink targetLink = fso.BuildPath( networkLocationFolderPath, "target.lnk" ) With shell.CreateShortcut( targetLink ) .TargetPath = networkLocationTarget .Save EndWith