Forked from anonymous/LicenseManager.launch4j.xml
Last active
December 10, 2015 19:18
-
-
Save seraphy/4480424 to your computer and use it in GitHub Desktop.
Javaアプリケーション上でUACによる特権昇格が必要な処理を行う方法
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Javaアプリケーション上でUACによる特権昇格が必要な処理を行う場合、 | |
1) 特権が必要な処理を別のjarに切りだし、 | |
2) launch4jなどで | |
"requestedExecutionLevel = highestAvailable" or (← 自分の特権を有効化) | |
"requestedExecutionLevel = requireAdministrator" (← 常に管理者を要求) | |
なマニフェストをもつexeファイルとする。 | |
3) アプリケーション側より、それを Desktop.open()メソッドで呼び出す. | |
※ UAC昇格にはShellExecute系APIによるexeの呼び出しが必要なため。 | |
※ CreateProcess系では不可 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<launch4jConfig> | |
<dontWrapJar>false</dontWrapJar> | |
<headerType>gui</headerType> | |
<jar>dist\LicenseManager.jar</jar> | |
<outfile>LicenseManager.exe</outfile> | |
<errTitle></errTitle> | |
<cmdLine></cmdLine> | |
<chdir></chdir> | |
<priority>normal</priority> | |
<downloadUrl>http://java.com/download</downloadUrl> | |
<supportUrl></supportUrl> | |
<customProcName>true</customProcName> | |
<stayAlive>false</stayAlive> | |
<manifest>LicenseManager.manifest</manifest> | |
<icon></icon> | |
<classPath> | |
<mainClass>example.LicenseManagerApp</mainClass> | |
<cp>lib/LicenseLib.jar</cp> | |
</classPath> | |
<jre> | |
<path></path> | |
<minVersion>1.6.0</minVersion> | |
<maxVersion></maxVersion> | |
<jdkPreference>preferJre</jdkPreference> | |
<initialHeapSize>128</initialHeapSize> | |
<maxHeapSize>128</maxHeapSize> | |
</jre> | |
<versionInfo> | |
<fileVersion>1.0.0.0</fileVersion> | |
<txtFileVersion>LicenseManager</txtFileVersion> | |
<fileDescription>EXAMPLE LICENSE MANAGER</fileDescription> | |
<copyright>seraphyware</copyright> | |
<productVersion>1.0.0.0</productVersion> | |
<txtProductVersion>LicenseManager</txtProductVersion> | |
<productName>LICENSE MANAGER</productName> | |
<companyName>seraphyware</companyName> | |
<internalName>LicenseManager</internalName> | |
<originalFilename>LicenseManager.exe</originalFilename> | |
</versionInfo> | |
</launch4jConfig> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?xml version="1.0" encoding="UTF-8" standalone="yes"?> | |
<assembly xmlns="urn:schemas-microsoft-com:asm.v1" manifestVersion="1.0"> | |
<trustInfo xmlns="urn:schemas-microsoft-com:asm.v3"> | |
<security> | |
<requestedPrivileges> | |
<requestedExecutionLevel level="highestAvailable" | |
uiAccess="False" /> | |
</requestedPrivileges> | |
</security> | |
</trustInfo> | |
</assembly> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* ライセンスマネージャを起動する.<br> | |
* | |
* @throws IOException 失敗 | |
* @throws URISyntaxException 失敗 | |
*/ | |
public void openLicManager() throws IOException, URISyntaxException { | |
// 自ディレクトリを検出する. | |
CodeSource cs = getClass().getProtectionDomain().getCodeSource(); | |
URL location = cs.getLocation(); | |
if (!"file".equals(location.getProtocol())) { | |
throw new IOException("unsupported protocol. " + location.toExternalForm()); | |
} | |
File baseDir = new File(location.toURI().getPath()); | |
if (baseDir.isFile()) { | |
// *.jarなどの場合は、その親に設定する. | |
baseDir = baseDir.getParentFile(); | |
} | |
// ライセンスマネージャのexeまでのパス | |
// (自ディレクトリと同じところにexeがあるものとする.) | |
File licMrg = new File(baseDir, LICENSEMANAGER_EXE); | |
// UACの昇格のためには、ShellExecute系のAPIである必要があるため、 | |
// Desktop#open()を用いてexeを開く. | |
Desktop desktop = Desktop.getDesktop(); | |
desktop.open(licMrg); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment