troubleshooting Question

How to read target path of printer link with Visual Basic Script

Avatar of itnifl
itniflFlag for Norway asked on
Scripting LanguagesMicrosoft Legacy OSVB Script
32 Comments1 Solution1200 ViewsLast Modified:
The code below receives a printer link file path as an argument to the script, it then reads the link files target path and tries to connect to the printer that the target path points to. However, reading the link targetpath only works for a directory link and I assume a file link also. With the code below, I can't seem to be able to read the target path of a link that links to a printer. Does anyone here know how to do it?

Option Explicit
Dim strLinkFullname, strShortcut, strShortTarget, objNetwork, oShell

Set oShell = wscript.createObject("wscript.shell")
Set objNetwork = CreateObject("WScript.Network") 

strLinkFullname = WScript.Arguments(0)
Set strShortcut = oShell.CreateShortcut(strLinkFullname)
strShortTarget = strShortcut.TargetPath

Wscript.Echo "Trying to connect the printer: " & strShortTarget

objNetwork.AddWindowsPrinterConnection strShortTarget
ASKER CERTIFIED SOLUTION
Join our community to see this answer!
Unlock 1 Answer and 32 Comments.
Start Free Trial
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 32 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros