Hi,
I want to create a shortcut/linkfile (.lnk) from my program to autostart-drawer. What's the best way to do that?
Best regards,
Nordwind64
There does not appear to be any 'automated' way to do that. I 'guess' that you would need to move the application to that folder, I can see no other way.
Paul
Quote from: Nordwind64 on January 21, 2006, 02:43:29 PM
from my program to autostart-drawer. What's the best way to do that?
Can you explain more? What is "autostart-drawer"? Are you trying to get your app executed at system startup time?
Hello,
QuoteAre you trying to get your app executed at system startup time?
Yes. I wanted to generate an .lnk file to the Windows folder "autostart".
But now I go the way via registry.
@PBrennik: I read about an way via OLE. But could not get it working.
Thanks!
Nordwind64
Sluggy,
The problem, here, is he wants to do it via a .lnk file instead of a .exe file, I think. Running a .exe at startup is easier. A .lnk, I don't think you can except through some fancy and complicated footwork as he just said.
By the way: The OLE solution he talks about creates an exe so why not just add the exe he 'really' wants to start to the startup list?
Paul
Edgar Hansen's files.lib static library provides some functions to create shotcuts. Here is one of them below :
CreateSpecialFolderLink:
This is a wrapper function for CreateLink that creates a link in a special folder
It works the same as CreateLink except that the path is not supplied with lpLinkName
Parameters:
lpLinkTarget = Pointer to the fully qualified path of the link target
lpLinkName = Pointer to a name for the link file
lpDescription = A description to add to the link, can be NULL
csidl = The class ID of the special folder
see the following url for a list of possible values :
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/shellcc/platform/shell/reference/enums/csidl.asp
The first icon in the file is used for the link icon
The extension .LNK is added to lpLinkName automatically
If lpDescription is NULL, no description will be added
CoInitialize must be called at some point in your program before this function
Returns 0 if successful
Tested GoAsm & MASM
Edgar's website is down, here is files.lib coded by Edgar Hansen.
[attachment deleted by admin]
There is a related example by Ernest Murphy in \masm32\com\examples\shortcut. To make it build on my system I had to edit the file \masm32\com\include\shlobj.inc changing the line:
includelib shell32.lib
To
includelib \masm32\lib\shell32.lib
Guys,
The problem here is NOT creating the LNK file but in adding it to the startup folder.
Paul
The only autostart folders on NT systems that I currently use are the the Startup folders in the Documents and Settings tree. The programs are activated on login. There is one Startup folder for each account, and there is one for "All Users". As far as I can tell, they are just ordinary directories which you can reach using the CD command in the Command Prompt.
Is there an earlier autostart?
Copying a shortcut to the startup folder should be no problem. This (tested) example uses the shortcut created by Ernest Murphy's shortcut (makelink.asm) example:
; «««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««
include \masm32\include\masm32rt.inc
fcopy MACRO existingFileName,newFileName,boolFailIfExists
invoke CopyFile,reparg(existingFileName),
reparg(newFileName),
boolFailIfExists
EXITM <eax>
ENDM
; «««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««
.data
destname db "\Documents and Settings\All Users\Start Menu\"
db "Programs\Startup\"
filename db "Shortcut to MakeLink.lnk",0
.code
; «««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««
start:
; «««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««
.if fcopy(ADDR filename, ADDR destname, TRUE) == 0
print "copy failed",13,10
.endif
inkey "Press any key to exit..."
exit
; «««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««
end start
BTW, the specified startup folder on my system contains a very normal looking shortcut that works no problem.
No no no... Don't EVER use hardcoded paths like that :wink
invoke SHGetSpecialFolderPath, 0, ADDR szBuffer, CSIDL_STARTUP, 0
This will return the folder you want on any system running IE 4.0 or later (and Win98 onwards all come with IE 4.0) :U
QuoteNo no no... Don't EVER use hardcoded paths like that
Not even for a quick and dirty test??
Hi.
QuoteSHGetSpecialFolderPath
Yes, that's the best way. Here's my code to find the actual user autostart folder:
.386
.model flat, stdcall
option casemap :none
include \masm32\include\windows.inc
include \masm32\include\user32.inc
include \masm32\include\kernel32.inc
include \masm32\include\shell32.inc
include \masm32\include\ole32.inc
includelib \masm32\lib\user32.lib
includelib \masm32\lib\kernel32.lib
includelib \masm32\lib\shell32.lib
includelib \masm32\lib\ole32.lib
.data?
buffer db 256 dup(?)
.data
var dd 0
text db "User's autostart folder is in:"
.code
start:
invoke SHGetSpecialFolderLocation, 0, CSIDL_STARTUP, addr var
.if eax==0
invoke SHGetPathFromIDList, var, addr buffer
.if eax!=0
invoke MessageBox,0, addr buffer ,addr text,MB_OK
.endif
invoke CoTaskMemFree,var
.endif
invoke ExitProcess,0
end start
Moving exe's to autostart folder sucks, if exe needs dll's, text's or so on. Windows will start them, two.
Best regards,
Nordwind64
If you delete the .lnk file from the Startup folder, you have not deleted you application. And you have recourse to put back the .lnk file.
On top of that, most users would expect a .lnk file in the Startup folder.
Regards, P1
Quote from: MichaelW on January 22, 2006, 12:55:24 PM
QuoteNo no no... Don't EVER use hardcoded paths like that
Not even for a quick and dirty test??
Mmm... yeah, okay. Just this once :wink :U
As long as you put a disclaimer with your code. Quick and dirty examples often get cut-pasted into release code :'( ::)
Quote from: zooba on January 23, 2006, 04:31:43 AM
As long as you put a disclaimer with your code. Quick and dirty examples often get cut-pasted into release code :'( ::)
Suggestion:
;***** DIRTY!! *** DIRTY!! *** THIS CODE IS DIRTY!! *** DIRTY!! *** DIRTY!! *****