Bat file to run .reg file and detele couple of folders and record the log file

I have one abc.reg file, which I want to run with the batch file and update the registry and after that I have couple of folders which I want to delete for example, I have 6 folders in c:\program files\lexmarkXXXXX

I want to delete all the folders in c:\program files\ starting with "Lexmark" name, and I want to delete these folders in quite mode.

After running the batch file, it should make a log file for any errors in c:\windows\logs\Lexmark_Removal.txt

please help.
collage_jeanzAsked:
Who is Participating?
 
knightEknightCommented:
Yes, it seems you have running processes that are dependent on the DLL files in these folders.  You should stop and restart what ever services you may have upgraded, or otherwise stop the processes from running.

Here is the same script that will (hopefully) log the errors also:

@echo %date% %time% 1>>c:\windows\logs\Lexmark_Removal.txt
regedit.exe /s  "c:\myfolder\myfile.reg" 1>>c:\windows\logs\Lexmark_Removal.txt  2>>c:\windows\logs\Lexmark_Removal.txt
cd/d "c:\program files"
for /D %%D in (Lexmark*) do attrib -s -h -r "%%D"
for /D %%D in (Lexmark*) do rd/s/q "%%D" 1>>c:\windows\logs\Lexmark_Removal.txt  2>>c:\windows\logs\Lexmark_Removal.txt
echo. >>c:\windows\logs\Lexmark_Removal.txt
0
 
knightEknightCommented:

myfile.reg

pushd "c:\program files"
for /D %%D in (Lexmark*) do rd/s/q "%%D"
0
 
knightEknightCommented:
:oops, left out the regedit part -- try this instead:

regedit.exe /s  "c:\myfolder\myfile.reg"
pushd "c:\program files"
for /D %%D in (Lexmark*) do rd/s/q "%%D"
0
Cloud Class® Course: Amazon Web Services - Basic

Are you thinking about creating an Amazon Web Services account for your business? Not sure where to start? In this course you’ll get an overview of the history of AWS and take a tour of their user interface.

 
knightEknightCommented:
:all that, and I forgot to log it -- sorry, third time's the charm...

@echo %date% %time% >>c:\windows\logs\Lexmark_Removal.txt
regedit.exe /s  "c:\myfolder\myfile.reg" >>c:\windows\logs\Lexmark_Removal.txt
pushd "c:\program files"
for /D %%D in (Lexmark*) do rd/s/q "%%D" >>c:\windows\logs\Lexmark_Removal.txt
echo. >>c:\windows\logs\Lexmark_Removal.txt
0
 
collage_jeanzAuthor Commented:
Folders are not getting deleted. I think the only reason, bcoz they are on read-only mode. Help !!!
0
 
knightEknightCommented:
:what does the error log say?  Let's try this:

@echo %date% %time% >>c:\windows\logs\Lexmark_Removal.txt
regedit.exe /s  "c:\myfolder\myfile.reg" >>c:\windows\logs\Lexmark_Removal.txt
cd/d "c:\program files"
for /D %%D in (Lexmark*) do attrib -s -h -r "%%D"
for /D %%D in (Lexmark*) do rd/s/q "%%D" >>c:\windows\logs\Lexmark_Removal.txt
echo. >>c:\windows\logs\Lexmark_Removal.txt
0
 
knightEknightCommented:
If the folders contain documents that are currently opened by other users, they may not delete.  Could this be the case?
0
 
knightEknightCommented:
also, it could be a user permission issue.  Run the script as an administrator.  (This is most likely the issue IMO)
0
 
collage_jeanzAuthor Commented:
You are rite, when I opened command prompt with Runas (admin account) and run the batch file it showed me something
C:\Documents and Settings\abc\Desktop>lexmark_removal.bat

C:\Documents and Settings\abc\Desktop>regedit.exe /s  "\\server\share\name\Registry.reg"  1>>c:\windows\logs\Lexmark_Removal.txt

C:\Documents and Settings\abc\Desktop>cd/d "c:\program files"

C:\Program Files>for / %D in (Lexmark*) do attrib -s -h -r "%D"

C:\Program Files>attrib -s -h -r "Lexmark"

C:\Program Files>attrib -s -h -r "Lexmark S300-S400 Series"

C:\Program Files>for / %D in (Lexmark*) do rd/s/q "%D"  1>>c:\windows\logs\Lexma
rk_Removal.txt

C:\Program Files>rd/s/q "Lexmark"  1>>c:\windows\logs\Lexmark_Removal.txt
Lexmark\S300-S~1\lxeacaps.dll - Accès refusé.
Lexmark\S300-S~1\lxeacfg.dll - Accès refusé.
Lexmark\S300-S~1\lxeacnv4.dll - Accès refusé.
Lexmark\S300-S~1\lxeadrs.dll - Accès refusé.
Lexmark\S300-S~1\lxeamicro.dll - Accès refusé.

C:\Program Files>rd/s/q "Lexmark S300-S400 Series"  1>>c:\windows\logs\Lexmark_R
emoval.txt
Lexmark S300-S400 Series\lxeacaps.dll - Accès refusé.
Lexmark S300-S400 Series\LXEAcfg.dll - Accès refusé.
Lexmark S300-S400 Series\lxeacnv4.dll - Accès refusé.
Lexmark S300-S400 Series\lxeacomc.dll - Accès refusé.
Lexmark S300-S400 Series\lxeadrs.dll - Accès refusé.
Lexmark S300-S400 Series\lxeamon.exe - Accès refusé.
Lexmark S300-S400 Series\lxeamonr.dll - Accès refusé.
Lexmark S300-S400 Series\lxeascw.dll - Accès refusé.

C:\Program Files>echo.  1>>c:\windows\logs\Lexmark_Removal.txt

But in the log file it was only

2011-05-09 12:46:47,49
 
2011-05-09 12:49:32,12
 
mentioned, It should show the whole process as It showed when I ran from CMD, I have the admin rights to the local machine where I am testing this, is there any command available to take ownership of the lexmark folder's as well? Thanks for being quick.
0
 
collage_jeanzAuthor Commented:
Sorry It didnt help, the purpose of deleting those folders and then deleting lxea*.* files from system32 bcoz whenever we plug in lexmark printer, the computer picks up the driver automattically, I thought to delete all lexmark related files from computer and clean registry with Lexmark name. But it seems to be not helping. If you can help me resolving this issue it would be great, What I want, whenever I plugin any lexmark device, it should ask me for the driver files and should not install anything by itslef.
0
 
knightEknightCommented:
If you unplug the printer and reboot, will the script above remove the directories?

As to the second part of your question: "...whenever I plugin any lexmark device, it should ask me for the driver files..."
that is a different question than simply removing directories, and being unfamiliar with the device I can't help with that.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.