Page 1 of 1

Deleting an expired shortcut from several remote workstations

Posted: Fri Jan 11, 2013 12:21 am
by operez
I need to delete an expired shortcut icon from several remote computers. I will be reading a text file with each workstation’s IP address and performing the following function. To test my logic I was running this script with just one IP address, but it doesn’t seem to find anything, even though if I do a search of this workstation's profile folder it finds three shortcuts, one in the administrator’s folder and the other two in two user folders.

Could someone please look at this and tell me where I went wrong?


DeleteExpiredShortcuts "10.227.201.261","Lotus Notes 6.4"

Function DeleteExpiredShortcuts(strComputer,strShortcut)
  Set objWMIService = GetObject("winmgmts:" & strComputer & "rootcimv2")

  Set colItems = objWMIService.ExecQuery _
    ("Select * From Win32_ShortcutFile Where FileName = '" & strShortcut & "'")

  For Each objItem in colItems
    If Instr(LCase(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
        WScript.Echo "Deleting " & objFile.Name
        'objFile.Delete
      Next
    End If
  Next
  strComputer = ""
  strShortcut = ""
End Function

Thank you in advance.

Deleting an expired shortcut from several remote workstations

Posted: Fri Jan 11, 2013 10:03 am
by jvierra
Some profiles are in All Users Profile and some are in the registry.

Deleting an expired shortcut from several remote workstations

Posted: Fri Jan 11, 2013 10:17 am
by jvierra
Start here:

DeleteExpiredShortcuts "10.227.201.261","Lotus Notes 6.4"

Function DeleteExpiredShortcuts(strComputer,strShortcut)

Set wmi = GetObject("winmgmts:" & strComputer & "rootcimv2")

Set colItems=wmi.ExecQuery("Select * From Win32_ShortcutFile Where FileName = '" & strShortcut & "'")

For Each objItem in colItems
If Instr(LCase(objItem.Name), "desktop") Then
WScript.Echo "Deleting " & objItem.Name
'objItem.Delete
End If
Next

End Function

Deleting an expired shortcut from several remote workstations

Posted: Mon Jan 14, 2013 3:53 am
by operez
Thank you. That seems to have worked.