Link to home
Start Free TrialLog in
Avatar of Alex-Kay
Alex-KayFlag for United Kingdom of Great Britain and Northern Ireland

asked on

I have written a srcipt

Good Afternoon,

I have written a script to clear the desktop of anything that we do not want on there (the company has a clear "desktop" policy)
however I have come to a blank point.

Could you please look at it give me suggestions on where to go next?

your help is much appreciated
set D=%date%
set D=%D:/=.%
set T=%time%
set T=%T::=.%
mkdir "%userprofile%\my documents\Desktop Backup\%D%\"
mkdir "%userprofile%\my documents\Desktop Backup\%D%\%T%\"
xcopy "%userprofile%\desktop\*.*" "%userprofile%\my documents\Desktop Backup\%D%\%T%\" /EXCLUDE:C:\exclude.txt /E /C /Y

Open in new window

Avatar of Alex-Kay
Alex-Kay
Flag of United Kingdom of Great Britain and Northern Ireland image

ASKER

I take it that I have added this into the wrong area could somone suggest a better place for me to put it?
Ok all desktops are XP pro, using a mixture of Office 2003 and 2007.

What we would like the script to do is to removing anything off the desktop that shouldn't be there... however we don't want to "delete" these items they need to be put in a folder in "My Documents".
I think we have covered that bit in the script.

What should be left on the desktop is the following:-

My Computer
My Documents
My Network places
Recycle Bin
Internet Explorer
Outlook

And we would like to be able to leave Mapped Network Drives on the desktop aswell.

please ask if anymore information is needed.


Thanks for your Help Vee  Mod

ASKER CERTIFIED SOLUTION
Avatar of Ryan_R
Ryan_R
Flag of Australia image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
No the current script appears to work but I cannot figure out how to make it
remove the stuff from the desktop.
We have managed to make it copy the stuff into a folder.
SOLUTION
Avatar of cj_1969
cj_1969
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
I haven't used scopy much myself, but to ask a simple question, do you have code there to delete the desktop files after they're copied to My Docs\Desktop Backup. I'd be otherwise assuming one of the switches that you've got at the end takes care of that.
No, the code isn't there, I have just tried the above addition and it does not delete from the desktop
If I were doing this I'd take a slightly different approach:

