I am trying to make a script that i can easily send to a client to connect to
printers on the network.

So far its gone well and im able to run the script on my computer and
connect to the printer.

But the issue im having is when i have a client come into the network that
are not on the domain, or when i have computers that will never be on the
domain and happen to get reset and lose there privilages to a printer.

How do i add a username and pass into the script so it will authenticate and
allow the computer to connect to the printer?

' PrintersLong.vbs - Windows Logon Script.
' VBScript - Connect a network printer with AddWindowsPrinterConnection
' VBScript - Set Printer to default with SetDefaultPrinter
' Author Eric Heyn http://www.wctv6.com
' Version 1.1 - May 15th 2007
'
------------------------------------------------------------------------------
Dim objNetwork, strUNCPrinter, strTrueName, strPrinterName, strError,
strOption, strTitle
strTitle = "WCTV Printer Connect V1.1"
StrOption = Inputbox ("Select Printer Desired", StrTitle)
If StrOption = 1 Then strTruename = "weather-office"
If StrOption = 1 Then strPrinterName = "HP Weather"
If (StrOption < 1) Or (StrOption > 1) Then strError = "1"
If StrError = 1 Then Msgbox "Invalid Choice please restart", vbOKOnly,
strTitle
If StrError = 1 Then WScript.Quit
strUNCPrinter = "\\" & strTrueName & "\" & strPrintername
Set objNetwork = CreateObject("WScript.Network")
objNetwork.AddWindowsPrinterConnection strUNCPrinter
objNetwork.SetDefaultPrinter strUNCPrinter
Msgbox "Printer :" & strTrueName & ": added as default", vbOKOnly, strTitle
WScript.Quit
' End of Eric's Windows printer script.
' Next Version Add "Make Default? Yes/No"
' Next Version Pull Printer True ShareName and Display It
' Added Msgbox
' Added Title.
' Added Inputbox with HP Printer as 1
' Added Inputbox error message with quit command

RE: Adding Username and password to Printer Connect Script. by Lvdarkwolf

Lvdarkwolf
Wed May 16 13:54:01 CDT 2007

StrUsername = "domain\username"
StrPassword = "password"
StrProfile = "false"

objNetwork.AddWindowsPrinterConnection StrUNCPrinter , StrProfile, StrUser,
StrPassword

Ive tried this method and it doesnt seem to work.

If i do it through windows and it asks me for a password i do the usual
domain\username
password

I dont understand why it wont authenticate and connect the printer.
When i have this code in even if i am already authenticated to something the
script wont run.


Re: Adding Username and password to Printer Connect Script. by Chris

Chris
Thu May 17 03:26:17 CDT 2007

On May 16, 1:54 pm, Lvdarkwolf <Lvdarkw...@discussions.microsoft.com>
wrote:
> StrUsername = "domain\username"
> StrPassword = "password"
> StrProfile = "false"
>
> objNetwork.AddWindowsPrinterConnection StrUNCPrinter , StrProfile, StrUser,
> StrPassword
>
> Ive tried this method and it doesnt seem to work.
>
> If i do it through windows and it asks me for a password i do the usual
> domain\username
> password
>
> I dont understand why it wont authenticate and connect the printer.
> When i have this code in even if i am already authenticated to something the
> script wont run.

You have

objNetwork.AddWindowsPrinterConnection StrUNCPrinter , StrProfile,
StrUser,
StrPassword

Forgot 'name' in 'Username'

objNetwork.AddWindowsPrinterConnection StrUNCPrinter , StrProfile,
StrUsername,
StrPassword


Re: Adding Username and password to Printer Connect Script. by Lvdarkwolf

Lvdarkwolf
Thu May 17 15:13:02 CDT 2007

Yeah i noticed that after i posted, i fixed it but it still didnt work. Im
thinking the corporate IT's have something blocked that wont let it work that
way.

But i found a work around.

If i Mapped a network drive to the server that houses the printers, i am
then able to run the connect to printer scripts without any problem.

For some reason it just wont authenticate if i post the username and
password to the printer connect part.