News:

MASM32 SDK Description, downloads and other helpful links
MASM32.com New Forum Link
masmforum WebSite

Making shortcuts (.lnk)?

Started by Nordwind64, January 21, 2006, 02:43:29 PM

Previous topic - Next topic

Nordwind64

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
Greetings, Nordwind.
Windows 7 (64Bit), JWASM/PoLink

PBrennick

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
The GeneSys Project is available from:
The Repository or My crappy website

sluggy

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?

Nordwind64

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
Greetings, Nordwind.
Windows 7 (64Bit), JWASM/PoLink

PBrennick

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


The GeneSys Project is available from:
The Repository or My crappy website

Vortex

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

Vortex

Edgar's website is down, here is files.lib coded by Edgar Hansen.

[attachment deleted by admin]

MichaelW

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

eschew obfuscation

PBrennick

Guys,
The problem here is NOT creating the LNK file but in adding it to the startup folder.

Paul
The GeneSys Project is available from:
The Repository or My crappy website

tenkey

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?
A programming language is low level when its programs require attention to the irrelevant.
Alan Perlis, Epigram #8

MichaelW

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.

eschew obfuscation

zooba

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

MichaelW

QuoteNo no no...  Don't EVER use hardcoded paths like that

Not even for a quick and dirty test??


eschew obfuscation

Nordwind64

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
Greetings, Nordwind.
Windows 7 (64Bit), JWASM/PoLink

P1

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