Page 1 of 3
Was wondering if someone could help me Make A Batch File
Posted: 29 Nov 2012 10:26
by anoble1
Was wondering if someone could help me Make A Batch File That Deletes Files
Not sure if many can help but I am in IT, and run in to a certain program error all the time. The fix is deleting 4 files in their PC.
Example:
1.Delete the UCF folder located at C:\Documents and Settings\Username\Documentum
2.Delete the Java folder located at C:\Cache
3.Delete Temp internet Files
4.Delete Cookies
Any suggestions?
Re: Was wondering if someone could help me Make A Batch File
Posted: 29 Nov 2012 13:57
by abc0502
To delete folders and it's content you use
Code: Select all
RMDIR /S /Q "C:\Documents and Settings\Username\Documentum" >nul
RMDIR /S /Q "C:\Cache" >nul
This will remove the directory and it's contents.
"Temp internet Files" for what browsers ?
And What system?
Re: Was wondering if someone could help me Make A Batch File
Posted: 29 Nov 2012 14:11
by anoble1
Very nice. How do I grab the username of who is currently logged into the PC?
There could be multiple usernames.
IE 7
Windows XP
Re: Was wondering if someone could help me Make A Batch File
Posted: 29 Nov 2012 14:27
by abc0502
Edited:
To grap the username u use try this in your cmd window
But this location :
C:\Documents and Settings\<username>\ is equal to
%userprofile%Code: Select all
@Echo Off
:: Remove Cash and Documentum Folders
RMDIR /S /Q "C:\Documents and Settings\%username%\Documentum\UCF" >nul
RMDIR /S /Q "C:\Cache\JAVA" >nul
:: Remove Internet Temporary Files
Del /F /S /Q "%userprofile%\Local Settings\Temporary Internet Files\*.*" >nul
Del /F /S /Q "C:\Documents and Settings\%username%\Cookies\*.*" >nul
pause
Test it and to make it exist after if finish, remove the "pause"
Re: Was wondering if someone could help me Make A Batch File
Posted: 29 Nov 2012 15:03
by anoble1
That is awesome. I may have made a mistake in my first comment.
Here is the one I want to delete.
.Delete the UCF folder located at C:\Documents and Settings\Username\Documentum\UCF
Delete the Java folder located at C:\Cache\JAVA
So, I really just wanted to delete the last folder. not the whole profile and everything. Or did I read your post wrong?
Thanks for all the help.
Re: Was wondering if someone could help me Make A Batch File
Posted: 29 Nov 2012 15:06
by abc0502
Ok, i changed the code above, it will delete the folder UFC and Java and all of it's content.
Re: Was wondering if someone could help me Make A Batch File
Posted: 29 Nov 2012 15:30
by anoble1
@Echo Off
:: Remove Cash and Documentum Folders
RMDIR /S /Q "C:\Documents and Settings\%username%\Documentum\UCF" >nul
RMDIR /S /Q "C:\Cache\JAVA" >nul
:: Remove Internet Temporary Files
Del /F /S /Q "%userprofile%\Local Settings\Temporary Internet Files\*.*" >nul
Del /F /S /Q "C:\Documents and Settings\%username%\Cookies\*.*" >nul
pause
On the Temp internet files, does it need to be like this?
Del /F /S /Q "C:\Documents and Settings\%userprofile%\Local Settings\Temporary Internet Files\*.*" >nul
Re: Was wondering if someone could help me Make A Batch File
Posted: 29 Nov 2012 15:44
by abc0502
Edited:Corrected wrong Path "C:\Documents and Settings\%userprofile%\" to "C:\Documents and Settings\%username%\"yes it can be but as i said
Code: Select all
C:\Documents and Settings\%username%\
Can be used as
as this point to the folder %username% directly, both are the same
I used to do that if i'm going to process folders inside the "
C:\Documents and Settings\%username%" path, so i don't write too much
Re: Was wondering if someone could help me Make A Batch File
Posted: 29 Nov 2012 22:45
by Ed Dyreen
'
hi abc0502,
'userName' == 'runAsUserName' neq 'logonUserName'
Code: Select all
%regKeyRead_% $logonUserName, "HKCU\Software\Microsoft\Windows\CurrentVersion\Explorer", "logon User Name"
But probably not a problem for the sake of simplicity so why mention it, I am bored
abc0502 wrote:Code: Select all
C:\Documents and Settings\%userprofile%\
Can be used as
That's obviously wrong,
Re: Was wondering if someone could help me Make A Batch File
Posted: 30 Nov 2012 04:45
by Boombox
.
If you type SET at the command prompt and hit ENTER.
You can see all the variables that are currently active on your system.
The text before the = symbol is your variable name, so...
%SystemRoot% is equal to the path 'c:\windows'
Re: Was wondering if someone could help me Make A Batch File
Posted: 30 Nov 2012 05:33
by abc0502
@Ed Dyreen and Boombox
Sorry for that it was a typing error, i meant
Code: Select all
C:\Documents and Settings\%username%
Equal to
I wrote that in my 2nd post
Code: Select all
Del /F /S /Q "%userprofile%\Local Settings\Temporary Internet Files\*.*" >nul
Del /F /S /Q "C:\Documents and Settings\%username%\Cookies\*.*" >nul
and didn't notice that i wrote the %userprofile% till you mentioned it.
I will correct that.
Re: Was wondering if someone could help me Make A Batch File
Posted: 30 Nov 2012 07:24
by anoble1
So,
Is there a way to write something that will distinguish between Windows Xp, and Windows 7? Like an IF Statement?
If using Windows XP then use below, ELSE use the Windows 7 file locations?
Re: Was wondering if someone could help me Make A Batch File
Posted: 30 Nov 2012 07:40
by abc0502
Yes, but will this location will change "C:\Cache\JAVA" ?
and is this always at the main folder of the user profile "Documentum\UCF" ?
Re: Was wondering if someone could help me Make A Batch File
Posted: 30 Nov 2012 07:52
by anoble1
In Windows 7 it will be like C:\Users\Username\Documentum
But, I assume the temp internet files and cookies location will change?
Re: Was wondering if someone could help me Make A Batch File
Posted: 30 Nov 2012 08:29
by abc0502
Test this, I only tested XP as I work on it now, in windows 7 i assumed the same when removing the attributes in order to delete protected files.
Code: Select all
@Echo Off
:: Check if OS is XP
ver | find "XP" > nul
if %ERRORLEVEL% == 0 (
:: Delete Temporary Internet Files
PUSHD "%userprofile%\Local Settings\Temporary Internet Files"
For /F "delims=" %%A in ('Dir /B /A:D "*.*"') Do (
ATTRIB -S -H -A "%%A"
RMDIR /S /Q "%%A" 2>nul
ATTRIB +S +H +A "%%A"
)
POPD
:: Delete Cookies
Del /F /Q "%userprofile%\Cookies\*.*" 2>nul
)
echo %vers% | find "Windows 7" > nul
if %ERRORLEVEL% == 0 (
:: Delete Temporary Internet Files [ Two Temp location in windows 7 ]
PUSHD "%userprofile%\AppData\Local\Microsoft\Windows\Temporary Internet Files"
For /F "delims=" %%A in ('Dir /B /A:D "*.*"') Do (
ATTRIB -S -H -A "%%A"
RMDIR /S /Q "%%A" 2>nul
ATTRIB +S +H +A "%%A"
)
POPD
PUSHD "%userprofile%\AppData\Local\Microsoft\Windows\Temporary Internet Files\Low"
For /F "delims=" %%A in ('Dir /B /A:D "*.*"') Do (
ATTRIB -S -H -A "%%A"
RMDIR /S /Q "%%A" 2>nul
ATTRIB +S +H +A "%%A"
)
POPD
:: Delete Cookies
Del /F /Q "%userprofile%\AppData\Roaming\Microsoft\Windows\Cookies\*.*" 2>nul
)
:: Deleting Other Folders [ They should be in general in the same location ]
RMDIR /S /Q "%userprofile%\Documentum\UCF" >nul
RMDIR /S /Q "C:\Cache\JAVA" >nul
Pause
Exit /B
I will test windows 7 when i come back and update the code if needed.
BTW, when running on 7 try running using Admin rights, and don't forget
I DIDN'T TEST IT ON 7and this "2>nul" to prevent errors to be displayed when there is no files in the cookies folder to delete