Advantages of COM approach are obvious - it's possible to change any field (I took most popular only)
Don't forget that in LnkName it's possible to use only letters, allowed for file names.
Don't forget that in LnkName it's possible to use only letters, allowed for file names.
Code:
' Based on Florent Heyworth's PB code and MSDN #Compile Exe #Dim All #Register None #Include "Win32Api.Inc" Declare Function CoInitialize Lib "ole32.dll" Alias "CoInitialize" _ (ByVal pvReserved As Dword) As Dword Declare Function CoCreateInstance Lib "ole32.dll" Alias "CoCreateInstance" _ (rclsid As String * 16, ByVal pUnkOuter As Any, ByVal dwClsContext As Dword, _ riid As String * 16, ppv As Dword) As Dword Declare Sub CoUninitialize Lib "ole32.dll" Alias "CoUninitialize" Declare Sub CoTaskMemFree Lib "ole32.dll" Alias "CoTaskMemFree" (pv As Dword) Declare Function Sub1 (p1 As Any) As Dword Declare Function Sub2 (p1 As Any, p2 As Any) As Dword Declare Function Sub3 (p1 As Any, p2 As Any, p3 As Any) As Dword Sub CreateLink (ByVal CSIDL As Long, LnkName As Asciiz, _ ExePath As Asciiz, Arguments As Asciiz, WorkDir As Asciiz, _ ByVal ShowCmd As Dword, Comment As Asciiz) Local TmpAsciiz As Asciiz * %MAX_PATH, TmpWide As Asciiz * (2 * %MAX_PATH) Local psl As Dword Ptr, ppf As Dword Ptr, pp As Dword Ptr, lResult As Dword Local CLSID_ShellLink As String * 16, IID_IShellLink As String * 16, _ CLSCTX_INPROC_SERVER As Dword, IID_Persist As String * 16 CLSID_ShellLink = Mkl$(&H00021401) + Chr$(0, 0, 0, 0, &HC0, 0, 0, 0, 0, 0, 0, &H46) IID_IShellLink = Mkl$(&H000214EE) + Chr$(0, 0, 0, 0, &HC0, 0, 0, 0, 0, 0, 0, &H46) IID_Persist = Mkl$(&H0000010B) + Chr$(0, 0, 0, 0, &HC0, 0, 0, 0, 0, 0, 0, &H46) CLSCTX_INPROC_SERVER = 1 CoInitialize %Null If IsFalse(CoCreateInstance (CLSID_ShellLink, %Null, CLSCTX_INPROC_SERVER, IID_IShellLink, psl)) Then pp = @psl + 80: Call Dword @pp Using Sub2 (ByVal psl, ExePath) pp = @psl + 44: Call Dword @pp Using Sub2 (ByVal psl, Arguments) pp = @psl + 36: Call Dword @pp Using Sub2 (ByVal psl, WorkDir) pp = @psl + 60: Call Dword @pp Using Sub2 (ByVal psl, ByVal ShowCmd) pp = @psl + 28: Call Dword @pp Using Sub2 (ByVal psl, Comment) pp = @psl: Call Dword @pp Using Sub3 (ByVal psl, IID_Persist, ppf) To lResult If lResult = 0 Then Dim pidl As Dword TmpAsciiz = CurDir$ If IsFalse(SHGetSpecialFolderLocation(ByVal %HWND_DESKTOP, ByVal CSIDL, ByVal VarPtr(pidl))) Then SHGetPathFromIDList ByVal pidl, TmpAsciiz CoTaskMemFree ByVal pidl End If TmpAsciiz = TmpAsciiz + "\" + LnkName + ".Lnk" MultiByteToWideChar %CP_ACP, 0, TmpAsciiz, -1, TmpWide, %MAX_PATH pp = @ppf + 24: Call Dword @pp Using Sub3 (ByVal ppf, TmpWide, ByVal %True) pp = @ppf + 8: Call Dword @pp Using Sub1 (ByVal ppf) End If pp = @psl + 8: Call Dword @pp Using Sub1 (ByVal psl) End If CoUninitialize End Sub Function PbMain CreateLink %CSIDL_DESKTOP, "PB shortcut", "D:\Ltr.00\Bas32\Ltr32.Exe", _ "My Arguments", "D:\Ltr.00\Bas32", %SW_MAXIMIZE, "My comment" MsgBox "See Desktop" End Function
Comment