JAVA “Run as administrator” “UAC disabled” alternative solution
java.io.IOException: Cannot run program "psexec.exe": CreateProcess error=740, The requested operation requires elevation
at java.lang.ProcessBuilder.start(Unknown Source)
at java.lang.Runtime.exec(Unknown Source)
at java.lang.Runtime.exec(Unknown Source)
at java.lang.Runtime.exec(Unknown Source)
at com.gdn.BuildHostNow.main(BuildHostNow.java:14)
Caused by: java.io.IOException: CreateProcess error=740, The requested operation requires elevation
http://stackoverflow.com/questions/1894967/how-to-request-administrator-access-inside-a-batch-file
update script:
@ECHO OFF
setlocal EnableDelayedExpansion NET FILE 1>NUL 2>NUL
if '%errorlevel%' == '0' ( goto START ) else ( goto getPrivileges ) :getPrivileges
if '%1'=='ELEV' ( goto START ) set "batchPath=%~f0"
set "batchArgs=ELEV" ::Add quotes to the batch path, if needed
set "script=%0"
set script=%script:"=%
IF '%0'=='!script!' ( GOTO PathQuotesDone )
set "batchPath=""%batchPath%"""
:PathQuotesDone ::Add quotes to the arguments, if needed.
:ArgLoop
IF '%1'=='' ( GOTO EndArgLoop ) else ( GOTO AddArg )
:AddArg
set "arg=%1"
set arg=%arg:"=%
IF '%1'=='!arg!' ( GOTO NoQuotes )
set "batchArgs=%batchArgs% "%1""
GOTO QuotesDone
:NoQuotes
set "batchArgs=%batchArgs% %1"
:QuotesDone
shift
GOTO ArgLoop
:EndArgLoop ::Create and run the vb script to elevate the batch file
ECHO Set UAC = CreateObject^("Shell.Application"^) > "%temp%\OEgetPrivileges.vbs"
ECHO UAC.ShellExecute "cmd", "/c ""!batchPath! !batchArgs!""", "", "runas", 1 >> "%temp%\OEgetPrivileges.vbs"
"%temp%\OEgetPrivileges.vbs"
exit /B :START
::Remove the elevation tag and set the correct working directory
IF '%1'=='ELEV' ( shift /1 )
cd /d %~dp0 ::Do your adminy thing here... psexec.exe -s cmd.exe /c dir >d:\output2.log 2>error2.log
@echo off :: BatchGotAdmin
:-------------------------------------
REM --> Check for permissions
>nul 2>&1 "%SYSTEMROOT%\system32\cacls.exe" "%SYSTEMROOT%\system32\config\system" REM --> If error flag set, we do not have admin.
if '%errorlevel%' NEQ '0' (
echo Requesting administrative privileges...
goto UACPrompt
) else ( goto gotAdmin ) :UACPrompt
echo Set UAC = CreateObject^("Shell.Application"^) > "%temp%\getadmin.vbs"
set params = %*:"=""
echo UAC.ShellExecute "cmd.exe", "/c %~s0 %params%", "", "runas", 1 >> "%temp%\getadmin.vbs" "%temp%\getadmin.vbs"
del "%temp%\getadmin.vbs"
exit /B :gotAdmin
pushd "%CD%"
CD /D "%~dp0"
:--------------------------------------put your command below psexec.exe -s cmd.exe /c dir >d:\output.log 2>error.log
JAVA “Run as administrator” “UAC disabled” alternative solution的更多相关文章
- How do I force my .NET application to run as administrator?
How do I force my .NET application to run as administrator? You'll want to modify the manifest that ...
- java Run to Line
在运行Java代码时, 选择运行 Run AS java , 出现 java Run to Line, 是因为程序还在运行,没有停止.在控制,点击右键.terminate 结束,在Run ...
- java.security.cert.CertificateException: No subject alternative names present
背景:在开发一个项目中,要调用一个webservice服务,之前设置的是http协议,项目中采用jdk自带的wsimport工具生成的客户端代码; 后来,需求变更要求兼容https协议的webserv ...
- Tomcat – java.lang.OutOfMemoryError: PermGen space Cause and Solution
Read more: http://javarevisited.blogspot.com/2012/01/tomcat-javalangoutofmemoryerror-permgen.html#ix ...
- Java实现 蓝桥杯 算法训练 Pollution Solution
试题 算法训练 Pollution Solution 问题描述 作为水污染管理部门的一名雇员,你需要监控那些被有意无意倒入河流.湖泊和海洋的污染物.你的其中一项工作就是估计污染物对不同的水生态系统(珊 ...
- eclipse的maven项目,如何使用java run main函数
项目使用maven管理,一般说来就使用jetty:run了.但是对于做功能测试和集成测试的用例,需要使用自定义的quickrun来运行进行测试环境的参数设定和功能隔离,google一番发现maven有 ...
- java run()方法无法throws 异常
感谢大佬:https://blog.csdn.net/z_ssyy/article/details/95345205 其实原因很简单,run()方法是我们调用start()方法后,jvm再去调用run ...
- java.security.cert.CertificateException: No subject alternative names matching IP address xxx.xxx.xxx.xxx found
https与http不同的是,https加密,需要验证证书,而http不需要. 在连接的代码中加上: static { disableSslVerification(); } private stat ...
- install root certificate failed, Please run as administrator/root/sudo
在钥匙窜中导入 证书就可以了
随机推荐
- python学习之路-day5-模块
本节内容: 模块详解 1.模块定义 2.os&sys模块 3.time&datetime模块 4.random模块 5.shutil模块 6.shelve模块 7.configpars ...
- c#控制IE浏览器自动点击等事件WebBrowser,mshtml.IHTMLDocument2 .
// c#控制IE浏览器自动点击等事件WebBrowser,mshtml.IHTMLDocument2 分类: c# 2013-02-06 15:18 3008人阅读 评论(0) 收藏 举报 可以实现 ...
- iOS遍历程序内某个文件夹下所有文件的属性
项目中有个文件管理系统,在做本地文件管理操作的时候,遇到了遍历本地文件的问题 遍历到的文件有些不需要显示,而且需要得到文件的相关属性,在此总结下. //查找需要遍历文件夹的目录 NSString *k ...
- Windows 打印控件
Windows窗体的PrintDocument组件用于设置一些属性,这些属性说明,在基于Windows的应用程序中要打印说明内容以及打印文档的能力,可将它与PrintDialog组件一起使用来控制文档 ...
- 居于集成了adt的Android 开发环境配置
一.先说一下环境 Windows 8.1 64 位 注:win7 Ultimate 64 配置会出现 Android SDK manger 不能启动的问题,是因为android.bat 里调用了fi ...
- 调用数据库函数CallableStatement
- delphi 生成网卡MAC地址
生成MAC地址的小工具: {*------------------------------------------------ 生成mac地址 @author @version 2015.7.2 20 ...
- struts2的运行原理及配置文件
struts2官方运行原理图: 1,客户发送请求(url地址就是请求),tomcat接到请求会找到相应的应用web.xml配置文件. 2,web.xml中filter拦截器把你的请求接收到,并进入Fi ...
- js与cookie的domain和path之间的关系
1.前言 使用javascript操作cookie我们都经常使用,对cookie不是很了解的话可以看下这篇帖子[javascript操作cookie](http://www.cnblogs.com/D ...
- 记录ASP.NET Web API 服务接口响应时间
实现起来很简单,一个Filter就可以搞定!!! /// <summary> /// 监控接口执行时间 /// </summary> public class TimingAc ...