Windows shortcut for a symbolic link to an executable file

I am going to use the problem that I am facing with a Java application to explain my question as an example, but this question has nothing to do with Java.

I am using Windows 7 (64-bit) and I want to create a Start menu shortcut to run a Java GUI application. Starting with Java 8, the installer places NTFS symbolic links in a known location that points to a release-specific directory (for example, to change frequently):

C:\>where javaw C:\ProgramData\Oracle\Java\javapath\javaw.exe C:\>dir C:\ProgramData\Oracle\Java\javapath\javaw.exe Volume in drive C is OS Volume Serial Number is D4DC-33AF Directory of C:\ProgramData\Oracle\Java\javapath 05/03/2015 15:40 <SYMLINK> javaw.exe [C:\Program Files\Java\jre1.8.0_40\bin\javaw.exe] 

I created a shortcut whose target command line was C: \ ProgramData \ Oracle \ Java \ javapath \ javaw.exe java_app.jar, but when I started it, Windows says that the javaw.exe path does not exist. I can successfully run the same command line in the "Start Windows" dialog box; just not from the shortcut. Can anyone suggest a solution? (I prefer not to create a batch file to run the command, as this will create a useless console console.)

(NB You can also see the same problem without using Java. Just create a symbolic link to Notepad.exe (using the MKLINK command), and then try to create a shortcut for the symbolic link.)

+5
source share
2 answers

You can still make a useless batch file. Use CALL to close the console window immediately after starting your application.

Also, not on a Windows computer right now, but can you create a shortcut for CMD.exe instead and transfer your command there? You can do this with CALL if a console window appears.

0
source

This simple launcher can be useful; you can create one or more shortcuts for it with the same command line options that you would use in the javaw.exe shortcut.

 #include <Windows.h> void NoCRTMain(void) { wchar_t * cmdline = GetCommandLineW(); STARTUPINFO si; PROCESS_INFORMATION pi; GetStartupInfo(&si); if (!CreateProcess(L"C:\\ProgramData\\Oracle\\Java\\javapath\\javaw.exe", cmdline, NULL, NULL, FALSE, 0, NULL, NULL, &si, &pi)) { MessageBox(NULL, L"Unable to launch Java.", L"runjava.exe", MB_OK); } ExitProcess(0); } 

To compile in Visual Studio, you will need to change some project parameters:

  • Buffer Security Checking for C / C ++ Code Missing
  • Ignore all libraries by default Yes in linker input
  • NoCRTMain entry point in Linker Advanced
  • / DYNAMICBASE: NO and / FIXED: YES as described here

(Or you can change the main function from NoCRTMain to WinMain, but then you need to set the C runtime or link it statically.)

Obviously, you can easily change the code to run symbolic links other than javaw.exe, although some programs may not like the fact that argv[0] does not point to its own executable file for the application.

0
source

Source: https://habr.com/ru/post/1214852/


All Articles