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
在钥匙窜中导入 证书就可以了
随机推荐
- Sql 常见面试题
SQL面试题(1) create table testtable1(id int IDENTITY,department varchar(12) ) select * from testtable1i ...
- servers中添加server时,看不到运行环境的选择。
servers中添加server时,看不到运行环境的选择. 主要原因是tomcat目录中的配置文件格式不对.
- SQL优化笔记—CPU优化
补充:常规服务器动态管理对象包括,下面有些资料可能会应用到 dm_db_*:数据库和数据库对象dm_exec_*:执行用户代码和关联的连接dm_os_*:内存.锁定和时间安排dm_tran_*:事务和 ...
- Model层数据验证
问题1:View层如何向Controller的Action传递Model数据?在View中,可以使用Form表单进行模型数据的提交,同样的,我们需要关联提交数据的类型,则需要在View中使用@mode ...
- struts框架学习过程中的问题
1,错误: java.lang.NullPointerException: Module 'null' not found.错误原因,struts运行需要的.jar文件拷贝不足,应该把它们加入到cla ...
- Eclipse程序员要掌握的常用快捷键
Ctrl+K 光标放在一个变量上(注意,是变量,如果你的光标放在了字符串上,如http://keleyi.com则没有任何作用的),按下Ctrl+K光标会定位到下一个相同的变量 Shift+Ctrl+ ...
- Dynamic CRM 2015学习笔记 系列汇总
这里列出所有 Dynamic CRM 2015学习笔记 系列文章,方便大家查阅.有任何建议.意见.需要,欢迎大家提交评论一起讨论. 本文原文地址:Dynamic CRM 2015学习笔记 系列汇总 一 ...
- Javascript中new Date的坑
在一段判断是否过期的js代码中是这么写的: if (new Date() < new Date(2014, 9, 25)) { //... } 后来发现过了9月25日竟然不过期,console. ...
- 【转】URL的井号
去年9月,twitter改版. 一个显著变化,就是URL加入了"#!"符号.比如,改版前的用户主页网址为 http://twitter.com/username 改版后,就变成了 ...
- 新手容易混乱的String+和StringBuffer,以及Java的方法参数传递方式。
之前在交流群里和猿友们讨论string+和stringbuffer哪个速度快以及Java的方法参数传递的问题,引起了群里猿友的小讨论.最终LZ得出的结果是string+没有stringbuffer快, ...