' create-shortcut.vbs Option Explicit Dim oWS, fso, oLink Dim linkFile, target, workDir, iconLoc Dim ext, ts Set oWS = WScript.CreateObject("WScript.Shell") Set fso = CreateObject("Scripting.FileSystemObject") ' Read arguments safely linkFile = WScript.Arguments(0) If WScript.Arguments.Count > 1 Then target = WScript.Arguments(1) Else target = "" If WScript.Arguments.Count > 2 Then workDir = WScript.Arguments(2) Else workDir = "" If WScript.Arguments.Count > 3 Then iconLoc = WScript.Arguments(3) Else iconLoc = "" ' Ensure parent directory exists Dim parent parent = fso.GetParentFolderName(linkFile) If parent <> "" And Not fso.FolderExists(parent) Then fso.CreateFolder(parent) End If ' Always create a .link shortut Set oLink = oWS.CreateShortcut(linkFile) ' If target looks like a URL, launch it via explorer.exe If LCase(Left(target, 4)) = "http" Then oLink.TargetPath = "explorer.exe" oLink.Arguments = target Else oLink.TargetPath = target End If If workDir <> "" Then oLink.WorkingDirectory = workDir End If If iconLoc <> "" Then oLink.IconLocation = iconLoc End If oLink.Save