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
Set objShell = CreateObject("WScript.Shell")
Set objFSO = CreateObject("Scripting.FileSystemObject")
For Each objFile In objFSO.GetFolder(objShell.ExpandEnvironmentStrings("%USERPROFILE%") & "\Start Menu\Printers").Files
objShell.Run objFile.Path, 1, False
Next
Option Explicit
Dim strLinkFullname, objShell, objFSO, objFile
strLinkFullname = WScript.Arguments(0)
Set objShell = CreateObject("WScript.Shell")
Set objFSO = CreateObject("Scripting.FileSystemObject")
For Each objFile In objFSO.GetFolder(strLinkFullname).Files
Wscript.Echo "Reading: " & objFile.Path
objShell.Run objFile.Path, 1, False
Next
Option Explicit
Dim strLinkFolderPath, objShell, objFSO, objFile
strLinkFolderPath = WScript.Arguments(0)
Set objShell = CreateObject("WScript.Shell")
Set objFSO = CreateObject("Scripting.FileSystemObject")
For Each objFile In objFSO.GetFolder(strLinkFolderPath).Files
Wscript.Echo "Reading: " & objFile.Path
objShell.Run objFile.Path, 1, False
Next
Option Explicit
Dim strLinkFolderPath, objShell, objFSO, objFile, strShortPath
strLinkFolderPath = WScript.Arguments(0)
Set objShell = CreateObject("WScript.Shell")
Set objFSO = CreateObject("Scripting.FileSystemObject")
For Each objFile In objFSO.GetFolder(strLinkFolderPath).Files
If LCase(Right(objFile.Name, 4)) = ".lnk" Then
strShortPath = objFSO.GetFile(objFile.Path).ShortPath
Wscript.Echo "Reading: """ & strShortPath & """"
objShell.Run """" & strShortPath & """", 1, False
End If
Next
Option Explicit
Dim strLinkFolderPath, objShell, objFSO, objNetwork, objFile, objShortcut, strContents, strPrinter
If WScript.Arguments.Count = 0 Then
strLinkFolderPath = Replace(WScript.ScriptFullName, WScript.ScriptName, "")
Else
strLinkFolderPath = WScript.Arguments(0)
End If
Set objShell = CreateObject("WScript.Shell")
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objNetwork = CreateObject("WScript.Network")
For Each objFile In objFSO.GetFolder(strLinkFolderPath).Files
If LCase(Right(objFile.Name, 4)) = ".lnk" Then
Set objShortcut = objFSO.OpenTextFile(objFile.Path, 1, False, 0)
strContents = Replace(objShortcut.ReadAll, Chr(0), "")
objShortcut.Close
strPrinter = Mid(strContents, InStrRev(strContents, "\\"))
objNetwork.AddWindowsPrinterConnection strPrinter
End If
Next
Option Explicit
Dim strLinkFolderPath, objShell, objFSO, objNetwork, objFile, objShortcut, strContents, strPrinter, strChr
If WScript.Arguments.Count = 0 Then
strLinkFolderPath = Replace(WScript.ScriptFullName, WScript.ScriptName, "")
Else
strLinkFolderPath = WScript.Arguments(0)
End If
Set objShell = CreateObject("WScript.Shell")
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objNetwork = CreateObject("WScript.Network")
For Each objFile In objFSO.GetFolder(strLinkFolderPath).Files
If LCase(Right(objFile.Name, 4)) = ".lnk" Then
Set objShortcut = objFSO.OpenTextFile(objFile.Path, 1, False, 0)
While Not objShortcut.AtEndOfStream
strChr = objShortcut.Read(1)
'If Asc(strChr) >= 32 And Asc(strChr) <= 126 Then WScript.Echo strChr & ": " & Asc(strChr)
If Asc(strChr) >= 32 And Asc(strChr) <= 126 Then strContents = strContents & strChr
Wend
objShortcut.Close
WScript.Echo vbCrLf & "File: "
WScript.Echo objFile.Name
WScript.Echo vbCrLf & "Contents: "
WScript.Echo strContents
WScript.Echo vbCrLf & "Printer:"
strPrinter = Mid(strContents, InStrRev(strContents, "\\"))
WScript.Echo strPrinter
'objNetwork.AddWindowsPrinterConnection strPrinter
End If
Next
Option Explicit
Dim strLinkFolderPath, objShell, objFSO, objNetwork, objFile, objShortcut, strServer, strContents, strPrinter, strChr, intPos, intEnd, intStart
If WScript.Arguments.Count = 0 Then
strLinkFolderPath = Replace(WScript.ScriptFullName, WScript.ScriptName, "")
Else
strLinkFolderPath = WScript.Arguments(0)
End If
Set objShell = CreateObject("WScript.Shell")
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objNetwork = CreateObject("WScript.Network")
For Each objFile In objFSO.GetFolder(strLinkFolderPath).Files
If LCase(Right(objFile.Name, 4)) = ".lnk" Then
Set objShortcut = objFSO.OpenTextFile(objFile.Path, 1, False, 0)
While Not objShortcut.AtEndOfStream
strChr = objShortcut.Read(1)
'If Asc(strChr) >= 32 And Asc(strChr) <= 126 Then WScript.Echo strChr & ": " & Asc(strChr)
If Asc(strChr) >= 32 And Asc(strChr) <= 126 Then strContents = strContents & strChr
Wend
objShortcut.Close
WScript.Echo vbCrLf & "File: "
WScript.Echo objFile.Name
WScript.Echo vbCrLf & "Contents: "
WScript.Echo strContents
WScript.Echo vbCrLf & "Printer:"
'strPrinter = Mid(strContents, InStrRev(strContents, "\\"))
'WScript.Echo strPrinter
intPos = InStr(strContents, "-1SPS:")
If intPos > 0 Then
intEnd = intPos - 1
intStart = InStrRev(strContents, "-", intEnd)
If intStart > 0 Then
intStart = intStart + 1
strServer = Mid(strContents, intStart, intEnd - intStart + 1)
intPos = InStr(strContents, " C:\Windows\system32\imageres.dll")
If intPos > 0 Then
intEnd = intPos - 1
intStart = InStrRev(strContents, " ", intEnd)
If intStart > 0 Then
intStart = intStart + 1
strPrinter = Mid(strContents, intStart, intEnd - intStart + 1)
WScript.Echo "Would map printer to \\" & strServer & "\" & strPrinter
'objNetwork.AddWindowsPrinterConnection strPrinter
Else
WScript.Echo "Unable to find start of printer name by space in" & Mid(strContents, intEnd - 30, 30)
End If
Else
WScript.Echo "Unable to find end of printer name by C:\Windows\system32\imageres.dll"
End If
Else
WScript.Echo "Unable to find start of server name by hyphen in " & Right(Left(strContents, intEnd), 30)
End If
Else
WScript.Echo "Unable to find string -1SPS: in the link file."
End If
End If
Next
File:
printername - Canon iR C3080.lnk
Contents:
LFX`, :i+00GEntire Network3FMicrosoft Windows NetworkMicrosoft NetworkADomain NameMicro
soft Network*B\\servernameMicrosoft NetworkN'":i+00 printername
Printer:
Unable to find string -1SPS: in the link file.
cscript printer6.vbs O:\
Microsoft (R) Windows Script Host Version 5.6
Copyright (C) Microsoft Corporation 1996-2001. All rights reserved.
File:
xxxxxxC19 - Canon IR.lnk
Contents:
LFX`, :i+00GEntire Network3FMicrosoft Windows NetworkMicrosoft NetworkADomainMicro
soft Network*B\\serverMicrosoft NetworkN'":i+00 printer
Printer:
Unable to find string -1SPS: in the link file.
Would map printer to \\server\printer
Have you tried opening it just with Notepad? Maybe you could just use the FSO to read it as a flat file?
Regards,
Rob.