I just looked at your code again and saw that I forgot to execute the procedure

It does work!

Joakim Christiansen wrote:idle
I just looked at your code again and saw that I forgot to execute the procedure![]()
It does work!
Code: Select all
; German forum: http://robsite.de/php/pureboard/viewtopic.php?t=3078&highlight=
; Author: Danilo
; Date: 09. December 2003
;
; create shell links/shortcuts
; translated from my old example that used CallCOM()
;
; by Danilo, 09.12.2003
; changed for easy use in PB 4.0 >
; by ts-soft
; changed for PB 4.50 and Unicode
EnableExplicit
Macro DEFINE_GUID(Name, l, w1, w2, b1, b2, b3, b4, b5, b6, b7, b8)
CompilerIf Defined(Name, #PB_Variable)
If SizeOf(Name) = SizeOf(GUID)
Name\Data1 = l
Name\Data2 = w1
Name\Data3 = w2
Name\Data4[0] = b1
Name\Data4[1] = b2
Name\Data4[2] = b3
Name\Data4[3] = b4
Name\Data4[4] = b5
Name\Data4[5] = b6
Name\Data4[6] = b7
Name\Data4[7] = b8
Else
Debug "Error - variable not declared as guid"
EndIf
CompilerEndIf
EndMacro
Procedure CreateShortcut(Path.s, Link.s, WorkingDir.s = "", Argument.s = "", ShowCommand.l = #SW_SHOWNORMAL, Description.s = "", HotKey.l = #Null, IconFile.s = "|", IconIndex.l = 0)
Protected psl.IShellLinkW, ppf.IPersistFile, Result
Protected.GUID CLSID_ShellLink, IID_IShellLink, IID_IPersistFile
DEFINE_GUID(CLSID_ShellLink, $00021401, $0000,$0000, $C0, $00, $00, $00, $00, $00, $00, $46) ; {00021401-0000-0000-C000-000000000046}
DEFINE_GUID(IID_IShellLink, $000214F9, $0000,$0000, $C0, $00, $00, $00, $00, $00, $00, $46) ; {000214F9-0000-0000-C000-000000000046}
DEFINE_GUID(IID_IPersistFile, $0000010B, $0000,$0000, $C0, $00, $00, $00, $00, $00, $00, $46); {0000010b-0000-0000-C000-000000000046}
If IconFile = "|" : IconFile = Path : EndIf
If Not WorkingDir : WorkingDir = GetPathPart(Path) : EndIf
CoInitialize_(0)
If CoCreateInstance_(@CLSID_ShellLink, 0, 1, @IID_IShellLink, @psl) = #S_OK
Set_ShellLink_preferences:
psl\SetPath(Path)
psl\SetArguments(Argument)
psl\SetWorkingDirectory(WorkingDir)
psl\SetDescription(DESCRIPTION)
psl\SetShowCmd(ShowCommand)
psl\SetHotkey(HotKey)
psl\SetIconLocation(IconFile, IconIndex)
ShellLink_SAVE:
If psl\QueryInterface(@IID_IPersistFile, @ppf) = #S_OK
ppf\Save(Link, #True)
result = 1
ppf\Release()
EndIf
psl\Release()
EndIf
CoUninitialize_()
ProcedureReturn result
EndProcedure
Procedure.s GetSpecialFolder(CSIDL)
Protected *itemid.ITEMIDLIST
Protected location.s = Space(#MAX_PATH)
If SHGetSpecialFolderLocation_ (0, CSIDL, @*itemid) = #NOERROR
If SHGetPathFromIDList_(*itemid, @location) = #True
If Right(location, 1) <> "\" : location + "\" : EndIf
Else
location = ""
EndIf
CoTaskMemFree_(*itemid)
EndIf
ProcedureReturn location
EndProcedure
Define.s Folder = GetSpecialFolder(#CSIDL_STARTUP)
Debug CreateShortcut("notepad.exe", Folder + "editor.lnk")
Ok, I just checked it again and GetSpecialFolder(#CSIDL_STARTUP) returns nothing on Vista!c4s wrote:I just tried creating a shortcut in #CSIDL_STARTUP (using viewtopic.php?p=349331#p349331) on Vista and it miserably fails. Actually the shortcut was created on the desktop and I really don't know why... however it works just fine on XP.
Yep, just did.LuCiFeR[SD] wrote:have you tried #CSIDL_ALTSTARTUP ?
Hello, I have a problem with this code, it only writes the first 36 out of 74 characters of my software and as a result the software does not start. Is there a solution to make it write all the characters?netmaestro wrote: Sun Mar 20, 2011 3:25 pm This is the method I use, code is by Joakim Christiansen. With this procedure all you need to do is implement a menu item for the user to check or clear "Start with Windows" and run this procedure with the state parameter set to 1 or 0. I use it in several of my programs and it's never given me any problems:
Code: Select all
Procedure StartWithWindows(State.b) ; by Joakim Christiansen Protected Key.l = #HKEY_CURRENT_USER ;or #HKEY_LOCAL_MACHINE for every user on the machine Protected Path.s = "Software\Microsoft\Windows\CurrentVersion\Run" Protected Value.s = "GmailEnhancer" ;Change into the name of your program Protected String.s = Chr(34)+ProgramFilename()+Chr(34) ;Path of your program Protected CurKey.l If State RegCreateKey_(Key,@Path,@CurKey) RegSetValueEx_(CurKey,@Value,0,#REG_SZ,@String,Len(String)) Else RegOpenKey_(Key,@Path,@CurKey) RegDeleteValue_(CurKey,@Value) EndIf RegCloseKey_(CurKey) EndProcedure
In fact, you should use StringByteLength(String) and not len(string).a_carignan wrote: Sat Mar 16, 2024 8:43 pmHello, I have a problem with this code, it only writes the first 36 out of 74 characters of my software and as a result the software does not start. Is there a solution to make it write all the characters?netmaestro wrote: Sun Mar 20, 2011 3:25 pm This is the method I use, code is by Joakim Christiansen. With this procedure all you need to do is implement a menu item for the user to check or clear "Start with Windows" and run this procedure with the state parameter set to 1 or 0. I use it in several of my programs and it's never given me any problems:
Code: Select all
Procedure StartWithWindows(State.b) ; by Joakim Christiansen Protected Key.l = #HKEY_CURRENT_USER ;or #HKEY_LOCAL_MACHINE for every user on the machine Protected Path.s = "Software\Microsoft\Windows\CurrentVersion\Run" Protected Value.s = "GmailEnhancer" ;Change into the name of your program Protected String.s = Chr(34)+ProgramFilename()+Chr(34) ;Path of your program Protected CurKey.l If State RegCreateKey_(Key,@Path,@CurKey) RegSetValueEx_(CurKey,@Value,0,#REG_SZ,@String,Len(String)) Else RegOpenKey_(Key,@Path,@CurKey) RegDeleteValue_(CurKey,@Value) EndIf RegCloseKey_(CurKey) EndProcedure