0

im new to batch files and im trying to write a file which gets admin rights and copies a file. This is the code I found for getting admin rights, but it seems that it is not working for Windows 8;

@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"
:--------------------------------------
<my code>

Then i´ve tried to write code for copying the files which didnt work neither:

xcopy "%1" "%2"
xcopy "%3" "%4"

echo "succesfull"
j0h4nn3s
  • 2,016
  • 2
  • 20
  • 35

1 Answers1

0

Try getting rid of "%temp%" throughout the script, I tried the same code under windows 8, but I keep getting access denied errors until I edit every line that accesses the systems temp folder.

Oniisaki
  • 21
  • 1