Photo Gallery Member List Search Calendars FAQ Ticket List Log Out


[Solved] Printer Addition

 
Logged in as: Guest
arrSession:exec spGetSession 2,2,33657
 Active Users: There are 0 members and 0 guests.
 Users viewing this topic: none
 

 

 
  
  Printable Version
All Forums >> [Scripting] >> WSH & Client Side VBScript >> [Solved] Printer Addition
  Do you like VisualBasicScript.com? Link to us and help spread the word about our forum. Thanks!
Page: [1]
Login
Message << Older Topic   Newer Topic >>
 [Solved] Printer Addition - 4/19/2006 7:30:33 AM   
  scotthawks

 

Posts: 10
Score: 0
Joined: 4/19/2006
Status: offline
I need help with adding a printer in comparison to the net use command in dos.  here is what i use now in dos command:

net use lpt3 \\servername\printer

i need to know how to do this in vbs script.

thanks in advance for help.

< Message edited by scotthawks -- 4/19/2006 11:43:59 AM >
 
 
Post #: 1
 
 RE: Printer Addition - 4/19/2006 8:40:52 AM   
  scotthawks

 

Posts: 10
Score: 0
Joined: 4/19/2006
Status: offline
OK Figured it out.  now, how do i place a variable in quotaion marks such as follows

WshNetwork.AddPrinterConnection "LPT1", "\\ROM\HP500"

 i need it to look like this

WshNetwork.AddPrinterConnection "strPrtPort" & ", " & strPrtPath

I need  both variable to be in quotes.
thanks

(in reply to scotthawks)
 
 
Post #: 2
 
 RE: Printer Addition - 4/19/2006 8:50:26 AM   
  ehvbs

 

Posts: 2204
Score: 50
Joined: 6/22/2005
From: Germany
Status: offline
Hi scotthawks,

Use >""< (sequence of 2 double quotes) to embed a single double qoute in a (double
quoted) string:

  WshNetwork.AddPrinterConnection """LPT1"", ""\\ROM\HP500"""


(in reply to scotthawks)
 
 
Post #: 3
 
 RE: Printer Addition - 4/19/2006 9:15:00 AM   
  scotthawks

 

Posts: 10
Score: 0
Joined: 4/19/2006
Status: offline
OK.  Here is what i have.  I used the suggested method of double quotes.  here is the actual line of code:

  strPrtPath = """" & strPrtPort & """, ""\\" & strPrtServer & "\" & strPrtShare & """"


objWshNetwork.AddPrinterConnection strPrtPath

the first line creates the string "LPT2", "\\Enterprise\ENG_6500"

when i output the strPrtPath, it shows exactly as it should be. 

however, when i do the 2nd line of code which should look like this with variables assigned

objWshNetwork.AddPrinterConnection "LPT2", "\\Enterprise\ENG_6500"

It give an error message.  am i missing something about this.

(in reply to ehvbs)
 
 
Post #: 4
 
 RE: Printer Addition - 4/19/2006 9:54:23 AM   
  ehvbs

 

Posts: 2204
Score: 50
Joined: 6/22/2005
From: Germany
Status: offline
Hi scotthawks,

(1) What error?

(2) The VBScript docs example:

Set WshNetwork = WScript.CreateObject("WScript.Network")
WshNetwork.AddPrinterConnection "LPT1", "\\Server\Print1"

uses to literal strings - if you want to use variables, this should work:

Set WshNetwork = WScript.CreateObject("WScript.Network")
strPort = "LPT1"
strServer = "\\Server\Print1"
WshNetwork.AddPrinterConnection strPort, strServer 

-- look: no extra quotes!

(in reply to scotthawks)
 
 
Post #: 5
 
 RE: Printer Addition - 4/19/2006 11:35:43 AM   
  scotthawks

 

Posts: 10
Score: 0
Joined: 4/19/2006
Status: offline
i need to mention that these variables are being passed thru a function call

here is the entire function with an example call


'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
'
' Sub:      AddPrinterLPT
'
' Purpose:  Connect to shared network printer
'
' Input:
'           strPrtServerDomain  Domain in which print server is a member
'           strPrtServer        Name of print server
'           strPrtShare         Share name of printer
'
' Output:
'
' Usage:
'           Call AddPrinter ("LPT2", "Mydomain2", "MyPrtSvr2", "Bld1Rm101-HP4050")
'          
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
Private Sub AddPrinterLPT(strPrtPort, strPrtServerDomain, strPrtServer, strPrtShare)

On Error Resume Next

DIM strPrtPath    'Full path to printer share
Dim objPrinter    'Object reference to printer
Dim strMsg        'Message output to user
Dim blnError      'True / False error condition
Dim strPrinter    'Path to Printer
blnError = False

'Build path to printer share
'
strPrinter = "\\" & strPrtServer & "\" & strPrtShare
strPrtPath = """" & strPrtPort & """, """ & strPrinter & """"
Call UserPrompt (strPrtPath)

'Test to see if shared printer exists.
'Proceed if yes, set error condition msg if no.
Set objPrinter = GetObject _
   ("WinNT://" & strPrtServerDomain & "/" & strPrtServer & "/" & strPrtShare)
If IsObject( objPrinter ) AND _
(objPrinter.Name <> "" AND objPrinter.Class = "PrintQueue") Then

    'Different mapping techniques depending on OS version
    If objWshShell.ExpandEnvironmentStrings( "%OS%" ) = "Windows_NT" Then
      Err.Clear
      'Map printer
      objWshNetwork.AddPrinterConnection strPrtPath
      'objWshNetwork.AddPrinterConnection "LPT2", "\\Enterprise\ENG_6500"
    Else
      'Mapping printers for Win9x & ME is a pain and unreliable.
    End If

Else
   blnError = True
End IF

'Check error condition and output appropriate user message
If Err <> 0 OR blnError = True Then
   strMsg = "Unable to connect to network printer. " & vbCrLf & _
            "Please contact the Helpdesk @ ext 291" & vbCrLf & _
            "and ask them to check the " & strPrtServer & " server." & _
            vbCrLf & vbCrLf & _
            "Let them know that you are unable to connect to the '" _
            & strPrtShare & "' printer"
   objWshShell.Popup strMsg,, "Logon Error !", 48
Else
   Call UserPrompt ("Successfully added printer connection to " & strPrtPath)
End If

Set objPrinter = Nothing

End Sub

the error i get is the strMsg that i have defined.

(in reply to scotthawks)
 
 
Post #: 6
 
 RE: Printer Addition - 4/19/2006 11:43:24 AM   
  scotthawks

 

Posts: 10
Score: 0
Joined: 4/19/2006
Status: offline
OK. Made a change to script to echo what you had above, and guess what?  it worked.  how about that. 

Thanks.

(in reply to scotthawks)
 
 
Post #: 7
 
 
 
  

If you found our site useful please link to us <a href="http://www.visualbasicscript.com">VisualBasicScript.com</a>.
All Forums >> [Scripting] >> WSH & Client Side VBScript >> [Solved] Printer Addition Page: [1]
Jump to:





New Messages No New Messages
Hot Topic w/ New Messages Hot Topic w/o New Messages
Locked w/ New Messages Locked w/o New Messages
 Post New Thread
 Reply to Message
 Post New Poll
 Submit Vote
 Delete My Own Post
 Delete My Own Thread
 Rate Posts