Adrianvdh Posted March 25, 2013 Posted March 25, 2013 Hello everyone I am running this batch file and it was working great (I am admin on my pc) and then it throws me an error saying access denied when I trying to write to a text file on my Desktop? echo My program started!>>%userprofile%\Desktop\textfile.txt Here are my permissions: P.S is ther like a .reg file out there that can help me with my problem?
ianymaty Posted March 25, 2013 Posted March 25, 2013 You may be the admin but you need to run the .bat as admin. Put this in the batch at the top to get admin privs :: Get ADMIN Privs:-------------------------------------mkdir "%windir%\BatchGotAdmin"if '%errorlevel%' == '0' ( rmdir "%windir%\BatchGotAdmin" & goto gotAdmin) else ( goto UACPrompt ) :UACPrompt echo Set UAC = CreateObject^("Shell.Application"^) > "%temp%\getadmin.vbs" echo UAC.ShellExecute %0, "", "", "runas", 1 >> "%temp%\getadmin.vbs" "%temp%\getadmin.vbs" exit /B :gotAdmin if exist "%temp%\getadmin.vbs" ( del "%temp%\getadmin.vbs" ) pushd "%CD%" CD /D "%~dp0":-------------------------------------:: End Get ADMIN Privs
Adrianvdh Posted March 25, 2013 Author Posted March 25, 2013 (edited) Ya that doesnt work or mine... @echo off set tempdir=%windir%\fixUAC if not exist %tempdir% md %tempdir% REG QUERY "HKU\S-1-5-19" >NUL 2>&1 && ( goto ADMIN ) || ( echo.RUN ME AS ADMINISTRATOR ping localhost -n 3 >nul exit ) :ADMIN echo [My program started]>>%userprofile%\program.log|findstr /i "Access Denied.">nul>nul IF %ERRORLEVEL% EQU 0 goto mainmenu ) else ( cls color c echo ACCESS DENIED - Writting to log file... ping localhost -n 2 >nul echo Fixing you UAC settings ping localhost -n 3 >nul color b goto fixUAC cls ) :fixUAC cd %tempdir% echo Set UAC = CreateObject^("Shell.Application"^) >>%tempdir%\fixUAC.vbs|findstr /i "Access Denied.">nul>nul IF %ERRORLEVEL% EQU 0 ( goto next ) else ( goto error1 ) :next echo UAC.ShellExecute %0, "", "", "runas", 1 >>%tempdir%\fixUAC.vbs|findstr /i "Access Denied.">nul>nul IF %ERRORLEVEL% EQU 0 ( "%tempdir%\fixUAC.vbs" goto mainmenu ) else ( goto error2 ) :error1 cls color c echo ACCESS DENIED - Writting to vbs file... echo with part...1 ping localhost -n 2 >nul echo Can not fix UAC settings ping localhost -n 4 >nul exit :error2 cls color c echo ACCESS DENIED - Writting to vbs file... echo. with part...2 ping localhost -n 2 >nul echo Can not fix UAC settings ping localhost -n 4 >nul exit :mainmenu cls echo Welldone this program has success! ping localhost -n 3 >nul echo Now this part is for the rest of you script... echo. pause exit I can md a folder but can write to it at all. My script throws the "ACCESS DENIED - Writting to vbs file..." error Or this .vbs script.. Set UAC = CreateObject^("Shell.Application"^) UAC.ShellExecute %0, "", "", "runas", 1 Edited March 25, 2013 by Adrianvdh
ianymaty Posted March 25, 2013 Posted March 25, 2013 Sorry, I can't help more. I know nothing about script. I just found that on the net and use it for simple tasks to elevate a cmd. It does what I need. Don't know more.
LIGHTNING UK! Posted March 25, 2013 Posted March 25, 2013 That line in your first post works fine for me. I don't use UAC though.
Adrianvdh Posted March 26, 2013 Author Posted March 26, 2013 Me Adrianvdh the REG QUERY "HKU\S-1-5-19" >NUL 2>&1 && ( goto ADMIN ) || ( echo.RUN ME AS ADMINISTRATOR ping localhost -n 3 >nul exit )
Recommended Posts