Solved

Logon script to delete TEMP files

Posted on 2004-08-19
13
1,046 Views
Last Modified: 2009-07-29
Hi,

I have a Windows 2000 Server SP4 / XP Pro SP1 network, one domain.

I need to create an automated mechanism to delete TEMP files in Windows XP workstations. The two folders I need to target are (everything within this folders should be deleted):

C:\Windows\Temp
C:\Documents and settings\Current_domain_user_name\Local settings\Temp

I also need to delete all files of type *.rtf *.doc and *.tmp (only this type of files, not folders or any other file type) from:

C:\Documents and Settings\Current_domain_user_name\Program files\Microsoft\Word

I would like to add a logon script to a GPO, so that everytime the user logs in, the delete action takes place, before starting any programs.

I have no knowledge of VBS. Could somebody help me with the script?

Thanks in advance,

Flecha
0
Comment
Question by:flechazul
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 4
  • 4
  • +1
13 Comments
 
LVL 9

Expert Comment

by:Pentrix2
ID: 11840184
a login script is more like a batch file, just do add the commands to delete those files in that Temp file in the login script.
0
 
LVL 31

Assisted Solution

by:merowinger
merowinger earned 20 total points
ID: 11840533
hi,
here try this, but wait for the answers of the others. the other experts shell check my script.

