GPO : delete temp folder at logoff

need to delete temp folder for all user on domain at logoff
- would like to use group policy
- delete all files and subfolder in temp folder

del /s /q /f "%temp%\*.*"
I entered that in the cmd  -  it deletes all files but subfolders still remains(but files empty)
if I need to create a .bat file how would that .bat file look like and how would I add that to GPO to run every  time user logs off - to delete all files and subfolder in the temp folder
Who is Participating?

Improve company productivity with a Business Account.Sign Up

SteveGTRConnect With a Mentor Commented:
Could always do this:
rd /s /q "%temp%"
mkdir "%temp%"

Open in new window

enosunaAuthor Commented:
thank you for the info..but not exactly what I'm looking for.
i want to run a script at logoff through group policy
without having to use xecutor
What Kind of Coding Program is Right for You?

There are many ways to learn to code these days. From coding bootcamps like Flatiron School to online courses to totally free beginner resources. The best way to learn to code depends on many factors, but the most important one is you. See what course is best for you.

Farhan KaziSystems EngineerCommented:
Try following batch script it will delete all sub directories inside Temp folder.
DEL /S /Q /F "%TEMP%\*.*"
FOR /D %%d IN ("%TEMP%\*.*") DO RD /S /Q "%%d"

Open in new window

enosunaAuthor Commented:
how would I add the script the group policy??
Create the script and place it on a commonly accessible network share. Give it a .bat extension.

Open the group policy and select Computer Configuration --> Windows Settings --> Scripts --> Shutdown. Add a reference to the script.
I was able to use the preference to clear the contents of the C:\Windows\Temp fold but I do not think GP preference like variables like &userprofiles%
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.