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. Hadoop中HDFS的管理

    本文讲述怎么在Linux Shell中对HDFS进行操作. 三种命令格式: hadoop fs适用于任何不同的文件系统,比如本地文件系统和HDFS文件系统 hadoop dfs只能适用于HDFS文件系 ...

  2. andorid lint

    (一)Lint简介 Android SDK提供了一个代码扫描工具,称为lint.可以帮助您轻松地识别并纠正问题与结构质量的代码,不必执行应用程序或编写任何测试用例.每个问题检测到该工具报告的一个描述消 ...

  3. ActiveMQ学习笔记

    关键接口和类: ConnectionFactory connectionFactory;//连接工厂 Connection connection;//连接 Session session; Desti ...

  4. 泛型,存放N张图片

    (* ************************************************* 1.里面放多张图片,用文件名作为索引 2.线程在背后从硬盘加载到内存 3.批量加载 4.加载完 ...

  5. python通过ip获取地址

    # -*- coding: utf-8 -*- url = "http://ip.taobao.com/service/getIpInfo.php?ip=" #查找IP地址 def ...

  6. Dynamic CRM 2013学习笔记(二十)字段改变事件的二种实现方法

    CRM里有二种方式实现字段change事件,一种是在form里,一种完全通过js来实现.本文介绍下二者的用途及区别. 1. Form里用法 这种方式估计其实也是添加一个js的function. 这种方 ...

  7. Windows2003 架设VPN服务

    一.确保Windows防火墙关闭. 在我的电脑上右键=>管理,在左边窗口找到“服务和应用程序”,展开,单击“服务”,在右边窗口中找到“Windows Firewall/Internet Conn ...

  8. 敏捷开发 与 Scrum

    敏捷开发以用户的需求进化为核心,采用迭代.循序渐进的方法进行软件开发.在敏捷开发中,软件项目在构建初期被切分成多个子项目,各个子项目的成果都经过测试,具备可视.可集成和可运行使用的特征.换言之,就是把 ...

  9. [.NET 即时通信SignalR] 认识SignalR (一)

    ASP .NET SignalR[1] 是一个ASP .NET 下的类库,可以在ASP .NET 的Web项目中实现实时通信.什么是实时通信的Web呢?就是让客户端(Web页面)和服务器端可以互相通知 ...

  10. Xperf Analysis Basics(转)

      FQ不易,转载 http://randomascii.wordpress.com/2011/08/23/xperf-analysis-basics/ I started writing a des ...