Run batch file rename a folder as administrator!

Page 2 of 3 FirstFirst 123 LastLast

  1. Posts : 3,615
    Win 10 x64, Linux Lite, Win 7 x64, BlackArch, & Kali
       #11

    Paul Black said:
    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.

    You're trying to circumvent win security protocol. Batch file run from guest cmd & elevate guest to admin rights?
    Don't believe that's possible!
    How to open an elevated cmd using command line for Windows ...
    #62 green check


      My Computer


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

    Hi Snick,

    Snick said:
    You're trying to circumvent win security protocol. Batch file run from guest cmd & elevate guest to admin rights?
    Don't believe that's possible!
    How to open an elevated cmd using command line for Windows ...
    #62 green check
    I didn't think it was but I thought I would ask!

    What does #62 green check mean?
      My Computer


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

    Would opening PowerShell from within the batch file and performing the processes [then closing PowerShell] overcome the administrator restrictions?

    I would assume that it doesn't!
      My Computer


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

    No joy? I'd thought you'd have this up and running by now! I did a bit more homework on the two commands, and I tried this on a folder called Demo, and it seems to work perfectly.

    Code:
    RUNAS /profile /user:user1 "iCACLS c:\users\user1\desktop\demo /deny user1:(OI)(CI)F"
    RUNAS /profile /user:user1 "iCACLS c:\users\user1\desktop\demo /grant user1:(OI)(CI)F"
    
    This returns success on mine, so I'd assume it would also work on c:\windows\logs\cbs on your computer. Assume user1 has admin rights.

    I think @Snick is correct, you cannot run an elevated command prompt from a batch file. This example does not attempt to break that restriction.
    Last edited by iko22; 18 Apr 2019 at 04:15. Reason: formatting text
      My Computer


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

    Hi iko22,

    iko22 said:
    No joy? I'd thought you'd have this up and running by now!
    I have had limited time to spend on this for the last couple of days, but I will get around to it this afternoon, hopefully!

    iko22 said:
    I think @Snick is correct, you cannot run an elevated command prompt from a batch file. This example does not attempt to break that restriction.
    That was what I thought, but I wondered if there was a clever workaround, obviously not, which makes sense because it is to keep the integrity of the system secure!

    Thanks again.
      My Computer


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

    Hi iko22,

    iko22 said:
    No joy? I'd thought you'd have this up and running by now! I did a bit more homework on the two commands, and I tried this on a folder called Demo, and it seems to work perfectly.

    Code:
    RUNAS /profile /user:user1 "iCACLS c:\users\user1\desktop\demo /deny user1:(OI)(CI)F"
    RUNAS /profile /user:user1 "iCACLS c:\users\user1\desktop\demo /grant user1:(OI)(CI)F"
    No go I'm afraid!

    Says error with RUNAS and I can't leave the password blank [even though it is not passworded]!

    I will try and have a better look later.
    Last edited by Paul Black; 18 Apr 2019 at 08:00.
      My Computer


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

    UPDATE:

    I ran this...

    Code:
    echo.
    net stop wuauserv
    icacls "c:\windows\logs\cbs" /grant system-admin:(OI)(CI)F /T
    ren c:\windows\Logs\CBS\ c:\windows\Logs\CBS_OLD\
    net start wuauserv
    pause
    ...and got this...

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

    Thanks in advance.
      My Computer


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

    Hello Paul

    THe syntax for the REN statement says you are trying to RENAME the entire folder. DO you not want to rename the CBS.log within the CBS folder?
      My Computer


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

    Hi iko22,

    iko22 said:
    The syntax for the REN statement says you are trying to RENAME the entire folder. DO you not want to rename the CBS.log within the CBS folder?
    Yes. I would however, also find it useful to be able to rename the parent folder [CBS] if I so wished.

    I was trying out both, hence the confusion!
    Last edited by Paul Black; 18 Apr 2019 at 11:12.
      My Computer


  10. Posts : 3,615
    Win 10 x64, Linux Lite, Win 7 x64, BlackArch, & Kali
       #20

    Well, my reference to #62 green was the response number that was marked with a green check-mark.
    It's not there anymore. Many other responses not there either, must be admin vetting.
    The gist of the response was that you can't elevate from guest to admin from within the guest process. Don't recall who claimed to be the respondent.
      My Computer


 
Page 2 of 3 FirstFirst 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 10:18.
Find Us