Post by xxgeek on Apr 7, 2024 23:30:15 GMT
A GUI for creating shortcuts to the 'Desktop', the 'Start Menu', the 'Send To' folder, and the 'Startup' folder
- Defaults to creating the shortcut on the Desktop
- Default name of the shortcut is the name of the target file selected by the user with the first character of the name capitalized and the file extension removed. User can change before creating the shortcut to any name.
- Buttons are provided to access the Folders where the shortcuts are placed in case users want to delete them later.
- Defaults to creating the shortcut on the Desktop
- Default name of the shortcut is the name of the target file selected by the user with the first character of the name capitalized and the file extension removed. User can change before creating the shortcut to any name.
- Buttons are provided to access the Folders where the shortcuts are placed in case users want to delete them later.
'Make Shortcuts using VB Script
'by xxgeek
'v1.0 Nov 2023
' Editted April 2024
'v1.1
'added a GUI and 3 "Special Folders" destination options
'More "Special Folders" you can use this code for
' https://www.winhelponline.com/blog/shell-commands-to-access-the-special-folders/
'this example assumes a 3 character file extension
'Save to file before RUN'ning
nomainwin
call getUserPath
global filepath$, shortCutName$, dest$, upath$
deskTop$=upath$;"\Desktop"
startMenu$=upath$;"\AppData\Roaming\Microsoft\Windows\Start Menu"
sendTo$=upath$;"\AppData\Roaming\Microsoft\Windows\SendTo"
startUp$ = upath$;"\AppData\Roaming\Microsoft\Windows\Start Menu\Programs\Startup"
WindowWidth = 360
WindowHeight = 300
UpperLeftX = int((DisplayWidth-WindowWidth)/2)
UpperLeftY = int((DisplayHeight-WindowHeight)/2)
button #1.mkshtct,"&Make Shortcut",[makeShortCut], UL, 130,215,100,35
radiobutton #1.desktop,"Desktop",[desktopSet],[desktopReset],20,85,80,25
radiobutton #1.startmenu,"StartMenu",[startmenuSet],[startmenuReset],100,85,80,25
radiobutton #1.sendto,"Send To",[sendtoSet],[sendtoReset],180,85,80,25
radiobutton #1.startup,"Startup",[startupSet],[startupReset],260,85,80,25
button #1.browse,"Browse",[browse], UL, 20,30,90,25
textbox #1.destPath,120,30,200,25
textbox #1.shName,70,165,200,25
statictext #1.target "Target",20,10,50,15
statictext #1.dest "Destination",20,70,130,15
button #1.dirDesk,"Browse",[desk], UL, 30,110,45,15
button #1.dirStartm,"Browse",[startm], UL, 110,110,45,15
button #1.dirSend,"Browse",[send], UL, 190,110,45,15
button #1.dirStartu,"Browse",[startu], UL, 270,110,45,15
statictext #1.name "Name",30,170,35,15
statictext #1.optional "( Optional )",275,170,55,15
open "Create Shortcuts v1.1" for window_nf as #1
#1 "trapclose [quit]"
dest$="Desktop"
#1.desktop "set"
wait
[browse]
'comment & uncomment next 2 lines - use hard coded filepath$
filedialog "Select File to Create Shorcut on Desktop", DefaultDir$;"\*.*", filepath$
'shortcut to this file will be placed on your desktop
'filepath$ = "Path\to\YourFile.xxx"
#1.destPath filepath$
if filepath$ <> "" then
i = len(filepath$)
while mid$(filepath$, i, 1) <> "\" and mid$(filepath$, i, 1) <> ""
i = i-1
wend
nameOffile$ = mid$(filepath$, i+1)
'name the shortcut (appears as text on shortcut) - assumes extension is . + 3 characters
'Defaults to name of file selected
'prefix the shortcut with - 'Shortcut to'
'shortCutName$ = "Shortcut to ";left$(nameOffile$, len(nameOffile$)-4)
'Don't use "Shortcut to " at beginning of name if desired
shortCutName$ = left$(nameOffile$, len(nameOffile$)-4)
'Capitalize first character of shortcut name
shortCutName$ = q$;upper$(mid$(shortCutName$,1,1));right$(shortCutName$,len(shortCutName$)-1);q$
'Type ANY Custom Text for shortcut name
'shortCutName$ = "WhatEver You Type Here"
#1.shName shortCutName$
else
wait
end if
[makeShortCut]
if shortCutName$ <> "" then
#1.shName "!contents? shortCutName$"
call MDS
end if
wait
[desktopSet]
dest$="Desktop"
wait
[startmenuSet]
dest$="StartMenu"
wait
[sendtoSet]
dest$="SendTo"
wait
[startupSet]
dest$="Startup"
wait
[desk]
run "explorer ";deskTop$
wait
[startm]
run "explorer ";startMenu$
wait
[send]
run "explorer ";sendTo$
wait
[startu]
run "explorer ";startUp$
wait
[quit]
close #1
end
'Make Desktop Shortcut - Using Visual Basic Script
'write/run a short .vbs script to create a desktop shortcut to the selected file
sub MDS
q$=chr$(34)
desktopShortcut$ = "desktopShortcut.vbs"
open desktopShortcut$ for output as #2
#2 "Set Shell = CreateObject(";q$;"WScript.Shell";q$;")"
#2 "DesktopPath = Shell.SpecialFolders(";q$;dest$;q$;")"
#2 "Set link = Shell.CreateShortcut(DesktopPath & ";q$;"\";shortCutName$;".lnk";q$;")"
#2 "link.Description = ";q$;shortCutName$;" ";filepath$;q$
'#2 "link.HotKey = ";q$;"CTRL+ALT+E";q$ 'setup a hotkey Link option
#2 "link.TargetPath = ";q$;filepath$;q$
#2 "link.WindowStyle = 3"
#2 "link.Save"
#2 "Set link = nothing"
#2 "Set Shell = nothing"
close #2
run "wscript ";desktopShortcut$
end sub
'get the users HomePath
sub getUserPath
run "cmd.exe /c echo %userprofile% >UserHomePath.txt", HIDE
do
scan
loop until fileExists(DefaultDir$, "UserHomePath.txt")
open "UserHomePath.txt" for input as #1
upath$ = input$(#1, lof(#1))
close #1
if upath$ = "" then notice "Sorry, can't find user path " : end
kill DefaultDir$;"\UserHomePath.txt"
upath$=trim$(upath$)
end sub
'function for checking file existence
function fileExists(path$, filename$)
dim info$(0, 0)
files path$, filename$, info$()
fileExists = val(info$(0, 0)) 'non zero is true
end function