Date: 02-16-2022
Return to Index
created by gbSnippets
'Compilable Example: (Jose Includes)
#Compiler PBWin 10
#Compile Exe
#Dim All
%Unicode = 1
#Include "win32api.inc"
#Include "wshom.inc" 'Jose include, also loads scrrun.inc
'#Include "scrrun.inc" 'Jose include, also loads scrrun.inc
Enum Equates Singular
IDC_Button
End Enum
Global hDlg As Dword
Function PBMain() As Long
Dialog New Pixels, 0, "PowerBASIC",300,300,200,200, %WS_OverlappedWindow To hDlg
Control Add Button, hDlg, %IDC_Button,"Push", 50,10,100,20
Dialog Show Modal hDlg Call DlgProc
End Function
CallBack Function DlgProc() As Long
Select Case Cb.Msg
Case %WM_Command
Select Case Cb.Ctl
Case %IDC_Button
CreateDesktopShortCut
End Select
End Select
End Function
Sub CreateDesktopShortCut
'create instance of WSH
Local pWsh As IWshShell, pLnk As IWshShortcut
pWsh = NewCom "WScript.Shell"
'info to use in the shortcut
Local targetFolder,targetExe,workingFolder,targetLNK As String
Local sDesktop,comment As WString, sPath As WStringZ * %Max_Path
targetFolder = Exe.Path$ 'folder where EXE resides
targetEXE = Exe.Full$ 'full path of EXE
workingFolder = Exe.Path$ 'current directory assigned to EXE process on startup
comment = "My New Shortcut" 'comment for Properties dialog
SHGetFolderPath(0, %CSIDL_DeskTop, 0, 0, sPath) 'sPath contains Desktop folder (AsciiZ)
targetLNK = sPath + "\" + Exe.Name$ + ".lnk" 'where LNK will reside
'edit content of shortcut, then save
pLnk = pWsh.CreateShortcut(targetLNK) 'uses existing, if already exists
pLnk.Description = comment 'comment for Properties dialog
pLnk.WorkingDirectory = workingFolder 'current directory assigned to EXE process on startup
pLnk.IconLocation = targetEXE + " ,0" 'file containing icon, and index of icon (0 is first icon)
pLnk.RelativePath = Exe.Path$
pLnk.TargetPath = targetEXE 'EXE full path
pLnk.WindowStyle = %WshNormalFocus 'window style of EXE on startup
pLnk.Save
End Sub
'gbs_01202
'Date: 05-11-2013
http://www.garybeene.com/sw/gbsnippets.htm