vatbub/mslinks


Java library for parsing and creating Windows shortcut files (.lnk)

Download


Step 1. Add the JitPack repository to your build file

Add it in your root settings.gradle at the end of repositories:

	dependencyResolutionManagement {
		repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS)
		repositories {
			mavenCentral()
			maven { url 'https://jitpack.io' }
		}
	}

Add it in your settings.gradle.kts at the end of repositories:

	dependencyResolutionManagement {
		repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS)
		repositories {
			mavenCentral()
			maven { url = uri("https://jitpack.io") }
		}
	}

Add to pom.xml

	<repositories>
		<repository>
		    <id>jitpack.io</id>
		    <url>https://jitpack.io</url>
		</repository>
	</repositories>

Add it in your build.sbt at the end of resolvers:

 
    resolvers += "jitpack" at "https://jitpack.io"
        
    

Add it in your project.clj at the end of repositories:

 
    :repositories [["jitpack" "https://jitpack.io"]]
        
    

Step 2. Add the dependency

	dependencies {
		implementation 'com.github.vatbub:mslinks:mslinks-1.0.6.2'
	}
	dependencies {
		implementation("com.github.vatbub:mslinks:mslinks-1.0.6.2")
	}
	<dependency>
	    <groupId>com.github.vatbub</groupId>
	    <artifactId>mslinks</artifactId>
	    <version>mslinks-1.0.6.2</version>
	</dependency>

                            
    libraryDependencies += "com.github.vatbub" % "mslinks" % "mslinks-1.0.6.2"
        
        

                            
    :dependencies [[com.github.vatbub/mslinks "mslinks-1.0.6.2"]]
        
        

Readme


mslinks

Library for parsing and creating Windows shortcut files (.lnk)


This is a exact fork of BlackOverlord666/mslinks, however, I published it on maven central:

Java 10

<dependency>
	<groupId>com.github.vatbub</groupId>
	<artifactId>mslinks</artifactId>
	<version>1.0.6.2</version>
</dependency>

Java 1.7

<dependency>
	<groupId>com.github.vatbub</groupId>
	<artifactId>mslinks</artifactId>
	<version>1.0.5.1</version>
</dependency>

PLEASE NOTE that this fork is not under active developement anymore. Please post any feature requests and bugs at BlackOverlord666/mslinks.


Partial implementation of Shell Link (.LNK) Binary File Format

You can edit most properties of the link such as working directory, tooltip text, icon, command line arguments, hotkeys, create links to LAN shared files and directories but followed features are not implemented:

  • extra data blocks: Darwin, IconEnvironment, KnownFolder, PropertyStore, Shim, SpecialFolder
  • most options in LinkTargetIDList because it not documented, only key parts for resolving links are implemented, others are zero stub
  • you can use environment variables in target path but they are resolved at creation time and not stored in the lnk file

Easiest way to create link with default parameters: ShellLink.createLink("targetfile", "linkfile.lnk")

Next sample demonstrates creating link for .bat file with setting working directory, icon and tune font parameters for console

package mslinks;

import java.io.IOException;

public class Main {
	public static void main(String[] args) throws IOException {
		ShellLink sl = ShellLink.createLink("pause.bat")
			.setWorkingDir("..")
			.setIconLocation("%SystemRoot%\\system32\\SHELL32.dll");
		sl.getHeader().setIconIndex(128);
		sl.getConsoleData()
			.setFont(mslinks.extra.ConsoleData.Font.Consolas)
			.setFontSize(24)
			.setTextColor(5);
				
		sl.saveTo("testlink.lnk");
		System.out.println(sl.getWorkingDir());
		System.out.println(sl.resolveTarget());
	}
}

Final example creates recursive link that blocks explorer on Windows 7 while trying to get into the containing directory :D

package mslinks;

import java.io.IOException;

public class Main {
	public static void main(String[] args) throws IOException {
		ShellLink sl = ShellLink.createLink("test.lnk");
		sl.getHeader().getLinkFlags().setAllowLinkToLink();
		sl.saveTo("test.lnk");
	}
}