VBS or Batch File - Delete Desktop Shortcuts

SP3CLt
SP3CLt used Ask the Experts™
on
Hello, I need help with a script - looking to remove certain shortcuts from user profiles. The script will be ran remotley. The script works great when ran locally, not when ran via altiris as the system account.
Option Explicit 
Dim oFS 
Dim oWsh 
Dim oNetwork 
Dim strUser 
Set oWsh = CreateObject("WScript.Shell") 
set oFS = WScript.CreateObject("Scripting.FileSystemObject") 
Set oNetwork= CreateObject("Wscript.Network") 
strUser = oNetwork.username 
Dim icon1 
icon1 = oWsh.SpecialFolders("Desktop") & "\CTI Softphone.lnk" 
Dim icon2 
icon2 = oWsh.SpecialFolders("Desktop") & "\Shortcut CTI Softphone.lnk" 
Dim icon3 
icon3 = oWsh.SpecialFolders("Desktop") & "\Agent Desktop.lnk" 
Dim icon4 
icon4 = oWsh.SpecialFolders("Desktop") & "\Shortcut to Agent Desktop.lnk" 
Dim icon5 
icon5 = oWsh.SpecialFolders("Desktop") & "\CTI Agent Desktop.lnk" 
IF (oFS.FileExists(icon1)) then 
   oFS.deletefile (icon1) 
End if 
IF (oFS.FileExists(icon2)) then 
   oFS.deletefile (icon2) 
End if 
IF (oFS.FileExists(icon3)) then 
   oFS.deletefile (icon3) 
End if 
IF (oFS.FileExists(icon4)) then 
   oFS.deletefile (icon4) 
End if 
IF (oFS.FileExists(icon5)) then 
   oFS.deletefile (icon5) 
End if 
Set oFS = Nothing 
WScript.Quit (0)

Open in new window

Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Commented:
The problem is that your script is designed to be run as a logon script.  When run under the SYSTEM account it doesn't look in other users' profiles.

Paste the script below into a text file with a .cmd extension.  Customize the value of the files variable on line 4 with the names of the files to delete.  Running the script will echo delete commands to be run.  Note that these commands delete the files from anywhere under the profiles directory, not just from users' Desktop folders.

Once you have tested it successfully and are certain that it will do what you intend, remove the word ECHO from line 6 to execute the commands.


@echo off
setlocal
 
set files="CTI Softphone.lnk" "Shortcut CTI Softphone.lnk" "Agent Desktop.lnk" "Shortcut to Agent Desktop.lnk" "CTI Agent Desktop.lnk"
 
for %%G in (%files%) do ECHO del /f /s /q "%allusersprofile%\..\%%~G"
 
pause

Open in new window

Author

Commented:
Works perfectly! Thank you so much Shift-3.
I changed pause to exit, to move onto the next script in the update batch.
 
 

@echo off
setlocal
 
set files="CTI Softphone.lnk" "Shortcut CTI Softphone.lnk" "Agent Desktop.lnk" "Shortcut to Agent Desktop.lnk" "CTI Agent Desktop.lnk"
 
for %%G in (%files%) do del /f /s /q "%allusersprofile%\..\%%~G"
 
exit

Open in new window

Author

Commented:
Shift-3 is a genius..

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial