Skip to content

Instantly share code, notes, and snippets.

Created January 8, 2013 01:51
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save anonymous/4480388 to your computer and use it in GitHub Desktop.
Save anonymous/4480388 to your computer and use it in GitHub Desktop.
Javaアプリケーション上でUACによる特権昇格が必要な処理を行う方法
Javaアプリケーション上でUACによる特権昇格が必要な処理を行う場合、
1) 特権が必要な処理を別のjarに切りだし、
2) launch4jなどで
"requestedExecutionLevel = highestAvailable"
なマニフェストをもつexeファイルとする。
3) アプリケーション側より、それを Desktop.open()メソッドで呼び出す.
 ※ UAC昇格にはShellExecute系APIによるexeの呼び出しが必要なため。
 ※ CreateProcess系では不可
<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>
<?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>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment