im very new to batch building, my batch file needs to create some directories and folders on a USB stick, but it must do it with admin rights for a program that i will be running further on in the code. when i run it without admin rights, it creates the dirs and file just fine. I then delete the newly created dirs and files and run the batch in admin mode and it comes up with errors saying that all the subdirectories and files already exist. what am i doing wrong?
Code: Select all
@ECHO OFF
GOTO init
REM *******************************
REM ********* initialise *********
REM *******************************
:init
REM Setup time and date functions used for log file.
FOR %%A IN (%Date%) DO SET current_date=%%A
SET current_time=%Time%
REM Setup key directories.
SET evidence_results=Extractor_results
SET memory_results=%evidence_results%\memory
SET image_results=%evidence_results%\images
SET errors=%evidence_results%\errors
SET extractor_log=%evidence_results%\extractor_log
REM Create Directory structure to hold results, errors and logs.
MKDIR %evidence_results%
MKDIR %memory_results%
MKDIR %image_results%
MKDIR %errors%
MKDIR %extractor_log%
REM Create and append log file.
ECHO %date% %time% : log started > %evidence_results%\extractor.log
REM check whether user is running batch file as Administrator.
>nul 2>&1 "%SYSTEMROOT%\system32\cacls.exe" "%SYSTEMROOT%\system32\config\system"&&(
ECHO admin...
)
....rest of code.
thanks for your help!
Loz.