Help with taking ownership of system file using a batch file.


  1. Posts : 73
    Windows 7 Ultimate x64 SP1
       #1

    Help with taking ownership of system file using a batch file.


    I'm making a batch file to reinstall some reg files back in to the registry after i rebuild windows. I also want to take ownership of a file in system32 and then replace it with a modified version containing extra icons i put in there.
    I'm hoping that as long as the files the .reg and .dll files are in the same folder as the batch file it will work.
    So does anyone know what command I can use to take ownership of a file then replace it. I know i use xcopy to replace just not sure how i implement it.
    Also no big deal but will be cool on how i can make each part colorized. Like where i have my notes at, i want it to be green as to stand out so it will be read.

    Here is my file so far.

    Code:
     @echo Off
    Mode 100,43
    :MENU
    ECHO ______ __ __ ______ __ __ ______ ______ __ ______ ______
    ECHO /\ ___\ /\ "-.\ \ /\ __ \ /\ \/ / /\ ___\ /\ ___\ /\ \ /\ ___\ /\__ _\
    ECHO \ \___ \ \ \ \-. \ \ \ __ \ \ \ _"-. \ \ __\ \ \ __\ \ \ \ \ \___ \ \/_/\ \/
    ECHO \/\_____\ \ \_"\_\ \ \_\ \_\ \ \_\ \_\ \ \_____\ \ \_\ \ \_\ \/\_____\ \ \_\
    ECHO \/_____/ \/_/ \/_/ \/_/\/_/ \/_/\/_/ \/_____/ \/_/ \/_/ \/_____/ \/_/
    ECHO.
    ECHO ___________________________________________________________
    ECHO *Notes*
    ECHO Make Sure To Have Photoshop CC 2015 Installed For The Edit
    ECHO On Right Click Menu To Open Images In Photoshop.
    ECHO ___________________________________________________________
    ECHO Make Sure imageres.dll Is Copied Over To System32 Folder
    ECHO For Hard Drive Icons, Command Prompt Icon And Power Options
    ECHO Cascade Menu On Right Click Icons To Show Up.
    ECHO *Notes*
    ECHO ___________________________________________________________
    ECHO.
    ECHO.
    ECHO.
    ECHO -----------------------------------------------------------
    ECHO PRESS 1, 2, 3, 4, 5, 6 to select your task, or 7 to EXIT.
    ECHO -----------------------------------------------------------
    ECHO.
    ECHO 1 - Change Edit To Open Photoshop
    ECHO 2 - Enable Logon In Windows 7
    ECHO 3 - HDD Icons
    ECHO 4 - Open Command Prompt Here With Icon
    ECHO 5 - Power Options Cascade Menu On Right Click
    ECHO 6 - Take Ownership Of Files
    ECHO 7 - EXIT
    ECHO.
    ECHO 1 - Change Edit To Open Photoshop
    ECHO 2 - Enable Logon In Windows 7
    ECHO 3 - HDD Icons
    ECHO 4 - Open Command Prompt Here With Icon
    ECHO 5 - Power Options Cascade Menu On Right Click
    ECHO 6 - Take Ownership Of Files
    ECHO 7 - EXIT
    ECHO.
    SET /P M=Type 1, 2, 3, or 4 then press ENTER:
    IF %M%==1 Change Edit To Open Photoshop
    IF %M%==2 Enable Logon In Windows 7
    IF %M%==3 HDD Icons
    IF %M%==4 Open Command Prompt Here With Icon
    IF %M%==5 Power Options Cascade Menu On Right Click
    IF %M%==6 Take Ownership Of Files
    IF %M%==7 GOTO EOF
    :Registry Entry
    cd regedit.exe /s Change Edit To Open Photoshop.reg
    start regedit.exe
    GOTO MENU
    :Registry Entry
    cd regedit.exe /s Enable Logon In Windows 7.reg
    start regedit.exe
    GOTO MENU
    :Registry Entry
    cd regedit.exe /s HDD Icons.reg
    start regedit.exe
    GOTO MENU
    :Registry Entry
    cd regedit.exe /s Open Command Prompt Here Icon.reg
    start regedit.exe
    GOTO MENU
    :Registry Entry
    cd regedit.exe /s Power Options Cascade Menu On Right Click.reg
    start regedit.exe
    GOTO MENU
    :Registry Entry
    cd regedit.exe /s Take Ownership Of Files.reg
    start regedit.exe
    GOTO MENU
    Last edited by SnakeFist; 07 May 2017 at 00:13. Reason: Cause the text is coming up like it's greyed out.
      My Computer


  2. Posts : 721
    Windows 10, Windows 8.1 Pro, Windows 7 Professional, OS X El Capitan
       #2

    SnakeFist said:
    I also want to take ownership of a file in system32 and then replace it with a modified version containing extra icons i put in there.

    So does anyone know what command I can use to take ownership of a file then replace it. I know i use xcopy to replace just not sure how i implement it
    To replace a file in System32, you need to first take ownership of it (using the takeown command) then change it’s permissions (with icacls). Then you can simply use copy to replace the file.

    E.g., here I demonstrate how to replace sethc.exe with cmd.exe.
    Code:
    takeown /f "C:\Windows\System32\sethc.exe"
    icacls "C:\Windows\System32\sethc.exe" /grant "%username%":F
    copy "C:\Windows\System32\cmd.exe" "C:\Windows\System32\sethc.exe"
    The batch file will need to be executed with administrative privileges for this to work.


    SnakeFist said:
    Also no big deal but will be cool on how i can make each part colorized. Like where i have my notes at i wan't to be green to stand out so it will be read.
    The color command will change the background/foreground colours of the console. Changing the colour of just a section is a bit difficult in batch.
      My Computer


  3. Posts : 73
    Windows 7 Ultimate x64 SP1
    Thread Starter
       #3

    Thank you for the reply.
    But when i go to choose an option it gives me an error which states. HDD is not recognized as an internal or external command, operable program or batch file. The system cannot find the path specified. I added in what was suggested to me in post 2. But took it out when option 1 through 6 kept give me an error. I took the part out and still got the same errors.

    What i was trying to do is have all the reg files in a folder along with the modified dll with the batch file and when i click on an option it will run that reg file in that folder or copy over the dll after taking ownership of the original dll. But when i tested it in a virtual machine i get the error stated above. Is my paths right? I want to be able to use it regardless of where i put the folder. Or pack it in a winrar exe and have it work. Also if possible make the take ownership and copying of the dll as option 7 and 8 and then option 9 as exit so all of it will be 1 batch file.
    Last edited by SnakeFist; 07 May 2017 at 19:32.
      My Computer


  4. Posts : 721
    Windows 10, Windows 8.1 Pro, Windows 7 Professional, OS X El Capitan
       #4

    It sounds like more than a few things need correcting before you start taking on board suggestions. You need to be able to get the bulk of it down on your own and reserve your enquiries for specific questions, or it’s off topic and unsuitable in a forum to be discussing solutions that are so personalised.

    The batch script is not functional currently. None of the options work because these ifs aren’t wired correctly.
    Code:
    IF %M%==1 Change Edit To Open Photoshop
    IF %M%==2 Enable Logon In Windows 7
    IF %M%==3 HDD Icons
    IF %M%==4 Open Command Prompt Here With Icon
    IF %M%==5 Power Options Cascade Menu On Right Click
    IF %M%==6 Take Ownership Of Files
    This is causing your “… is not recognized as an internal or external command” errors. What you need is a goto command after each if. E.g.,
    Code:
    IF "%M%"==1 goto :photoshop
    IF "%M%"==2 goto :enableLogin
    IF "%M%"==3 goto :icons
    ...
    Then a corresponding label for each of them,
    Code:
    :photoshop
    rem Commands here
    GOTO MENU
      My Computer


  5. Posts : 73
    Windows 7 Ultimate x64 SP1
    Thread Starter
       #5

    Thank you.

    Sorry for posting a questions did not know that wasn't allowed. Sorry for posting in the wrong forum. I won't make them mistakes again. I will mark this solved and continue on my own. Sorry to have troubled you.
      My Computer


  6. Posts : 721
    Windows 10, Windows 8.1 Pro, Windows 7 Professional, OS X El Capitan
       #6

    Don’t say that. I just though that if we started to discuss those errors it would generate too much back and forth communication, a lot of which wouldn’t relate to the OP.

    Feel free to PM me any time if you need any sort of help with this at all.
      My Computer


 

  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:43.
Find Us