I need to run a batch file (setup.bat) which will call another batch file (make_dir.bat) which will create a folder in the "C:\Program Files" directory. This is for an internal installer. All the users will be logged in with their user names but will have local administrator rights. I've tried two approaches but neither work.
Approach 1:
SET PRGFILES=%programfiles%\mySoftware
SET admin=N
SET domain=%USERDOMAIN%\
IF /i "%domain%" EQU "%computername%\" set domain=
SET user=%domain%%username%
FOR /f "Tokens=*" %%a IN ('net localgroup administrators^|find /i "%user%"') DO SET admin=Y
IF "%admin%"=="Y" (
MD "%PRGFILES%"
)
This says Access is denied
Approach 2:
runas /user:%Username% shell\make_dir.bat
where make_dir.bat is
md "%programfiles%\mySoftware"
This asks for the current username and password but somehow fails after that. I have checked that all users have local admin rights and can manually create a folder in their programfiles
folder.
Thanks for the help.
I use such script to run .bat file as administrator, using JScript: