Post by xxgeek on Nov 8, 2023 16:00:34 GMT
[EDIT] - A new version posted with a GUI In This Thread
The following code is meant more as an example to be used in code to create desktop shortcuts. As is it creates a shortcut to a user selected file on the desktop.
Opens to a filedialog to select a file.
Then a shortcut to that file is placed on the desktop.
The code writes/runs a VB script to create the shortcut.
This is a more versatile adaptation of the script used in BAS2EXE to create the desktop shortcut.
The following code is meant more as an example to be used in code to create desktop shortcuts. As is it creates a shortcut to a user selected file on the desktop.
Opens to a filedialog to select a file.
Then a shortcut to that file is placed on the desktop.
The code writes/runs a VB script to create the shortcut.
This is a more versatile adaptation of the script used in BAS2EXE to create the desktop shortcut.
'Make Desktop Shortcut using VB Script
'by xxgeek
'Nov 2023
'an example to use in code to create desktop shorcuts
nomainwin
filedialog "Select File to Create Shorcut on Desktop", DefaultDir$;"*\*", filepath$
GetFilename$ = GetFilename$(filepath$)
nameOffile$ = GetFilename$
nameOffile$ = left$(GetFilename$, len(GetFilename$)-4)'assumes extension is 3 characters
call MDS
end
'write/run a vbs script to create a desktop shortcut to the selected file
sub MDS
q$=chr$(34)
global filepath$, nameOffile$
desktopShortcut$ = "desktopShortcut.vbs"
open desktopShortcut$ for output as #1
#1 "Set Shell = CreateObject(";q$;"WScript.Shell";q$;")"
#1 "DesktopPath = Shell.SpecialFolders(";q$;"Desktop";q$;")"
#1 "Set link = Shell.CreateShortcut(DesktopPath & ";q$;"\";nameOffile$;".lnk";q$;")"
#1 "link.Description = ";q$;nameOffile$;" shortcut";q$
#1 "link.HotKey = ";q$;"CTRL+ALT+E";q$
#1 "link.TargetPath = ";q$;filepath$;q$
#1 "link.WindowStyle = 3"
#1 "link.Save"
#1 "Set link = nothing"
#1 "Set Shell = nothing"
close #1
run "wscript ";desktopShortcut$
end sub
function GetFilename$(fileName$)
i = len(fileName$)
while mid$(fileName$, i, 1) <> "\" and mid$(fileName$, i, 1) <> ""
i = i-1
wend
GetFilename$ = mid$(fileName$, i+1)
end function