removing shortcuts via script

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

hi,

i would like some advice on removing desktop shortcuts using a logon script
or using wsh.

i have been able to remove files or folders using the del command but it
fails to delte shortcuts. .lnk all other file extensions seem fine to remove
but this is not what i am trying to achieve.

how would i go about be able to to scan for this perticualar shortcut find
it and remove it regardsles of what user is logged in.

Theres quite a few machines to deal with and automating this would be good.

is wsh suitable for this if so how would i do it guys

thanks for any feedback in advance.
clients are windows 2000 pro

Scripts are my weakness!

Thanks
 
In microsoft.public.win2000.cmdprompt.admin =?Utf-8?B?TmV3Ymll?=
wrote:
hi,

i would like some advice on removing desktop shortcuts using a
logon script or using wsh.

i have been able to remove files or folders using the del command
but it fails to delte shortcuts. .lnk all other file extensions
seem fine to remove but this is not what i am trying to achieve.

What is it you _are_ trying to achieve?
how would i go about be able to to scan for this perticualar
shortcut find it and remove it regardsles of what user is logged
in.

Firstly you would have to know something about whatever it is you are
attempting to locate (and then delete). Like a standard _name_ or a
fixed creation date or the target of the "shortcut". BTW what kind
of "shortcut" is it if not a .LNK file? .URL? What is it a
shortcut too and can you just remove the target (leaving a dead
link)?

Such a find and delete for all local user profiles would require a
Administrator authority in most cases. System Startup Script might
be an option...scheduled task...
 
Newbie said:
hi,

i would like some advice on removing desktop shortcuts using a logon script
or using wsh.

i have been able to remove files or folders using the del command but it
fails to delte shortcuts. .lnk all other file extensions seem fine to remove
but this is not what i am trying to achieve.

how would i go about be able to to scan for this perticualar shortcut find
it and remove it regardsles of what user is logged in.

Theres quite a few machines to deal with and automating this would be good.

is wsh suitable for this if so how would i do it guys
Hi

As long as the user running the VBScript below is a local
administrator, it will delete desktop shortcuts in all user profiles
on the computer. If the user is not a local admin, it will only
delete the shortcut(s) in the desktop folder for the current user.

If this is an Active Directory domain, here is a better solution if
the users are not local admins:

You can do it in a computer startup script that runs as part of
the boot up process (before the user logs in). It runs under the system
context and has admin rights.


'--------------------8<----------------------
' shortcut(s) to delete (add more to the array if you need)
arrLinkFiles = Array("Shortcut to some.exe.lnk","corporate.lnk")

Set objShell = CreateObject("WScript.Shell")
Set objFSO = CreateObject("Scripting.FileSystemObject")

On Error Resume Next
strProfilesDirectory = "" 'init value
strProfilesDirectory = objShell.RegRead("HKLM\SOFTWARE\Microsoft\" _
& "Windows NT\CurrentVersion\ProfileList\ProfilesDirectory")
On Error Goto 0

If strProfilesDirectory = "" Then
' The ProfilesDirectory registry value didn't exist,
' parsing the "Common Start Menu" path read from registry instead
strCSMpath = objShell.RegRead("HKLM\SOFTWARE\Microsoft\Windows\" _
& "CurrentVersion\Explorer\Shell Folders\Common Start Menu")
' Remove the "\All Users\Start Menu" part of it
strProfilesDirectory = Left(strCSMpath, Len(strCSMpath) -21)
End If

strProfilesDirectory = objShell.ExpandEnvironmentStrings(strProfilesDirectory)

' enumerate the folders
Set objFolder = objFSO.GetFolder(strProfilesDirectory)

' supress errors
On Error Resume Next
For Each objFldr In objFolder.SubFolders
For Each strLinkFile In arrLinkFiles
objFSO.DeleteFile objFldr.Path & "\Desktop\" & strLinkFile, True
Next
Next
'--------------------8<----------------------


WSH 5.6 documentation (local help file) can be downloaded from here
if you haven't got it already:
http://msdn.microsoft.com/downloads/list/webdev.asp
 
On Fri, 06 Aug 2004 17:01:25 +0200, "Torgeir Bakken \(MVP\)"

Torgeir

you posted a snippet of code to delete a shortcut using a
computer startup script, do you know of a way to add a shortcut this
way for specific users by checking if they belong to a specific OU or
group? If so would you mind posting it?

Thanks in advance....

Robert
 
Back
Top