Run batch file rename a folder as administrator!

Page 1 of 3 123 LastLast

  1. Posts : 6,021
    Win 7 HP SP1 64-bit Vista HB SP2 32-bit Linux Mint 18.3
       #1

    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 Computer


  2. Posts : 3,787
    win 8 32 bit
       #2
      My Computer


  3. Posts : 2,798
    Windows 7 x64, Vista x64, 8.1 smartphone
       #3

    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 Computer


  4. Posts : 6,021
    Win 7 HP SP1 64-bit Vista HB SP2 32-bit Linux Mint 18.3
    Thread Starter
       #4

    Thanks for the replies samuria and iko22,

    iko22 said:
    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 Computer


  5. Posts : 3,787
    win 8 32 bit
       #5

    If you use the runasin the script as post 2 it should work
      My Computer


  6. Posts : 6,021
    Win 7 HP SP1 64-bit Vista HB SP2 32-bit Linux Mint 18.3
    Thread Starter
       #6

    Hi samuria,

    samuria said:
    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 Computer


  7. Posts : 2,798
    Windows 7 x64, Vista x64, 8.1 smartphone
       #7

    Cannot tell where it has fallen over, because you have Echo Off in your example output screen.
      My Computer


  8. Posts : 6,021
    Win 7 HP SP1 64-bit Vista HB SP2 32-bit Linux Mint 18.3
    Thread Starter
       #8

    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 Computer


  9. Posts : 2,798
    Windows 7 x64, Vista x64, 8.1 smartphone
       #9

    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 Computer


  10. Posts : 6,021
    Win 7 HP SP1 64-bit Vista HB SP2 32-bit Linux Mint 18.3
    Thread Starter
       #10

    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 Computer


 
Page 1 of 3 123 LastLast

  Related Discussions
Our Sites
Site Links
About 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 07:56.
Find Us