Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 997139
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T06:59:06+00:00 2026-05-16T06:59:06+00:00

I have an executable on my disk-on-key in dir\program\prog.exe I’d like to have a

  • 0

I have an executable on my disk-on-key in dir\program\prog.exe
I’d like to have a shortcut to the executable on the DoK’s root directory, that is, prog.lnk would refer to dir\program\prog.exe.

However, it seems that prog.lnk can’t have a relative target. This is a problem when the DoK will have different drive letters assigned to it, depending on which PC it’s connected to.

Any suggestions, aside from the obvious one of putting prog.exe in the root dir?

(ultimately, I’d like to do this at install time using nsis)

Thanks,

Rony

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-16T06:59:07+00:00Added an answer on May 16, 2026 at 6:59 am

    While it is possible for shortcuts to contain a relative path to the target (.lnk files have a flag called SLDF_HAS_RELPATH) NSIS does not support creating anything other than “normal” shortcuts so you need to write the binary data directly (The .lnk format is pretty stable and has been documented by MS)

    !macro FileWriteHexBytes h b
    push ${h}
    push ${b}
    call FileWriteHexBytes
    !macroend
    Function FileWriteHexBytes
    exch $9
    exch
    exch $0
    push $1
    push $2
    loop:
        StrCpy $2 $9 2
        StrLen $1 $2
        IntCmp $1 2 0 end
        FileWriteByte $0 "0x$2"
        StrCpy $9 $9 "" 2
        goto loop
    end:
    pop $2
    pop $1
    pop $0
    pop $9
    FunctionEnd
    
    
    Function CreateRelativeLnk
    exch $9
    exch
    exch $0
    push $1
    FileOpen $0 "$0" w
    StrCmp $0 "" clean
    !insertmacro FileWriteHexBytes $0 "4C0000000114020000000000C000000000000046"
    !insertmacro FileWriteHexBytes $0 48010400 ;flags
    !insertmacro FileWriteHexBytes $0 00000000000000000000000000000000000000000000000000000000000000000000000001000000000000000000000000000000
    
    StrLen $1 $9 ;must be < 255!
    FileWriteByte $0 $1
    FileWriteByte $0 0
    FileWrite $0 "$9" ;relative target path
    
    !if 0
    ;The icon is problematic, does not seem like it works with relative paths (but you can use system icons...)
    StrCpy $9 "explorer.exe"
    StrLen $1 $9
    FileWriteByte $0 $1
    FileWriteByte $0 0
    FileWrite $0 "$9"
    !else
    !insertmacro FileWriteHexBytes $0 05003e2e657865 ;fake default .exe icon
    !endif
    
    clean:
    FileClose $0
    pop $1
    pop $0
    pop $9
    FunctionEnd
    

    Call it like this:

    push "$temp\testlink.lnk"
    push "testdir\testapp.exe" ;full path to this is $temp\testdir\testapp.exe
    call CreateRelativeLnk
    

    While the generated .lnk seems to work, I’m not sure if I would use this in production code

    A much better solution is to create a little NSIS app like Oleg suggests (NSIS applications can contain embedded data at the end of the .exe that it can read from itself at runtime etc..)

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have an executable that is started by a windows service, this program will
i have a command line executable program that accepts a configuration file as it's
I have an executable that depending on the command line switch supplied looks something
I have an executable module created by third party. I would like to inject
I have an executable that defaults to 32-bit. It doesn't have source code and
I want to have an executable file that will call some other programs. The
I have a setup executable that I need to install. When I run it,
I have a non-.Net executable file that is included in my .net assembly as
I have a png file on disk at compile time. I'd like to have
I'd like to simulate a file without writing it on disk. I have a

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.