' Shortcut.vbs - Create/edit folder shortcuts
'
' shortcut.vbs [folder [target]]
'
' folder 	The full pathname of the folder shortcut to be created/edited.
'		If not specified, the script will create "New Folder Shortcut" on your desktop.
' target 	The full pathname or URL of the folder shortcut target.
'		If not specified, the script will prompt for the target URL.
'
' Notes:
' - To quickly convert an existing folder to a folder shortcut, just drag-and-drop it on this script file.
' After that, you cannot anymore access the files and subfolders of the folder with Windows Explorer
' or standard Windows Open/Save dialogs. However, you can still access them their full pathnames!
' - To change the icon that this script sets for the folder shortcut, you need to modify the script below.
'
' Copyright (c) 2007 PanuWorld - Free to modify and/or distribute if the original source is credited.
	 

on error resume next

set WshShell = WScript.CreateObject("WScript.Shell")
dir = WshShell.SpecialFolders("Desktop") & "\New Folder Shortcut"	' Default name
dir = WScript.Arguments(0)
url = WScript.Arguments(1)

if url = "" then 
	url = inputbox("Enter target URL/path for the folder shortcut:" & vbCr & vbCr & dir, _
		"New Folder Shortcut", "http://www.panuworld.net/")
end if

if url <> "" then

	' Create the folder which will be converted to a Folder Shortcut
	set FsoFileSystem = CreateObject("Scripting.FileSystemObject")
	set oFolder = FsoFileSystem.GetFolder(dir)	' If already exists
	set oFolder = FsoFileSystem.CreateFolder(dir)	' If a new folder

	' Create the Desktop.ini of a Folder Shortcut in the folder
	set oFile = oFolder.CreateTextFile("Desktop.ini", true)
	oFile.WriteLine("[.ShellClassInfo]")
	oFile.WriteLine("CLSID2={0AFACED1-E828-11D1-9187-B532F1E9575D}")
	oFile.WriteLine("Flags=2")
	oFile.WriteLine("ConfirmFileOp=0")
	oFile.Close()

	' Create the target.lnk to the target in the folder
	set oShellLink = WshShell.CreateShortcut(oFolder.Path & "\target.lnk")
	oShellLink.TargetPath = url
	oShellLink.IconLocation = "shell32.dll, 103"
	oShellLink.Description = url
	oShellLink.Save

	' Convert the folder to a Folder Shortcut
	OFolder.Attributes = 1

end if

