Question

DEL /F /Q "%AllUsersProfile%\Desktop\Kronos Workforce Central(R).url"
DEL /F /Q "%AllUsersProfile%\Desktop\Kronos Workforce Central(R).website"

DEL /F /Q "%UserProfile%\Desktop\Kronos Workforce Central(R).url"
DEL /F /Q "%UserProfile%\Desktop\Kronos Workforce Central(R).website"

Call %CD%\!Kshort.vbs

I created the above batch file which works well. I plan to execute a mass removal of an old link using LogMeIn. Each system has the same credentials for the Admin account but different for the individual users. Using this method I would need to manually enter the login information for hundreds of computers. Is there a smarter way to perhaps seek out these known file names and remove them without using the %UserProfile% command but still keeping the multi-system flexibility that I need?

Is there a way of deleting files on another user's desktop without knowing that user's name?

Can you remove a file from each and every "Desktop" folder on a computer?

Was it helpful?

Solution

Use the for /f command to loop through all users in C:\Users, then check if the file exists in each users Desktop directory - if it does, delete the file.

for /f %%a in ('dir /B /AD C:\Users') do (
    if exist "C:\Users\%%a\Desktop\Kronos Workforce Central(R).url" del /F /Q "C:\Users\%%a\Desktop\Kronos Workforce Central(R).url"
    if exist "C:\Users\%%a\Desktop\Kronos Workforce Central(R).website" del /F /Q "C:\Users\%%a\Desktop\Kronos Workforce Central(R).website"
)
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top