I'll begin by saying I'm a noob at writing batch files although I've modified a few to suit my specific needs. So. I'm trying to write a batch file that will:- a) Take full ownership of a file(s) b) Rename original file(s) c) Copy replacement file(s) from folder A (different) to the original locations (Windows, system32 and SysWOW64 involved here) Code: takeown /f C:\Windows\System32\Elmers.rtf cacls C:\Windows\System32\Elmers.rtf REN C:\Windows\System32\Elmers.rtf Elmers0ld.rtf COPY "D:\ MODIFYING\7 DLL+ W.I.P.s\Elmers.rtf" "C:\Windows\System32\Elmers.rtf" N.B. The space at the start of the folder called " Modifying" (its Alt+160) is deliberate, not a typo. I've made a mock up as above so I assumed the first two (takeown & cacls) were working and the rename bit worked no problem. When I tried it on PNIDUI.DLL it showed that take ownership didn't work so neither did the re-name !! The copying of the replacement file from my storage folder to system32 folder does NADA, zip, zilch! This is to automate (eventually!) the changing of my imageres.dll file and several other system files I've modified and changes will mostly be to the Windows, system32 and/or SysWOW64 folders. TIA
Hey, I wrote an example in AutoIt script for you: Code: #NoTrayIcon ; We don't want a tray icon #RequireAdmin ; Request administrative access #include <Process.au3> ; We need a function in this file _RunDOS("takeown /f " & @SystemDir & "\Elmers.rtf") ; Do the takeown _RunDOS("icacls " & @SystemDir & "\Elmers.rtf") ; Do the icacls _FileRename(@SystemDir & "\Elmers.rtf", @SystemDir & "\Elmers0ld.rtf") ; Rename the file FileCopy("D:\ MODIFYING\7 DLL+ W.I.P.s\Elmers.rtf", @SystemDir & "\Elmers.rtf") ; Copy the new file ; This is a simple alias for the FileMove() function to make it more obvious that it handles the rename operation Func _FileRename($s_Source, $s_Destination, $i_Flag = 0) Return FileMove($s_Source, $s_Destination, $i_Flag) EndFunc ;==>_FileRename I haven't tested it, but the syntax check was satisfied. Have to advertise for my favorite scripting language, eh
Thanks a lot for that Calistoga. In the meantime this Dufos this end here realised that the line that read: CACLS C:\Windows\System32\elmers.rtf Should have read: ICACLS C:\Windows\System32\elmers.rtf /grant administrators:F /t Once I'd told the Acls to give me control I could move and swap em about. I've got your script though, will be playing about, as one does!! Thanks again.
Batch Rename Files I would like to suggest a program called "KrojamSoft BatchRenameFiles Tool" for renaming batch files batchrenamefiles.org
Just noticed this post and would advise everybody to steer clear of this. Its from the same people who bring you LONG PATH Tool 4.7.1.. I'm not 100% certain but I'm sure it's the one that dumps a long name string of folders on your desktop that you can't 'normally' delete, but you can if you pay them!
Replace protected system files with modded or patched file.. Here is a working batch that I did recently for patching explorer.exe for Windows 8, should work for system .dll files as well if you just revise the path and file name etc..DP Code: @set @jscript=1/* @echo off&color 4f&set cd /d=%~dp0&mode con: cols=73 lines=4&&title[~ REPLACE SYSTEM FILES ~] :: ### ADMIN CHECK reg query "hku\S-1-5-19" >nul 2>&1 || ( @cscript //e:jscript //nologo "%~f0" "%~f0" goto :eof ) :: ### MODIFY AND REPLACE WINDOWS PROTECTED O.S. FILES ### :: ~DosProbie - 09.12.13 :: Place your modded file in same directory with this batch file! :: 1. Takes ownership then taskkill of system target file. :: 2. Disables the software protection service during patching then re-enables. :: 3. Appends end of existing file for possible future restore. :: 4. Copies source file to target destination, effectively replacing original file. :: 5. Re-enables software protection service and system target file. :: ### VARIABLES set srv=sppsvc set cpy=xcopy /qy set file1=explorer.exe set path1=%systemroot% set path2=%systemdrive% :: ### OWNERSHIP OF EXPLORER.EXE takeown /a /f %path1%\%file1%>nul&icacls %path1%\%file1% /Grant *S-1-5-32-544:F>nul :: ### CHECK THEN STOP THE FILE PROTECTION SERVICE IF RUNNING echo. Stopping The Software Protection Service and Explorer.exe.. sc query %1 | find "%srv%">nul 2>&1 if not .%errorlevel%.==.1. goto disableservice ::(If already disabled then goto begin) goto begin :disableservice taskkill /f /im %srv% /t>nul 2>&1&timeout /t 2 > nul sc config %srv% start=disabled>nul 2>&1&net stop %srv%>nul 2>&1 goto begin :begin :: ### KILL EXPLORER.EXE taskkill /f /im %file1%>nul timeout /t 2 /nobreak>nul :: ### MOVE THEN RENAME EXPLORER.EXE FIRST move "%path1%\%file1%" "%tmp%\">nul&ren "%tmp%\explorer.exe" "explorer.exe.Org" move "%tmp%\explorer.exe.Org" "%path1%\">nul :: ### COPY PATCHED EXPLORER.EXE %cpy% "%~dp0explorer.exe" "%path1%\">nul :: ### RESTORE OWNERSHIP cls echo. Modifying and Replacing System Files..Resetting Permissions icacls "%path1%\%file1%" /setowner "NT Service\TrustedInstaller" /T /C>nul 2>&1 timeout /t 2 /nobreak>nul :: ### RESTART APPS & SERVICES net start %srv%>nul cls echo. Almost Done!..Restarting Explorer.exe and Software Protection Service.. timeout /t 3 /nobreak>nul net start %srv%>nul start %file1%&exit /b :eof // ### RUN AS ADMINISTRATOR */ var strArg = WScript.Arguments(0); var objSH = WScript.CreateObject("Shell.Application"); objSH.ShellExecute(strArg, "", "", "runas", "5");
Batch file to rename then replace system files I suggest you to try KrojamSoft BatchRenameFiles program.