Hi

I want to add network printers using vbs

To make it easy to maintain I want to use an ini-file containing information about the available printers.
I was thinking of using AD, but it was difficult to resolve the computers location and their available printers from the information registered in AD.

I have made a script as you can see below, the problem is using a variable as argument to the function AddPrinter??

Can someone please help me.

br,
andler




ini-file

[Location]
NumberOfPrinters=3
Printer0="\\server\printer01"
Printer1="\\server\printer02"
Printer2="\\server\printer03"

----------------------------------------
Vbs-file

NumberOfPrinters = ReadIni("Printers.ini", "Location", "NumberOfPrinters")

For i=0 to NumberOfPrinters-1
strPrinter = ReadIni("Printers.ini", "Location", "Printer"&i)

AddPrinter strPrinter                        ' -> Returns error : "Printername is invalid" Code:80070709
AddPrinter "\\server\printer01"          ' -> Adding the printer successfully

Next


Function AddPrinter(strPrntr)
      objNetwork.AddWindowsPrinterConnection strPrntr
End Function


Function ReadIni(file, section, item)
''''''''''''''''''''''''''''''''''''''''''''
' Purpose:
' Returns a value from an ini file.
' Sample:
' strRes = readini("test.ini", "main", "user")
''''''''''''''''''''''''''''''''''''''''''''

Dim LineKey, line,  ini, intEQpos

item=trim(ucase(item))
section=ucase(section)
ReadIni = ""

If FileSysObj.FileExists( file ) Then
Set ini = FileSysObj.OpenTextFile( file, 1, False)
Do While ini.AtEndOfStream = False
line = Ucase(trim(ini.ReadLine))
If line = "[" & section & "]" Then
line = Trim(ini.ReadLine)

Do While (Left(line, 1) <> "[")
intEQPos = Instr(1,Line,"=")-1
If intEQPos > 0 Then
LineKey = Left(Line,intEQPos)
Else
LineKey = ""
End If

If trim(ucase(LineKey))=item then
ReadIni = trim(Mid(Line, instr(1,Line,"=")+1))
Exit Do
End If

If ini.AtEndOfStream Then exit do
line = trim(ini.ReadLine)
Loop

Exit Do
End If
Loop
ini.Close
End If
End Function

0 Comments   [ + ] Show Comments

Comments

Please log in to comment

Answers

Rating comments in this legacy AppDeploy message board thread won't reorder them,
so that the conversation will remain readable.
0

Found my problem

The problem was quotes inside ini-file

Changed from

[Location]
NumberOfPrinters=3
Printer0="\\server\printer01"
Printer1="\\server\printer02"
Printer2="\\server\printer03"

to
[Location]
NumberOfPrinters=3
Printer0=\\server\printer01
Printer1=\\server\printer02
Printer2=\\server\printer03

and all is working fine :-)

Answered 10/19/2005 by: andler
Orange Belt

Please log in to comment
Answer this question or Comment on this question for clarity