Windows 7 Forums
Welcome to Windows 7 Forums. Our forum is dedicated to helping you find support and solutions for any problems regarding your Windows 7 PC be it Dell, HP, Acer, Asus or a custom build. We also provide an extensive Windows 7 tutorial section that covers a wide range of tips and tricks.


Windows 7: Run batch file rename a folder as administrator!

17 Apr 2019   #1
Paul Black

[1] Win 7 HP SP1 64-bit [2] Vista HB SP2 32-bit [3] Linux Mint 18.3
 
 
Run batch file rename a folder as administrator!

I am trying to rename the CBS [C:\Windows\Logs\CBS] folder to CBS_OLD but got an Access Denied error.
I have tried numerous combinations of commands but to no avail and Google has been no help!
Is there an easy way [probably not] to run commands as an Administrator from within a batch file please?
I am not interested in running from the command line or right-clicking and Run as administrator.

This is the latest code I have...

Code:
@echo off
echo.
net stop wuauserv
rem net stop bits
takeown /f %systemroot%\Logs\CBS /r /d y
ICACLS %systemroot% /grant %username%:F /T
rename %systemroot%\Logs\CBS %systemroot%\Logs\CBS_OLD
net start wuauserv
pause
Here is the current output...

Run batch file rename a folder as administrator!-rename.jpg

Thanks in advance.




My System SpecsSystem Spec
.
17 Apr 2019   #2
samuria

win 8 32 bit
 
 

My System SpecsSystem Spec
17 Apr 2019   #3
iko22

Windows 7 x64, Vista x64, 8.1 smartphone
 
 

takeown gives ownership to the current user, rather than the administrator, until you include the /a switch as a parameter to the takeown command. Depends on if that is what you want to do.
My System SpecsSystem Spec
.

17 Apr 2019   #4
Paul Black

[1] Win 7 HP SP1 64-bit [2] Vista HB SP2 32-bit [3] Linux Mint 18.3
 
 

Thanks for the replies samuria and iko22,

Quote   Quote: Originally Posted by iko22 View Post
takeown gives ownership to the current user, rather than the administrator, until you include the /a switch as a parameter to the takeown command. Depends on if that is what you want to do.
I have got a small menu driven batch file. I have administrator rights so for me there is not a problem. I would like the batch commands to run as administrator for those who are normal users. i.e. changing the CBS [C:\Windows\Logs\CBS] folder to CBS_OLD etc, if possible!

Thanks in adcance.
My System SpecsSystem Spec
17 Apr 2019   #5
samuria

win 8 32 bit
 
 

If you use the runasin the script as post 2 it should work
My System SpecsSystem Spec
17 Apr 2019   #6
Paul Black

[1] Win 7 HP SP1 64-bit [2] Vista HB SP2 32-bit [3] Linux Mint 18.3
 
 

Hi samuria,

Quote   Quote: Originally Posted by samuria View Post
If you use the runas in the script as post 2 it should work.
That will not run within the code though. I want to be able to achieve this from within the script!
My System SpecsSystem Spec
17 Apr 2019   #7
iko22

Windows 7 x64, Vista x64, 8.1 smartphone
 
 

Cannot tell where it has fallen over, because you have Echo Off in your example output screen.
My System SpecsSystem Spec
17 Apr 2019   #8
Paul Black

[1] Win 7 HP SP1 64-bit [2] Vista HB SP2 32-bit [3] Linux Mint 18.3
 
 

Here is an amended screen shot without @echo off...

Run batch file rename a folder as administrator!-scr_1.jpg

The thing is I think this is wrong because I need it to be set as Administrator and to run as Administrator!

Thanks in advance.


My System SpecsSystem Spec
17 Apr 2019   #9
iko22

Windows 7 x64, Vista x64, 8.1 smartphone
 
 

Then correct the iCACLS command line with a runas, as Samuria suggested. For Example: RUNAS /profile /user:system-admin-pc\system-admin "ICACLS %systemroot% /grant %username%:F /T"

Does that get you what you want, if you replace that line in the script?
My System SpecsSystem Spec
17 Apr 2019   #10
Paul Black

[1] Win 7 HP SP1 64-bit [2] Vista HB SP2 32-bit [3] Linux Mint 18.3
 
 

Thanks again iko22,

This is not critical BTW and is not networked!

The idea behind this is I want to upload a batch file that members can use. It has a menu. I want them to be able to run the menu items. i.e. If they wanted to run SFC, then I thought it would be a good idea to rename the CBS folder to CBS_OLD first for example. I just wondered if there was an easy way to get the code to run with administrator rights.

Thanks.
My System SpecsSystem Spec
Reply

 Run batch file rename a folder as administrator!




Thread Tools




Similar help and support threads
Thread Forum
mass/batch file rename rollback?
Hey all, Last night i renamed a bunch of files. Is there a way to undo all of that? the changes i made last night were pretty much 36327780_p0_master1200 >>> 36327780_p0 system restore doesn't restore files and documents, so that one's a dead end...
General Discussion
Batch File on USB fails when Ran As Administrator
I am new to this site so please excuse any lack of etiquette I may show. I have recently built a .bat files to perform a large number of configuration changes needed for a Win7 or Win8 workstation to function properly on my network. The .bat file obviously needs to be ran with elevated...
Software
Batch File that grabs file names from folder to insert into batch file
Ok I'm totally at a loss on how to word this so I'm just going to write it out the best that I can... :confused: First I have a batch file that I'm writing that will convert mp4 files to mp3 files (I have a lot) for a buddies band using ffmpeg. Here's the code that I'm using: ffmpeg -i...
General Discussion
Batch file or Exe to copy & rename directory and update files
I require a batch file or free utility that i can redistribute from my web site to other users, (gamers) that will copy the contents of a directory inside their game to a new location and re-name the directory at the same time. Something like this; Copy "Genesis\Vehicles\truck\diesel\4tonbaker"...
General Discussion
How to always run batch file as administrator?
I've made a batch file, but i don't know how to make it to always run as administartor. In .bat's file properties the option "always run as administartor" is grayed out. I have to right click it and then choose "run as administartor" from context menu. But i don't want to do it every time because...
General Discussion


Our Sites

Site Links

About Us

Find Us

Windows 7 Forums is an independent web site and has not been authorized, sponsored, or otherwise approved by Microsoft Corporation. "Windows 7" and related materials are trademarks of Microsoft Corp.

Designer Media Ltd

All times are GMT -5. The time now is 14:04.
Twitter Facebook