/build/static/layout/Breadcrumb_cap_w.png

Scripting Question


Adding printers using VBscript

10/19/2005 6562 views
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


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

All Answers

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

Don't be a Stranger!

Sign up today to participate, stay informed, earn points and establish a reputation for yourself!

Sign up! or login

View more:

Share

 
This website uses cookies. By continuing to use this site and/or clicking the "Accept" button you are providing consent Quest Software and its affiliates do NOT sell the Personal Data you provide to us either when you register on our websites or when you do business with us. For more information about our Privacy Policy and our data protection efforts, please visit GDPR-HQ