Deleting an expired shortcut from several remote workstations
Posted: Fri Jan 11, 2013 12:21 am
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.
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.