dkp*_*dkp 9 java scheduler access-denied windows-vista
当我尝试通过Java ProcessBuilder类在任务调度程序中创建新任务时,我得到一个访问被拒绝错误的Windows Vista.在XP上它工作得很好.
当我使用"Run as adminstrator"选项时,它也可以在Vista上运行.
然而,这是一个额外的步骤,用户可能不知道这一点.当用户只需双击应用程序图标时,它将失败并拒绝访问.我的问题是如何在启动后立即强制java应用程序重新获取管理员权限?
fre*_*uch 24
您是否考虑过使用launch4j在.exe中包装Java应用程序?通过执行此操作,您可以嵌入清单文件,该文件允许您指定可执行文件的"执行级别".换句话说,您可以控制应该授予正在运行的应用程序的权限,从而有效地告诉操作系统"以管理员身份运行",而无需用户手动执行此操作.
例如...
build.xml文件:
<target name="wrapMyApp" depends="myapp.jar">
<launch4j configFile="myappConfig.xml" />
</target>
Run Code Online (Sandbox Code Playgroud)
myappConfig.xml:
<launch4jConfig>
<dontWrapJar>false</dontWrapJar>
<headerType>gui</headerType>
<jar>bin\myapp.jar</jar>
<outfile>bin\myapp.exe</outfile>
<priority>normal</priority>
<downloadUrl>http://java.com/download</downloadUrl>
<customProcName>true</customProcName>
<stayAlive>false</stayAlive>
<manifest>myapp.manifest</manifest>
<jre>
<path></path>
<minVersion>1.5.0</minVersion>
<maxVersion></maxVersion>
<jdkPreference>preferJre</jdkPreference>
</jre>
</launch4jConfig>
Run Code Online (Sandbox Code Playgroud)
myapp.manifest:
<?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>
Run Code Online (Sandbox Code Playgroud)
有关模式详细信息,请参阅http://msdn.microsoft.com/en-us/library/bb756929.aspx和launch4j网站.
我不确定你是否可以通过编程来完成它。如果您有应用程序的安装程序,则可以添加注册表项以强制以管理员身份运行:
路径: HKEY_CURRENT_USER\Software\Microsoft\Windows NT\Currentversion\Appcompatflags\layers
键:<< exe 的完整路径>>
值:RUNASADMIN
类型:REG_SZ