Link to home
Start Free TrialLog in
Avatar of USBMHC
USBMHC

asked on

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
Avatar of xtross
xtross

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"
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\
the path is empty, the condition on Instr(objItem.Name, "Desktop") is returning false.
ASKER CERTIFIED SOLUTION
Avatar of Kenneniah
Kenneniah

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