I'm trying to find out all the network printer shortcuts which target path matches a certain pattern, then do something about them. I came up with this unfinished vbscript:
while this script does find all the shortcuts in the target folder, it fails to extract theTargetPath of the shortcut if it is a network printer shortcut. The value is null. However, if I check the properties of those shortcuts in Explorer, the target is filled with correct information.
Did I miss something?
Set objFS = CreateObject("Scripting.FileSystemObject")
Set objShell = CreateObject("WScript.Shell")
strAllUsersStartup = objShell.SpecialFolders.Item("AllUsersStartup")
Set myRegExp = New RegExp
myRegExp.IgnoreCase = True
myRegExp.Pattern = "^somepattern$"
If (strAllUsersStartup <> "") Then
Set folderAllUsersStartup = objFS.GetFolder(strAllUsersStartup)
For Each objFile in folderAllUsersStartup.Files
WScript.Echo objFile.Type
If (objFile.Type = "Shortcut") Then
Set lnk = objShell.CreateShortcut(objFile.Path)
WScript.Echo lnk.TargetPath
'Do something here
Set lnk = Nothing
End If
Next
Set folderAllUsersStartup = Nothing
End If
Set myRegExp = Nothing
Set objShell = Nothing
Set objFS = Nothingwhile this script does find all the shortcuts in the target folder, it fails to extract theTargetPath of the shortcut if it is a network printer shortcut. The value is null. However, if I check the properties of those shortcuts in Explorer, the target is filled with correct information.
Did I miss something?