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: Help with taking ownership of system file using a batch file.

05 May 2017   #1
SnakeFist

Windows 7 Ultimate x64 SP1
 
 
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



My System SpecsSystem Spec
.
06 May 2017   #2
Pyprohly

Windows 10, Windows 8.1 Pro, Windows 7 Professional, OS X El Capitan
 
 

Quote   Quote: Originally Posted by SnakeFist View Post
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.


Quote   Quote: Originally Posted by SnakeFist View Post
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 System SpecsSystem Spec
07 May 2017   #3
SnakeFist

Windows 7 Ultimate x64 SP1
 
 

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.
My System SpecsSystem Spec
.

08 May 2017   #4
Pyprohly

Windows 10, Windows 8.1 Pro, Windows 7 Professional, OS X El Capitan
 
 

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 System SpecsSystem Spec
08 May 2017   #5
SnakeFist

Windows 7 Ultimate x64 SP1
 
 

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 System SpecsSystem Spec
09 May 2017   #6
Pyprohly

Windows 10, Windows 8.1 Pro, Windows 7 Professional, OS X El Capitan
 
 

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 System SpecsSystem Spec
Reply

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




Thread Tools




Similar help and support threads
Thread Forum
Taking Ownership of hosts file
I'm using a self customized hosts file in Windows 7 Enterprise and am wondering if it would create usablilty problems if I : 1 : Took ownership of the file and/or 2 : Removed System access The reason being, making the file read only is constantly and regularly being undone and entries I...
General Discussion
Batch File .bat to copy file from File Sharing & FTP Hosting
Hi all, Any idea how to write Batch File .bat to copy file from File Sharing & FTP Hosting to local directory. Current the File Sharing & FTP Hosting is SMARTFILE. I don't want to use WINSCP as the connector. Thanks
General Discussion
Access denied when taking ownership of a file
Hi, I recently downloaded an application file (.exe), and tried to delete it, but i keep getting the error "Windows cannot access the specified device, path, or file. You may not have the appropriate permissions to access the item". I tried changing the ownership of the file > right click >...
System Security
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
Taking ownership of System folder
Hi folks, I was wondering would anyone be able to help me. I am trying to copy a file to my windows system folder. I have already taken ownership of the folder and given myself full control. I even successfully copied a file to the folder a few days ago but now when I go to copy a file...
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 22:54.
Twitter Facebook Google+ Seven Forums iOS App Seven Forums Android App