'--------------------------------------------------------------------------------
Dim fso, folder1, folder2, folder3, file, filetype
Dim username, net
Set net = CreateObject("Wscript.Network")
Set fso = CreateObject("Scripting.FileSystemObject")
username = net.username
folder1 = fso.GetFolder("C:\Windows\Temp")
folder2 = fso.GetFolder("C:\Documents and settings\" &username &"\Local settings\Temp")
folder3 = fso.GetFolder("C:\Documents And Settings\Current_domain_user_name\Program files\Microsoft\Word")

For Each file In folder1.Files
File.Delete
Next

For Each file In folder2.Files
File.Delete
Next

For Each file In folder3.Files
file = fso.GetFile

fileype = Right(file, 3)
If filetype = "rtf " Or filetype = "tmp"
file.Delete
Next
'--------------------------------------------------------------------------------


mero
0
 
LVL 9

Expert Comment

by:Pentrix2
ID: 11840554
you could just do this, so much easier.

echo off
delete C:\Windows\Temp\*.*
delete C:\Documents and settings\Current_domain_user_name\Local settings\Temp\*.*
0
What Is Transaction Monitoring and who needs it?

Synthetic Transaction Monitoring that you need for the day to day, which ensures your business website keeps running optimally, and that there is no downtime to impact your customer experience.

 
LVL 9

Expert Comment

by:Pentrix2
ID: 11840562
I meant,

C:\Documents and settings\%user%Local settings\Temp

or

C:\Documents and settings\Default User\Local settings\Temp
0
 
LVL 18

Expert Comment

by:crissand
ID: 11842644
Delete *.* is not working because it's waiting for an input. I use del *.tmp, del ~*.*.

del %temp%\*.tmp
del %temp%\~*.*

for the users's temp folder

del %homedrive%\%homepath%\Program files\Microsoft\Word\*.rtf
del %homedrive%\%homepath%\Program files\Microsoft\Word\*.doc
del %homedrive%\%homepath%\Program files\Microsoft\Word\*.tmp

but I think is Not
\Program Files\
but
\Application data\

for Office files and

del %windir%\Temp\*.tmp

for system temp folder

If you want to delete all files you can use the syntax

for %L in (*.*) do del "%L"


0
 
LVL 9

Expert Comment

by:Pentrix2
ID: 11843327
Oh, my bad.  Or you could kix it.
0
 

Author Comment

by:flechazul
ID: 11939792
Please excuse me for not replying earlier. I was  away and could not try your suggestions.

Now I have implemented them, but I am experiencing some problems. The batch file looks like this:

del %temp%\*.* /f /s /q
rmdir %windir%\Temp /s /q
mkdir %windir%\Temp
del %homedrive%%homepath%\Application Data\Microsoft\Word\*.rtf
del %homedrive%%homepath%\Application Data\Microsoft\Word\*.doc
del %homedrive%%homepath%\Application Data\Microsoft\Word\*.tmp
del %homedrive%%homepath%\Application Data\Microsoft\Word\~*.*

My problems are:

1.- The first 3 lines are working fine, although I would like to be able to delete the %temp% directory and recreate, like I do with %windir%. This would allow me to delete also the folders, not only the files. How to do it?
2.- The next 4 lines are not working. Regarding the Word temp files, Crissand was right when pointing out that the path was really to Application Data, not Program Files. However, all the lines to delete the temp files in the Microsoft\Word folder are not working. It seems like they cannot reach the Application data folder itself. I have read in http://support.microsoft.com/default.aspx?scid=kb;en-us;329308&Product=winxp that there is a problem with the path to Application data folder in XP. I have followed the proposed steps but it is still not working (even in CMD I do not get the folder if I type %APPDATA%). As you can see, I have also manually added the folder to the del path, but it still fails to delete the files. Where is the problem?

Thank you
0
 
LVL 18

Accepted Solution

by:
crissand earned 105 total points
ID: 11941071
del %homedrive%%homepath%\Application Data\Microsoft\Word\*.rtf
del %homedrive%%homepath%\Application Data\Microsoft\Word\*.doc
del %homedrive%%homepath%\Application Data\Microsoft\Word\*.tmp
del %homedrive%%homepath%\Application Data\Microsoft\Word\~*.*
                          ^
                          |
Here you forgot a backslash

It's

del %homedrive%\%homepath%\Application Data\Microsoft\Word\*.rtf
del %homedrive%\%homepath%\Application Data\Microsoft\Word\*.doc
del %homedrive%\%homepath%\Application Data\Microsoft\Word\*.tmp
del %homedrive%\%homepath%\Application Data\Microsoft\Word\~*.*

Where is the prompt when you type the following lines:

%systemdrive%
cd %appdata%

It must give you the user's application data folder.

Then if you type cd Microsoft\Word you will be where you want.

That mean you could replace the three lines bellow with

del %appdata%\Microsoft\Word\*.rtf
del %appdata%\Microsoft\Word\*.doc
del %appdata%\Microsoft\Word\*.tmp
del %appdata%\Microsoft\Word\~*.*

Be very carefull to the backslashes.
0
 

Author Comment

by:flechazul
ID: 11941323
> Here you forgot a backslash

You are right. I have corrected it but stil does not work.

> Where is the prompt when you type the following lines:
> %systemdrive%
> cd %appdata%

It takes me where I want to go: to the current user application data folder. It seems this part is fine then.

> That mean you could replace the three lines bellow with...

I've done it. If I run it locally (no as a logon script) I get the message "The system cannot find the specfied path", although the path that I can see in the CMD window as selected for this task is correct (I have added a pause to let me see what it is doing).
If I run it as a logon script, it does not delete any files, I guess for the same reason provided when I run it locally (I cannot see what it is happennig in the logon script).
0
 
LVL 18

Expert Comment

by:crissand
ID: 11941446
You can't see the logon script? Make it visible. Let's see:

The script must be assigned to user, not computer, otherwise all user environment variables does'n't exists.

Do the following modification to the GPO:

Administrative Templates\System\Logon
Always wait for the network at computer startup and logon

and

USER
Administrative Templates\System\Scripts
Run logon scripts synchronously

and

Run logon scripts visible
0
 

Author Comment

by:flechazul
ID: 11950444
I am applying the logon script to user, no doubts about that.

I have modified the GPO according to your instructions (except for "Always wait for the network at computer startup and logon" which is not present - Windows 2000 server english SP4).

Now I can see the script. It runs as in the local test. I get the same error: "The system cannot find the specified path" (just for the word files path, the %appdata%). However, the path shown is correct. I do not think it makes any difference, but I should let you know that although the server is the english version, the client machines runs XP Pro spanish version SP1 updated with all the patches.

Any new ideas? Could it be a bug?

Thanks
0
 
LVL 18

Expert Comment

by:crissand
ID: 11950527
It's not a bug. Application data is a hidden folder for any user except the administrator. I think you must run

attrib -r -h %appdata%

to make the folder visible. I never done this, so I don't know if it works.
0
 

Author Comment

by:flechazul
ID: 11954880
It does not.

I've tried other parameters of the attrib command as well, but no luck (neither running it locally, or as a logon script). If I tried the same command and parameters with any other %value% like %windir% or %temp% it works fine. However, for some reason, attrib does not recognize %appdata%.

I guess I will wait one more day for replies, but if nobody has any other ideas, I will give Crissand the points for the valuable time employed trying to solve this issue, although half of my problem is not solved.

Thanks you very much,
0

Featured Post

Instantly Create Instructional Tutorials

Contextual Guidance at the moment of need helps your employees adopt to new software or processes instantly. Boost knowledge retention and employee engagement step-by-step with one easy solution.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

A common practice in small networks is making file sharing easy which works extremely well when intra-network security is not an issue. In essence, everyone, that is "Everyone", is given access to all of the shared files - often the entire C: drive …
We recently endured a series of broadcast storms that caused our ISP to shut us down for brief periods of time. After going through a multitude of tests, we determined that the issue was related to Intel NIC drivers on some new HP desktop computers …
In this video, viewers are given an introduction to using the Windows 10 Snipping Tool, how to quickly locate it when it's needed and also how make it always available with a single click of a mouse button, by pinning it to the Desktop Task Bar. Int…
Michael from AdRem Software explains how to view the most utilized and worst performing nodes in your network, by accessing the Top Charts view in NetCrunch network monitor (https://www.adremsoft.com/). Top Charts is a view in which you can set seve…

729 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question