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

Posted on 2007-10-19
Last Modified: 2012-05-05
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
    End If
Question by:USBMHC

    Expert Comment

    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"

    Expert Comment

    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\
    LVL 3

    Expert Comment

    the path is empty, the condition on Instr(objItem.Name, "Desktop") is returning false.
    LVL 24

    Accepted Solution

    Just an FYI you can also use group policy.
    Computer Configuration|Administrative Templates|Windows Components|Windows Media Player "Prevent Desktop Shortcut Creation".

    Featured Post

    What Security Threats Are You Missing?

    Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

    Join & Write a Comment

    Sometimes people don't understand why download speed shows differently for Windows than Linux.Specially, this article covers and shows the solution for throughput difference for Windows than a Linux machine. For this, I arranged a test scenario.I…
    Deploying a Microsoft Access application in a Citrix environment is not difficult but takes a few steps. However, Citrix system people are often of little help, as they typically know next to nothing about Access. The script provided here will take …
    This Micro Tutorial will give you a basic overview of Windows DVD Burner through its features and interface. This will be demonstrated using Windows 7 operating system.
    The viewer will learn how to successfully create a multiboot device using the SARDU utility on Windows 7. Start the SARDU utility: Change the image directory to wherever you store your ISOs, this will prevent you from having 2 copies of an ISO wit…

    745 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    17 Experts available now in Live!

    Get 1:1 Help Now