find the path of my application installed in regis

2019-03-05 10:19发布

Im using the innosetup to install my program java, the installer will generated the key run. I want to get the path of installation

Line of innosetup:

Root: HKLM; 
Subkey: "Software\Microsoft\Windows\CurrentVersion\Run"; 
ValueType: string; 
ValueName: "Mi_Programak"; 
ValueData: "{app}\esperoo.exe";"

The class will called to file but I need the path of installation, how I get the path of installation finding in the registry with the name of my application?

1条回答
欢心
2楼-- · 2019-03-05 10:47

I don't know if there is a built-in registry key for the installed program folder, but you can always create your own. You have the installer script create the registry key during installation, using {app} as the placeholder for the registry value.

Reading from any arbitrary key in the Windows registry from Java can be done with some trickery, but to keep to standard JDK classes and documented features, it's best to use the standard Preferences interface. Preferences under the system root get placed as keys under HKLM\Software\JavaSoft\Prefs\. Bear in mind there is some strangeness with upper-case letters - each uppercase letter is prefixed with a slash, so keep the name of the key lowercase. e.g. installdir rather than InstallDir.

In summary: to find the installation directory, add a registry key under Software\Java\Prefs to the installer script and you can use the system root of java.util.Preferences to retrieve the value at runtime.

查看更多
登录 后发表回答