Link to home
Start Free TrialLog in
Avatar of collage_jeanz
collage_jeanzFlag for Canada

asked on

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.
Avatar of knightEknight
knightEknight
Flag of United States of America image


myfile.reg

pushd "c:\program files"
for /D %%D in (Lexmark*) do rd/s/q "%%D"
: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"
: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
Avatar of collage_jeanz

ASKER

Folders are not getting deleted. I think the only reason, bcoz they are on read-only mode. Help !!!
: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
If the folders contain documents that are currently opened by other users, they may not delete.  Could this be the case?
also, it could be a user permission issue.  Run the script as an administrator.  (This is most likely the issue IMO)
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.
ASKER CERTIFIED SOLUTION
Avatar of knightEknight
knightEknight
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
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.
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.