Technorati Tags: 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 OFFsetlocalenabledelayedexpansionNETFILE 1>nul 2>NULif‘%ERRORLEVEL% ' = = ' 0 ' (Goto START)Else(GotoGetprivileges): Getprivilegesif‘%1' = = ' Elev ' (Goto START)Set"Batchpath=%~f0"Set"Batchargs=elev"::Add quotes to the batch path, if neededSet"Script=%0"SetScript=%script: "=%if '%0 ' = = '!script! ' (GOTO pathquotesdone) Set"Batchpath=" "%batchpath%" "" ":P Athquotesdone::add Quotes to the arguments, if needed.:argloopif '%1 ' = = ' (goto endargloop) Else (goto Addarg) : Addarg Set"Arg=%1"Set Arg=%arg:"=% IF‘%1' = = '!arg! ' (GOTONoquotes)Set"Batchargs=%batchargs%"%1""GOTOQuotesdone: Noquotes Set"Batchargs=%batchargs%%1": Quotesdone Shift GOTOArgloop: Endargloop::Create and run the VB script to elevate the batch fileECHO SetUAC = createobject^ ("shell.application" ^) > "%temp%\oegetprivileges.vbs"ECHOUac. 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 directoryIF‘%1' = = ' Elev ' (Shift/1)CD/D%~dp0::Do your adminy thing ...PsExec. exe-scmd. exe/cdir>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 ' (EchoRequesting administrative privileges ...Gotouacprompt)Else(GotoGotadmin): Uacprompt Echo SetUAC = createobject^ ("shell.application" ^) > "%temp%\getadmin.vbs"Setparams =%*: "=" "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 belowpsexec.exe-s cmd.exe/c dir >d:\output.log 2> Error.log
JAVA "Run as Administrator" "UAC disabled" alternative solution