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.
source share