JAVA "Run as Administrator" "UAC disabled" alternative solution

Source: Internet
Author: User
Tags goto

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.