Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Delete shortcuts from \\servername\profiles\%username%\Desktop Folders

Status
Not open for further replies.

Dublin73

IS-IT--Management
Apr 26, 2005
236
US
Hi,

Trying to do something simple ( or so I thought ), but not having much luck with it so far. If I want to delete all shortcuts ( files that have the *.lnk extension ) from a folder called "test", located in the root of my "C: drive" I can do this with a VBScript as follows...

Const DeleteReadOnly = TRUE

Set objFSO = CreateObject("Scripting.FileSystemObject")
objFSO.DeleteFile("C:\test\*.lnk"), DeleteReadOnly

straightforward enough. What I'm trying to accomplish is based on this idea, but more advanced... deleting all of the desktop shortcuts in a user's profile when they log in. So I'm trying to write a VBScript that will be applied, within a GPO as a user "logon script". This VBScript file will look in the user's desktop folder ( in their Windows profile ), and will delete all of the files that are in there.

Unfortunately using %username% as part of the VBScript doesn't work. Hey, it was worth a try!

and obviously I don't want to write a seperate VBScript for all 300 users.

Any suggestions on how to do this would be much appreciated.

thanks in advance to any takers!

 
Have a look at markdmac's login script FAQ faq329-5798 as this would seem to give you the code you need:

UserString = WSHNetwork.UserName

--------------------------------------
"Insert funny comment in here!"
--------------------------------------
 
Unless I missed something, you may consider this:
Set WshShell = CreateObject("WScript.Shell")
strDesktop = WshShell.SpecialFolders("Desktop")
Set objFSO = CreateObject("Scripting.FileSystemObject")
objFSO.DeleteFile strDesktop & "\*.lnk", True

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ181-2886
 
Hey thanks PHV, your suggestion works a treat! TheLad, thanks for responding also. I did try going down the road of... UserString = WSHNetwork.UserName before posting, but that didn't work.

What I'm basically trying to do with this script is... Distribute Desktop and Start Menu shortcuts (icons) based on Windows global group membership. In other words, if a user is a member of a global group called "MicrosoftWord" they will receive a shortcut to the Microsoft Word application on their desktop and in their Start Menu. In contrast to this, if a user is not a member of the "MicrosoftWord" group, they should not see any shortcuts to Microsoft Word. Hence, why I wanted to delete all shortcuts in the %username%\Desktop folder.

I have to crawl before I can walk so I'm starting out with just the Desktop first. This is what I have, but so far it doesn't work....

Set WshShell = CreateObject("WScript.Shell")
strDesktop = WshShell.SpecialFolders("Desktop")
Set objFSO = CreateObject("Scripting.FileSystemObject")
objFSO.DeleteFile strDesktop & "\*.lnk", True

On Error Resume Next

Set objSysInfo = CreateObject("ADSystemInfo")
Set objNetwork = CreateObject("Wscript.Network")

strUserPath = "LDAP://" & objSysInfo.UserName
Set objUser = GetObject(strUserPath)

For Each strGroup in objUser.MemberOf
strGroupPath = "LDAP://" & strGroup
Set objGroup = GetObject(strGroupPath)
strGroupName = objGroup.CN

Select Case strGroupName
Case "MicrosoftWord"
Const OverwriteExisting = TRUE

Set objFSO = CreateObject("Scripting.FileSystemObject")
objFSO.CopyFile "\\servername\Profiles\icons\Microsoft Word.lnk" , "strDesktop", OverwriteExisting
End Select
Next

The shortcut file (which I want copied down to the user's Desktop), pointing to Microsoft Word is on a network share in this location: \\servername\Profiles\icons\Microsoft Word.lnk

I believe that this is where I'm going wrong in the script...

objFSO.CopyFile "\\servername\Profiles\icons\Microsoft Word.lnk" , "strDesktop", OverwriteExisting

Any suggestions there?



 
[!]Set objFSO = CreateObject("Scripting.FileSystemObject")[/!] ' objFSO already created above
objFSO.CopyFile "\\servername\Profiles\icons\Microsoft Word.lnk" , [!]"[/!]strDesktop[!]"[/!], OverwriteExisting

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ181-2886
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top