Need help with a script to remove media player icon from the desktop

I need assistance in writing a script that will remove windows media player shortcut from the desktop. I found this script but it doesn't seem to work.

strComputer = "."

Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")

Set colItems = objWMIService.ExecQuery _
    ("Select * From Win32_ShortcutFile Where FileName = 'Windows Media Player'")

For Each objItem in colItems
    If Instr(objItem.Name, "desktop") Then
        strPath = objItem.Name
        strPath = Replace(strPath, "\", "\\")
        Set colFiles = objWMIService.ExecQuery _
            ("Select * From CIM_Datafile Where Name = '" & strpath & "'")
        For Each objFile in colFiles
            objFile.Delete
        Next
    End If
Next
USBMHCAsked:
Who is Participating?
 
KenneniahCommented:
Just an FYI you can also use group policy.
Computer Configuration|Administrative Templates|Windows Components|Windows Media Player "Prevent Desktop Shortcut Creation".
0
 
xtrossCommented:
Where FileName = 'Windows Media Player'")

Is that what you actually have in the script?  I don't think the FileName for the Shortcut is going to be "Windows Media Player"
0
 
Diophantus32Commented:
Depending on the version of Windows.  It should be the full path.

XP:  C:\Documents and Settings\All Users\Desktop\
Vista:  C:\Users\Public\Public Desktop\
0
 
elissaqpCommented:
the path is empty, the condition on Instr(objItem.Name, "Desktop") is returning false.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.