Jump to content

Help With Batch Scripting


Recommended Posts

I'm trying to create a Batch File that will perform a few cleanup operations such as deleting shortcuts/log files etc.

However I'm having a few problems, the batch file dosen't seem to be doing anything. I have a feeling its to do with my IF EXIST statements and using more than one in the same instance, but after some googling, I've been unable to find a solution. I'm sure its pretty easy but I dont think my google search terms are picking it up.

Another problem is deleting the 'install' folder and subfolders, with the del command I'm able to delete the folder and subfolder contents, but not the folders and subfolders themselves! It's pretty late, and I'm sure I'm missing something simple, but I'm stumped right now :rolleyes:

I've attached my cleanup.bat file incase anyone can help out.

// Xeijin

cleanup.txt

Link to comment
Share on other sites


Best way to remove Install folder:

SET KEY=HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\RunOnceEx

REG ADD %KEY% /V TITLE /D "Windows Install Is Finally Done" /f

REG ADD %KEY%55 /VE /D "Removing Windows Install Folder" /f

REG ADD %KEY%55 /V 1 /D "cmd /C RD /S /Q %systemdrive%\Install" /f

start rundll32.exe iernonce.dll,RunOnceExProcess

And to the end of any script right before EXIT.

Edited by war59312
Link to comment
Share on other sites

Open a command window and type if /? or any other dos command to find how to use it.

You either need it all on the same line or use ( ) like this

IF EXIST "*.log"  DEL "*.log"  ELSE ( 
IF EXIST "*.exe" DEL "*.exe" ELSE (
CD "%USERPROFILE%\Desktop"
)
)

Link to comment
Share on other sites

As well as looking at correct IF and ELSE usage, the script could be reduced considerably too.

Have you noticed that in your different profiles, you are performing the same tasks?, that could effectively be carried out in a for loop.

Here's a quick untested example of a batch file which should do everything you need:

@FOR %%? IN (CMDOW.EXE) DO @IF "%%~$PATH:?" NEQ "" (
@%%~$PATH:? @ /HID) ELSE (@ECHO OFF)
FOR /D %%? IN ("%ALLUSERSPROFILE:\ALL USERS=%\*") DO CALL :C_ "%%?"
2>NUL (DEL %SYSTEMDRIVE%\NVLOG.TXT
RD/S/Q %SYSTEMDRIVE%\INSTALL)
GOTO :EOF
:C_
PUSHD %1
2>NUL DEL/F/Q *.EXE *.LOG DESKTOP\*.*
POPD &GOTO :EOF

Link to comment
Share on other sites

@war59312: Thanks I didn't know about the RD command :)

@jbm: I did try that out but it didn't seem to work for me?? Doing pretty much the same thing as it was doing before.

@Yzowl: Thanks Yzowl this is the script I'm using now :) Even more useful as it seems to delete it for other users as well!! Though I have no idea what it's doing, it seems to work!

Thanks Again,

// Xeijin

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...