Technorati 标签: psexec,run as administrator,UAC

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

old script :

http://stackoverflow.com/questions/1894967/how-to-request-administrator-access-inside-a-batch-file

update script:

http://stackoverflow.com/questions/7044985/how-can-i-auto-elevate-my-batch-file-so-that-it-requests-from-uac-administrator/28467343#28467343

@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的更多相关文章

  1. 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 ...

  2. java Run to Line

    在运行Java代码时, 选择运行  Run AS java ,  出现    java Run to Line, 是因为程序还在运行,没有停止.在控制,点击右键.terminate  结束,在Run ...

  3. java.security.cert.CertificateException: No subject alternative names present

    背景:在开发一个项目中,要调用一个webservice服务,之前设置的是http协议,项目中采用jdk自带的wsimport工具生成的客户端代码; 后来,需求变更要求兼容https协议的webserv ...

  4. Tomcat – java.lang.OutOfMemoryError: PermGen space Cause and Solution

    Read more: http://javarevisited.blogspot.com/2012/01/tomcat-javalangoutofmemoryerror-permgen.html#ix ...

  5. Java实现 蓝桥杯 算法训练 Pollution Solution

    试题 算法训练 Pollution Solution 问题描述 作为水污染管理部门的一名雇员,你需要监控那些被有意无意倒入河流.湖泊和海洋的污染物.你的其中一项工作就是估计污染物对不同的水生态系统(珊 ...

  6. eclipse的maven项目,如何使用java run main函数

    项目使用maven管理,一般说来就使用jetty:run了.但是对于做功能测试和集成测试的用例,需要使用自定义的quickrun来运行进行测试环境的参数设定和功能隔离,google一番发现maven有 ...

  7. java run()方法无法throws 异常

    感谢大佬:https://blog.csdn.net/z_ssyy/article/details/95345205 其实原因很简单,run()方法是我们调用start()方法后,jvm再去调用run ...

  8. java.security.cert.CertificateException: No subject alternative names matching IP address xxx.xxx.xxx.xxx found

    https与http不同的是,https加密,需要验证证书,而http不需要. 在连接的代码中加上: static { disableSslVerification(); } private stat ...

  9. install root certificate failed, Please run as administrator/root/sudo

    在钥匙窜中导入  证书就可以了

随机推荐

  1. 专题:initramfs & dracut

    Initramfs An initramfs (initial ram file system) is used by Linux systems to prepare the system duri ...

  2. MSSERVER创建链接服务器

    exec sp_addlinkedserver 'DB_RASS','','SQLOLEDB','127.0.0.1' ' exec sp_serveroption 'DB_RASS','rpc ou ...

  3. SQL多行转多列

    --★转换结果如上图 1.首先创建表: CREATE TABLE [成绩表]( ,) NOT NULL, )NULL, , )NULL, , )NULL, , )NULL ) ON [PRIMARY] ...

  4. webpack与gulp的区别及实例搭建

    webpack是什么,提到这个概念,很多人可能立马说出来,模块化加载器兼打包工具,可以把各种资源都作为模块来使用和处理等等. 说到前端构建工具,不可避免的会提到gulp,到底webpack和gulp有 ...

  5. 利用Access-Control-Allow-Origin响应头解决跨域请求

    //允许任何域名访问 header("Access-Control-Allow-Origin: *"); //指定域名允许跨域 header("Access-Contro ...

  6. redis-cli 命令总结

    redis-cli 命令总结 Redis提供了丰富的命令(command)对数据库和各种数据类型进行操作,这些command可以在Linux终端使用.在编程时,比如使用Redis 的Java语言包,这 ...

  7. jquery给input域赋值和取值

    参考: http://blog.csdn.net/happymagic/article/details/8707117

  8. QSS总结以及最近做的Qt项目

    什么是QSS QSS称为Qt Style Sheets也就是Qt样式表,它是Qt提供的一种用来自定义控件外观的机制.QSS大量参考了CSS的内容,只不过QSS的功能比CSS要弱很多,体现在选择器要少, ...

  9. Dynamic CRM 2013学习笔记(二十六)报表设计:Reporting Service报表 动态参数、参数多选全选、动态列、动态显示行字体颜色

    上次介绍过CRM里开始报表的一些注意事项:Dynamic CRM 2013学习笔记(十五)报表入门.开发工具及注意事项,本文继续介绍报表里的一些动态效果:动态显示参数,参数是从数据库里查询出来的:参数 ...

  10. Asp.Net Web API 2第六课——Web API路由和动作选择

    Asp.Net Web API 导航 Asp.Net Web API第一课——入门http://www.cnblogs.com/aehyok/p/3432158.html Asp.Net Web AP ...