Have a backup folder containing all the files currently in your exclude list in the location "%userprofile%\DesktopBackup" and set it's attributes to hidden so that the user can't see it in explorer (assuming you don't show hidden files)
Then at startup:


set D=%date%
set D=%D:/=.%
set T=%time%
set T=%T::=.%
rename "%userprofile%\Desktop" "%userprofile%\Desktop-%D%-%T%"
copy "%userprofile%\DesktopBackup" "%userprofile%\Desktop"
attrib -h "%userprofile%\Desktop"
 
 
 
It's untested (since I like my desktop the way it is) but it's something to play with

Open in new window

If the above code didn't work can you tell us what happened ... was there an error message?  if so, what was it ... it could be a simple syntax problem keeping it from working.

I tried the script ... it looks like a simple syntax error in the second line ... try this ...
cd "%userprofile%\my documents\Desktop Backup\%D%\%T%\"
for %%a in (*.*) DO del /F/Q "%userprofile%\desktop\%%a"

*** remove the /F option in the for statement ***
Ok we have got a bit further with this but I am now struggling with a different point.
the cript runs and copies everything into the designated folder that is created when you run the script, and some of the .lnk files get deleted from the desktop but not all of them. I cannot figure out why some of these shorcuts (.lnk files) are not being deleted. The only thing I can think of is that the ones that are staying (on my machine) are the ones that were installed when I was logged on as Domain admin... (I do have local admin rights)

any ideas?

I have attahced the code below.
set D=%date%
set D=%D:/=.%
set T=%time%
set T=%T::=.%
mkdir "%userprofile%\my documents\Desktop Backup\%D%\"
mkdir "%userprofile%\my documents\Desktop Backup\%D%\%T%\"
mkdir "%userprofile%\my documents\Desktop Backup\Links"
xcopy "%userprofile%\desktop\*.*" "%userprofile%\my documents\Desktop Backup\%D%\%T%\" /EXCLUDE:C:\exclude.txt /E /C /Y
xcopy "%userprofile%\Desktop\*.lnk" "%userprofile%\my documents\Desktop Backup\Links\" /E /C /Y
del "%userprofile%\Desktop\Desktop\*.*" /Q /F
xcopy "%userprofile%\my documents\Desktop Backup\Links\*.*" "%userprofile%\Desktop\Desktop\" /E /C /Y

Open in new window

Open up My Computer and goto C:\Documents and Settings\[user]\Desktop
Are all of the files you deleted gone from there?

Now go to C:\Documents and Settings\All Users\Desktop
Does this folder contain the shortcuts that you couldn't delete previously?
When I changed from plain text to rich text the <USER> dissapeared which is why I wrote it again in square brakets - came back after clicking Submit - weird
Hi Ryan,

Yes and no... I have found that if you create a new folder on the desktop this will not be deleted either, along with things like Acrobat.
Could you create a detailed list of what files don't get deleted and if they're in the userprofile or All Users area?
OK here are some examples... (these are off my machine)

Adobe Reader8, SmartDashboard R65, VMware Infrastructure Client, Quicktime Pleyer and any folders that I have created.

other applications like Symantec PC anywhere and putty.exe do get deleted.
Have you considered my suggestion here: http:#22188297 
This is going to get a lot more complicated.
You can handle directories by doing a for loop in the destination directory and making the file selection criteria to be a list of directories ... you can then execute a command to remove the entire direectory structure.
As for the remaining program references ... there is 2 reasons that these might not be deleted.
1. the link is in the default or all users profile directory so that it shows up on the desktop of any user that logs into the machine ... easy enough to fix, just add another line that iterates through the contents of the copy directory and does a delete against each of those 2 profiles.
2. the application icons could be configured through the registry for display on the desktop.
*** If this is the case then things get complicated ... you would probably have to use VBScript to run a command to modify the registry to remove these entries.  Off the top of my head I can't think of a way to do this from the batch file.
Hello,

I've worked on this with Alex.  To identify the problems we're having more accurately on some machines the line below doesn't delete some shortcuts on the desktop and has deleted there targets:
del "%userprofile%\Desktop\Desktop\*.*" /Q /F

The other problem is we want to leave shortcuts on the desktop which is why we copy them into a folder and copy them back.  The problem with this is I didn't realise that as well as shortcuts, folders also have a .lnk extension.

This may be an over complicated way of solving the problem, the end result needs to be that users only have shortcuts on there desktops, not files.

Hope that clarify's what we are trying to acheive.  Any suggestions are much appreciated.

Thanks,

Ben
1.  Your del command directory reference appears to be incorrect.

2. This will take care of the directories ...
for /F %%a in ('dir /ad/b "%userprofile%\Desktop"') do rd /s/q %%a
*** You might have to play with the path a little ... I didn't want to mess with my desktop, this is the actual command I tested with that worked for removing directories from the current directory ...
for /F %a in ('dir /ad/b') do rd /s/q %a

As for the program file references on the desktop ... you need to see if they are links or placed their through a registry setting.  also, if the links are from the All Users then only an admin is going to be able to delete those.
We didn't want to mess with ours either which is why we were using "%userprofile%\Desktop\Desktop\*.*" /Q /F

So effectively we're treating a folder on our desktop as our desktop.
Ah, males sense ... that leaes the rest of the directory references in tact  :)
It would not address the icons on the desktop that are put there by the registry though.

So, what exactly is being left in the folder?  Since it is not the application icons from the registry (as they would ONLY be on the actual desktop) what is being left there?  What are the properties on the files?  Are they read-only?  Did you copy them from another location on disk?  If so they might have kept the security permissions from where they came from and you might not have the right to delete them.
boy I need a spell check in this thing!
Oh, any progress on this?
just to let any of you know, we have decided to do a vbs script for this.

Thanks for all your help, I am splitting the points equally between you.