Jump to content

Recommended Posts

Posted

Hi All,

 

I want to have a vbscript logon script for domain users. When they login

from client PCs, detect network printers, if it exist, then do nothing, if it

doesn't exist, then add it.

 

Can anybody help me out? Thanks.

 

My code is the following:

 

Option Explicit

 

Dim objNetwork, strNJQAPrinter1, strNJQAPrinter2, strNJQAPrinter3

Dim objPrinter, intDrive

Dim ExistPrinter1, ExistPrinter2, ExistPrinter3

 

strNJQAPrinter1 = "\\server\SHARP AR-M455N PCL6 "

strNJQAPrinter2 = "\\server\Zebra170XiIII Plus #2"

strNJQAPrinter3 = "\\server\Zebra170XiIIIPlus #3"

 

ExistPrinter1 = 0 'Set not exist printer1

ExistPrinter2 = 0 'Set not exist printer2

ExistPrinter3 = 0 'Set not exist printer3

 

' Create a network object

Set objNetwork = CreateObject("WScript.Network")

set objPrinter = objNetwork.EnumPrinterConnections

 

If objPrinter.Count = 0 Then

WScript.Echo "Warning: No Printers connected"

Else

WScript.Echo "Printer Count = " & objPrinter.Count

End IF

 

'Determine printer

For intDrive = 0 To (objPrinter.Count -1) Step 2

 

If objPrinter.Item(intDrive +1) = strNJQAPrinter1 Then

ExistPrinter1 = 1

End IF

 

If objPrinter.Item(intDrive +1) = strNJQAPrinter2 Then

ExistPrinter2 = 1

End IF

 

If objPrinter.Item(intDrive +1) = strNJQAPrinter3 Then

ExistPrinter3 = 1

End IF

 

Next

 

If ExistPrinter1 = 1 Then

WScript.Echo strNJQAPrinter1 & " is exist."

Else

objNetwork.AddWindowsPrinterConnection strNJQAPrinter1

WScript.Echo strNJQAPrinter1 & " is Not exist. Add it."

End IF

 

If ExistPrinter2 = 1 Then

WScript.Echo strNJQAPrinter2 & " is exist."

Else

objNetwork.AddWindowsPrinterConnection strNJQAPrinter2

WScript.Echo strNJQAPrinter2 & " is Not exist. Add it."

End IF

 

If ExistPrinter3 = 1 Then

WScript.Echo strNJQAPrinter3 & " is exist."

Else

objNetwork.AddWindowsPrinterConnection strNJQAPrinter3

WScript.Echo strNJQAPrinter3 & " is Not exist. Add it."

End IF

 

' Set the default printer now

objNetwork.SetDefaultPrinter strNJQAPrinter1

 

 

WScript.Quit

 

' End of printer script.

  • Replies 1
  • Created
  • Last Reply

Popular Days

Guest Lanwench [MVP - Exchange]
Posted

Re: logon script

 

qq <qq@discussions.microsoft.com> wrote:

> Hi All,

>

> I want to have a vbscript logon script for domain users. When they

> login from client PCs, detect network printers, if it exist, then do

> nothing, if it doesn't exist, then add it.

>

> Can anybody help me out? Thanks.

>

 

Seems like this would be better posted in

microsoft.public.windows.scripting.....

 

> My code is the following:

>

> Option Explicit

>

> Dim objNetwork, strNJQAPrinter1, strNJQAPrinter2, strNJQAPrinter3

> Dim objPrinter, intDrive

> Dim ExistPrinter1, ExistPrinter2, ExistPrinter3

>

> strNJQAPrinter1 = "\\server\SHARP AR-M455N PCL6 "

> strNJQAPrinter2 = "\\server\Zebra170XiIII Plus #2"

> strNJQAPrinter3 = "\\server\Zebra170XiIIIPlus #3"

>

> ExistPrinter1 = 0 'Set not exist printer1

> ExistPrinter2 = 0 'Set not exist printer2

> ExistPrinter3 = 0 'Set not exist printer3

>

> ' Create a network object

> Set objNetwork = CreateObject("WScript.Network")

> set objPrinter = objNetwork.EnumPrinterConnections

>

> If objPrinter.Count = 0 Then

> WScript.Echo "Warning: No Printers connected"

> Else

> WScript.Echo "Printer Count = " & objPrinter.Count

> End IF

>

> 'Determine printer

> For intDrive = 0 To (objPrinter.Count -1) Step 2

>

> If objPrinter.Item(intDrive +1) = strNJQAPrinter1 Then

> ExistPrinter1 = 1

> End IF

>

> If objPrinter.Item(intDrive +1) = strNJQAPrinter2 Then

> ExistPrinter2 = 1

> End IF

>

> If objPrinter.Item(intDrive +1) = strNJQAPrinter3 Then

> ExistPrinter3 = 1

> End IF

>

> Next

>

> If ExistPrinter1 = 1 Then

> WScript.Echo strNJQAPrinter1 & " is exist."

> Else

> objNetwork.AddWindowsPrinterConnection strNJQAPrinter1

> WScript.Echo strNJQAPrinter1 & " is Not exist. Add it."

> End IF

>

> If ExistPrinter2 = 1 Then

> WScript.Echo strNJQAPrinter2 & " is exist."

> Else

> objNetwork.AddWindowsPrinterConnection strNJQAPrinter2

> WScript.Echo strNJQAPrinter2 & " is Not exist. Add it."

> End IF

>

> If ExistPrinter3 = 1 Then

> WScript.Echo strNJQAPrinter3 & " is exist."

> Else

> objNetwork.AddWindowsPrinterConnection strNJQAPrinter3

> WScript.Echo strNJQAPrinter3 & " is Not exist. Add it."

> End IF

>

> ' Set the default printer now

> objNetwork.SetDefaultPrinter strNJQAPrinter1

>

>

> WScript.Quit

>

> ' End of printer script.


×
×
  • Create New...