snapo
snapo

Reputation: 704

Windows Batch File for loop on user dir

I need to create a batchfile to delete a specific file in the users appdata dir. The batchfile is executed as localsystem.

I did test the following senarios: Command Prompt as localsystem - this works Command Prompt as admin - this works Command Prompt as user - this works for all folders where the user has permissions

As soon as i put the for loop in a batch file, it dosent work anymore. It also dosent matter in which context (User,admin,localsystem) i start it.

for /D %i in ("C:\Users\*") do del /Q /F "%i\AppData\LocalLow\Sun\Java\Deployment\deployment.properties"

The exit code shows 255, which means to long error.

The error i get is the following:

C:\Windows\Scripts>sync_exeptionsiteslistandconfig_java.bat > output.txt
\Users\*") do del "i\AppData\LocalLow\Sun\Java\Deployment\deployment.properties"  /Q /F was unexpected at this time.

Any help why the single line is working and a batchfile with this single line is not working is welcome.

Please also explain why it is not working. (I always run tasks as localsystem)

Upvotes: 0

Views: 513

Answers (1)

foxidrive
foxidrive

Reputation: 41257

This may do what you want, but it only processes normal folders, not hidden etc.

Your problem may have been using %i within a batch script.

@echo off
for /D %%i in ("C:\Users\*") do del /Q /F "%%i\AppData\LocalLow\Sun\Java\Deployment\deployment.properties" 2>nul

Upvotes: 1

Related Questions