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
Forum rules
Do not post any licensing information in this forum.
Any code longer than three lines should be added as code using the 'Select Code' dropdown menu or attached as a file.
Do not post any licensing information in this forum.
Any code longer than three lines should be added as code using the 'Select Code' dropdown menu or attached as a file.
Deleting an expired shortcut from several remote workstations
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
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