Windows Vista Forums
Vista Forums Home Join Vista Forums Windows 7 Forum Vista Tutorials Tags
Welcome to Windows Vista Forums. Our forum is dedicated to helping you find solutions with any problems, errors or issues you are experiencing with Windows Vista. The Vista forum also covers news and updates and has an extensive Windows Vista tutorial section that covers a wide range of tips and tricks.

Go Back   Vista Forums > Misc Newsgroups > VB Script

Vista - NT Logon Script Error Checking

Reply
 
Old 10-12-2009   #1 (permalink)
Matthew


 
 

NT Logon Script Error Checking

This should be simple I want to see if the printer exists, if so them
I want to map the printer if not report that it failed.

Code:
On Error Resume Next
Dim strLAPrinter1, objNetwork
strLAPrinter1 = "\\la-fs1\LA-Reception-Printer2"
Set objNetwork = CreateObject("WScript.Network")
Wscript.StdOut.WriteLine "Adding printer connection " & strLAPrinter1
& "...   "
if objNetwork.AddWindowsPrinterConnection strLAPrinter1 <> 0 THEN
objNetwork.AddWindowsPrinterConnection strLAPrinter1
Wscript.StdOut.WriteLine "SUCCESS"
elseif Wscript.StdOut.WriteLine "FAILED"

My System SpecsSystem Spec
Old 10-12-2009   #2 (permalink)
Richard Mueller [MVP]


 
 

Re: NT Logon Script Error Checking


"Matthew" <mkruer@newsgroup> wrote in message
news:6960b036-805f-4108-84b7-d72f392dc9a7@newsgroup
Quote:

> This should be simple I want to see if the printer exists, if so them
> I want to map the printer if not report that it failed.
>
>
Code:
> On Error Resume Next
> Dim strLAPrinter1, objNetwork
> strLAPrinter1 = "\\la-fs1\LA-Reception-Printer2"
> Set objNetwork = CreateObject("WScript.Network")
> Wscript.StdOut.WriteLine "Adding printer connection " & strLAPrinter1
> & "...   "
> if objNetwork.AddWindowsPrinterConnection strLAPrinter1 <> 0 THEN
> objNetwork.AddWindowsPrinterConnection strLAPrinter1
> Wscript.StdOut.WriteLine "SUCCESS"
> elseif Wscript.StdOut.WriteLine "FAILED"
>
Several problems. First, there is no End If. Second, the
AddWindowsPrinterConnection method is a subroutine that does not return
values, so you need to test the Err object's Number property to check if
there was an error. Third, if the printer mapping fails you seem to make a
second attempt, but then report "Success". I would suggest:
========
Dim strLAPrinter1, objNetwork

strLAPrinter1 = "\\la-fs1\LA-Reception-Printer2"
Set objNetwork = CreateObject("WScript.Network")

Wscript.StdOut.WriteLine "Adding printer connection " & strLAPrinter1 & "...
"
On Error Resume Next
objNetwork.AddWindowsPrinterConnection strLAPrinter1
If (Err.Number = 0) Then
On Error GoTo 0
Wscript.StdOut.WriteLine "SUCCESS"
Else
On Error GoTo 0
Wscript.StdOut.WriteLine "FAILED"
End If
=========
If the printer is not found, there will be a long timeout, but I don't know
how to avoid that.

--
Richard Mueller
MVP Directory Services
Hilltop Lab - http://www.rlmueller.net
--


My System SpecsSystem Spec
Old 10-12-2009   #3 (permalink)
Matthew


 
 

Re: NT Logon Script Error Checking

Thanks for the feedback. Its been two years since I have done any VBS,
so I totally forgot all the rules. Thanks for pointing me in the right
direction.

On Oct 12, 5:19*pm, "Richard Mueller [MVP]" <rlmueller-
nos...@newsgroup> wrote:
Quote:

> "Matthew" <mkr...@newsgroup> wrote in message
>
> news:6960b036-805f-4108-84b7-d72f392dc9a7@newsgroup
>
Quote:

> > This should be simple I want toseeiftheprinterexists,ifso them
> > I want to map theprinterifnot report that it failed.
>
Quote:

> >
Code:
> > On Error Resume Next
> > Dim strLAPrinter1, objNetwork
> > strLAPrinter1 = "\\la-fs1\LA-Reception-Printer2"
> > Set objNetwork = CreateObject("WScript.Network")
> > Wscript.StdOut.WriteLine "Addingprinterconnection " & strLAPrinter1
> > & "... * "
> >ifobjNetwork.AddWindowsPrinterConnection strLAPrinter1 <> 0 THEN
> > objNetwork.AddWindowsPrinterConnection strLAPrinter1
> > Wscript.StdOut.WriteLine "SUCCESS"
> > elseif Wscript.StdOut.WriteLine "FAILED"
> >
>
> Several problems. First, there is no EndIf. Second, the
> AddWindowsPrinterConnection method is a subroutine that does not return
> values, so you need to test the Err object's Number property tocheckif
> there was an error. Third,iftheprintermapping fails you seem to make a
> second attempt, but then report "Success". I would suggest:
> ========
> Dim strLAPrinter1, objNetwork
>
> strLAPrinter1 = "\\la-fs1\LA-Reception-Printer2"
> Set objNetwork = CreateObject("WScript.Network")
>
> Wscript.StdOut.WriteLine "Addingprinterconnection " & strLAPrinter1 & "....
> "
> On Error Resume Next
> objNetwork.AddWindowsPrinterConnection strLAPrinter1If(Err.Number = 0) Then
> * * On Error GoTo 0
> * * Wscript.StdOut.WriteLine "SUCCESS"
> Else
> * * On Error GoTo 0
> * * Wscript.StdOut.WriteLine "FAILED"
> EndIf
> =========Iftheprinteris not found, there will be a longtimeout, but I don't know
> how to avoid that.
>
> --
> Richard Mueller
> MVP Directory Services
> Hilltop Lab -http://www.rlmueller.net
> --
My System SpecsSystem Spec
Old 10-13-2009   #4 (permalink)
Matthew


 
 

Re: NT Logon Script Error Checking

This should work,

Code:
Option Explicit
strPrinterArray = Array()
ReDim  strPrinterArray(2)
strPrinterArray(0) = "\\la-fs1\LA-Reception-Printer"
strPrinterArray(1) = "\\la-ad1\Front"
strPrinterArray(2) = "\\la-ad1\Boardroom"

Dim intCounter
intCounter = 0

'Main Add Printer Loop
For Each objFile in strPrinterArray
Wscript.StdOut.Write "Adding printer connection " & strPrinterArray
(intCounter) & "...   "
On Error Resume Next
'Add Printer
objNetwork.AddWindowsPrinterConnection strPrinterArray(intCounter)
'If Successful, Note Success
If (Err.Number = 0) Then
On Error GoTo 0
Wscript.StdOut.WriteLine "SUCCESS"
'If NOT Successful, Note Failure
Else
On Error GoTo 0
Wscript.StdOut.WriteLine "FAILED"
End If
intCounter = intCounter + 1
next
Is there a elegant way in an array to specify in an array to map a
printer or network share or anything else based upon AD permissions. I
am on a multidomain environment, and trying to re-gear the script into
a single one. If in LA, and part of this group, map this resource.

I guess the array should read something like strPrinterArray(0) =
("ou=LA", "cn=Domain Administrators", "\\la-fs1\LA-Reception-
Printer"')
So if a the printer only would map for a LA Domain Admin.

-Matt-

On Oct 12, 5:29*pm, Matthew <mkr...@newsgroup> wrote:
Quote:

> Thanks for the feedback. Its been two years since I have done any VBS,
> so I totally forgot all the rules. Thanks for pointing me in the right
> direction.
>
> On Oct 12, 5:19*pm, "Richard Mueller [MVP]" <rlmueller-
>
> nos...@newsgroup> wrote:
Quote:

> > "Matthew" <mkr...@newsgroup> wrote in message
>
Quote:

> >news:6960b036-805f-4108-84b7-d72f392dc9a7@newsgroup
>
Quote:
Quote:

> > > This should be simple I want toseeiftheprinterexists,ifso them
> > > I want to map theprinterifnot report that it failed.
>
Quote:
Quote:

> > >
Code:
> > > On Error Resume Next
> > > Dim strLAPrinter1, objNetwork
> > > strLAPrinter1 = "\\la-fs1\LA-Reception-Printer2"
> > > Set objNetwork = CreateObject("WScript.Network")
> > > Wscript.StdOut.WriteLine "Addingprinterconnection " & strLAPrinter1
> > > & "... * "
> > >ifobjNetwork.AddWindowsPrinterConnection strLAPrinter1 <> 0 THEN
> > > objNetwork.AddWindowsPrinterConnection strLAPrinter1
> > > Wscript.StdOut.WriteLine "SUCCESS"
> > > elseif Wscript.StdOut.WriteLine "FAILED"
> > >
>
Quote:

> > Several problems. First, there is no EndIf. Second, the
> > AddWindowsPrinterConnection method is a subroutine that does not return
> > values, so you need to test the Err object's Number property tocheckif
> > there was an error. Third,iftheprintermapping fails you seem to make a
> > second attempt, but then report "Success". I would suggest:
> > ========
> > Dim strLAPrinter1, objNetwork
>
Quote:

> > strLAPrinter1 = "\\la-fs1\LA-Reception-Printer2"
> > Set objNetwork = CreateObject("WScript.Network")
>
Quote:

> > Wscript.StdOut.WriteLine "Addingprinterconnection " & strLAPrinter1 & "....
> > "
> > On Error Resume Next
> > objNetwork.AddWindowsPrinterConnection strLAPrinter1If(Err.Number = 0) Then
> > * * On Error GoTo 0
> > * * Wscript.StdOut.WriteLine "SUCCESS"
> > Else
> > * * On Error GoTo 0
> > * * Wscript.StdOut.WriteLine "FAILED"
> > EndIf
> > =========Iftheprinteris not found, there will be a long timeout, but I don't know
> > how to avoid that.
>
Quote:

> > --
> > Richard Mueller
> > MVP Directory Services
> > Hilltop Lab -http://www.rlmueller.net
> > --
My System SpecsSystem Spec
Old 10-14-2009   #5 (permalink)
Richard Mueller [MVP]


 
 

Re: NT Logon Script Error Checking

I see a few options. One is to use Group Policy and configure a different
logon script for each OU. This is the way most adminstrators run their logon
scripts. Another option is to check group membership. You can create one
group for each printer.

If there are not too many groups, the easiest way to check group membership
is to bind to the group object and use the IsMember method of the group
object. For example:
============
Option Explicit
Dim objSysInfo, objUser, objGroup, objNetwork

Set objNetwork = CreateObject("Wscript.Network")

' Bind to the current user object.
Set objSysInfo = CreateObject("ADSystemInfo")
Set objUser = GetObject("LDAP://" & objSysInfo.UserName)

' Bind to group.
Set objGroup = GetObject("LDAP://cn=Test Group,ou=West,dc=MyDomain,dc=com")
' Check for membership.
If (objGroup.IsMember(objUser.AdsPath) = True) Then
' User is a member of the group, map appropriate printer.
objNetwork.AddWindowsPrinterConnection "\\la-fs1\LA-Reception-Printer"
End If
==========
If there are more than 2 or 3 groups to be checked, it would be more
efficient to enumerate all groups the user is a member of and populate a
dictionary object. It is very easy to use the Exists method of a dictionary
object to check memberships. For example:
========
Option Explicit
Dim objSysInfo, objUser, objGroup, objNetwork
Dim objList

Set objNetwork = CreateObject("Wscript.Network")

' Bind to the current user object.
Set objSysInfo = CreateObject("ADSystemInfo")
Set objUser = GetObject("LDAP://" & objSysInfo.UserName)

' Setup dictionary object of group membership.
Set objList = CreateObject("Scripting.Dictionary")
objList.CompareMode = vbTextCompare

' Enumerate direct group memberships of current user.
For Each objGroup In objUser.Groups
objList.Add objGroup.sAMAccountName, True
Next

' Check group membership.
If (objList.Exists("TestGroup") = True) Then
' User is a member of the group, map appropriate printer.
objNetwork.AddWindowsPrinterConnection "\\la-fs1\LA-Reception-Printer"
End If
===========
The above assumes you are only concerned with direct group membership, so
you can ignore membership due to group nesting. For general logon script
recommendations and methods to check group membership, see this link:

http://www.rlmueller.net/LogonScriptGuidelines.htm

Per this linked page, if users are members of many groups (and you don't
care about group nesting), the most efficient method is to enumerate the
memberOf attribute of the user. The Groups method of the user object, as
used above, binds to each group object, which is slow. Enumerating the
memberOf attribute will be much faster. Example code is in the link.

Finally, it sometimes makes sense to map printers according to computer
group membership, rather than user group membership. This is better in cases
where users roam, but computers do not. You can easily bind to the local
computer object with code similar to:
========
Option Explicit
Dim objSysInfo, objComputer

' Bind to the local computer user object.
Set objSysInfo = CreateObject("ADSystemInfo")
Set objComputer = GetObject("LDAP://" & objSysInfo.ComputerName)
==========
There is no built in way to check which OU a user object resides in. If you
want to map resources based on the OU, the only reliable method is to
compare the DN of the OU to the Parent of the user. In brief:
============
' Check if user in Admin OU.
If (UCase(objUser.Parent) = "ldap://ou=sales ou,ou=west,dc=mydomain,dc=com")
Then
objNetwork.AddWindowsPrinterConnection "\\la-fs1\LA-Reception-Printer"
End If
==========
You can also parse the DN of the user object, but that can be tricky.

--
Richard Mueller
MVP Directory Services
Hilltop Lab - http://www.rlmueller.net
--

"Matthew" <mkruer@newsgroup> wrote in message
news:2854662b-6c8c-4f7f-8355-dbfa7caf8f10@newsgroup
This should work,

Code:
Option Explicit
strPrinterArray = Array()
ReDim  strPrinterArray(2)
strPrinterArray(0) = "\\la-fs1\LA-Reception-Printer"
strPrinterArray(1) = "\\la-ad1\Front"
strPrinterArray(2) = "\\la-ad1\Boardroom"

Dim intCounter
intCounter = 0

'Main Add Printer Loop
For Each objFile in strPrinterArray
Wscript.StdOut.Write "Adding printer connection " & strPrinterArray
(intCounter) & "...   "
On Error Resume Next
'Add Printer
objNetwork.AddWindowsPrinterConnection strPrinterArray(intCounter)
'If Successful, Note Success
If (Err.Number = 0) Then
On Error GoTo 0
Wscript.StdOut.WriteLine "SUCCESS"
'If NOT Successful, Note Failure
Else
On Error GoTo 0
Wscript.StdOut.WriteLine "FAILED"
End If
intCounter = intCounter + 1
next
Is there a elegant way in an array to specify in an array to map a
printer or network share or anything else based upon AD permissions. I
am on a multidomain environment, and trying to re-gear the script into
a single one. If in LA, and part of this group, map this resource.

I guess the array should read something like strPrinterArray(0) =
("ou=LA", "cn=Domain Administrators", "\\la-fs1\LA-Reception-
Printer"')
So if a the printer only would map for a LA Domain Admin.

-Matt-

On Oct 12, 5:29 pm, Matthew <mkr...@newsgroup> wrote:
Quote:

> Thanks for the feedback. Its been two years since I have done any VBS,
> so I totally forgot all the rules. Thanks for pointing me in the right
> direction.
>
> On Oct 12, 5:19 pm, "Richard Mueller [MVP]" <rlmueller-
>
> nos...@newsgroup> wrote:
Quote:

> > "Matthew" <mkr...@newsgroup> wrote in message
>
Quote:

> >news:6960b036-805f-4108-84b7-d72f392dc9a7@newsgroup
>
Quote:
Quote:

> > > This should be simple I want toseeiftheprinterexists,ifso them
> > > I want to map theprinterifnot report that it failed.
>
Quote:
Quote:

> > >
Code:
> > > On Error Resume Next
> > > Dim strLAPrinter1, objNetwork
> > > strLAPrinter1 = "\\la-fs1\LA-Reception-Printer2"
> > > Set objNetwork = CreateObject("WScript.Network")
> > > Wscript.StdOut.WriteLine "Addingprinterconnection " & strLAPrinter1
> > > & "... "
> > >ifobjNetwork.AddWindowsPrinterConnection strLAPrinter1 <> 0 THEN
> > > objNetwork.AddWindowsPrinterConnection strLAPrinter1
> > > Wscript.StdOut.WriteLine "SUCCESS"
> > > elseif Wscript.StdOut.WriteLine "FAILED"
> > >
>
Quote:

> > Several problems. First, there is no EndIf. Second, the
> > AddWindowsPrinterConnection method is a subroutine that does not return
> > values, so you need to test the Err object's Number property tocheckif
> > there was an error. Third,iftheprintermapping fails you seem to make a
> > second attempt, but then report "Success". I would suggest:
> > ========
> > Dim strLAPrinter1, objNetwork
>
Quote:

> > strLAPrinter1 = "\\la-fs1\LA-Reception-Printer2"
> > Set objNetwork = CreateObject("WScript.Network")
>
Quote:

> > Wscript.StdOut.WriteLine "Addingprinterconnection " & strLAPrinter1 &
> > "...
> > "
> > On Error Resume Next
> > objNetwork.AddWindowsPrinterConnection strLAPrinter1If(Err.Number = 0)
> > Then
> > On Error GoTo 0
> > Wscript.StdOut.WriteLine "SUCCESS"
> > Else
> > On Error GoTo 0
> > Wscript.StdOut.WriteLine "FAILED"
> > EndIf
> > =========Iftheprinteris not found, there will be a long timeout, but I
> > don't know
> > how to avoid that.
>
Quote:

> > --
> > Richard Mueller
> > MVP Directory Services
> > Hilltop Lab -http://www.rlmueller.net
> > --

My System SpecsSystem Spec
Old 10-14-2009   #6 (permalink)
Matthew


 
 

Re: NT Logon Script Error Checking

Yeah I ran across that example. I was hoping to that I could specify
in the array a multiple criteria that had to be met, and make a nested
if statement, but it looks like i have to use multiple arrays. I guess
is more syntactical then anything else, just find reading back the
array like this

strPrinterArray(0) = "CN=Domain Admins", "\\la-fs1\LA-Reception-
Printer"
strPrinterArray(1) = "CN=Domain Users", "\\la-ad1\Front"
strPrinterArray(2) = "CN=Domain Users", "\\la-ad1\Boardroom"

is easier then

strPrinterArray(0,0) = "CN=Domain Admins"
strPrinterArray(0,1) = "CN=Domain Users"
strPrinterArray(0,2) = "CN=Domain Users"

strPrinterArray(1,0) = "\\la-fs1\LA-Reception-Printer"
strPrinterArray(1,1) = "\\la-ad1\Front"
strPrinterArray(1,2) = "\\la-ad1\Boardroom"

Thanks for the help

-Matt-

On Oct 14, 9:43*am, "Richard Mueller [MVP]" <rlmueller-
nos...@newsgroup> wrote:
Quote:

> I see a few options. One is to use Group Policy and configure a different
> logon script for each OU. This is the way most adminstrators run their logon
> scripts. Another option is to check group membership. You can create one
> group for each printer.
>
> If there are not too many groups, the easiest way to check group membership
> is to bind to the group object and use the IsMember method of the group
> object. For example:
> ============
> Option Explicit
> Dim objSysInfo, objUser, objGroup, objNetwork
>
> Set objNetwork = CreateObject("Wscript.Network")
>
> ' Bind to the current user object.
> Set objSysInfo = CreateObject("ADSystemInfo")
> Set objUser = GetObject("LDAP://" & objSysInfo.UserName)
>
> ' Bind to group.
> Set objGroup = GetObject("LDAP://cn=Test Group,ou=West,dc=MyDomain,dc=com")
> ' Check for membership.
> If (objGroup.IsMember(objUser.AdsPath) = True) Then
> * * ' User is a member of the group, map appropriate printer.
> * * objNetwork.AddWindowsPrinterConnection "\\la-fs1\LA-Reception-Printer"
> End If
> ==========
> If there are more than 2 or 3 groups to be checked, it would be more
> efficient to enumerate all groups the user is a member of and populate a
> dictionary object. It is very easy to use the Exists method of a dictionary
> object to check memberships. For example:
> ========
> Option Explicit
> Dim objSysInfo, objUser, objGroup, objNetwork
> Dim objList
>
> Set objNetwork = CreateObject("Wscript.Network")
>
> ' Bind to the current user object.
> Set objSysInfo = CreateObject("ADSystemInfo")
> Set objUser = GetObject("LDAP://" & objSysInfo.UserName)
>
> ' Setup dictionary object of group membership.
> Set objList = CreateObject("Scripting.Dictionary")
> objList.CompareMode = vbTextCompare
>
> ' Enumerate direct group memberships of current user.
> For Each objGroup In objUser.Groups
> * * objList.Add objGroup.sAMAccountName, True
> Next
>
> ' Check group membership.
> If (objList.Exists("TestGroup") = True) Then
> * * ' User is a member of the group, map appropriate printer.
> * * objNetwork.AddWindowsPrinterConnection "\\la-fs1\LA-Reception-Printer"
> End If
> ===========
> The above assumes you are only concerned with direct group membership, so
> you can ignore membership due to group nesting. For general logon script
> recommendations and methods to check group membership, see this link:
>
> http://www.rlmueller.net/LogonScriptGuidelines.htm
>
> Per this linked page, if users are members of many groups (and you don't
> care about group nesting), the most efficient method is to enumerate the
> memberOf attribute of the user. The Groups method of the user object, as
> used above, binds to each group object, which is slow. Enumerating the
> memberOf attribute will be much faster. Example code is in the link.
>
> Finally, it sometimes makes sense to map printers according to computer
> group membership, rather than user group membership. This is better in cases
> where users roam, but computers do not. You can easily bind to the local
> computer object with code similar to:
> ========
> Option Explicit
> Dim objSysInfo, objComputer
>
> ' Bind to the local computer user object.
> Set objSysInfo = CreateObject("ADSystemInfo")
> Set objComputer = GetObject("LDAP://" & objSysInfo.ComputerName)
> ==========
> There is no built in way to check which OU a user object resides in. If you
> want to map resources based on the OU, the only reliable method is to
> compare the DN of the OU to the Parent of the user. In brief:
> ============
> ' Check if user in Admin OU.
> If (UCase(objUser.Parent) = "ldap://ou=sales ou,ou=west,dc=mydomain,dc=com")
> Then
> * * objNetwork.AddWindowsPrinterConnection "\\la-fs1\LA-Reception-Printer"
> End If
> ==========
> You can also parse the DN of the user object, but that can be tricky.
>
> --
> Richard Mueller
> MVP Directory Services
> Hilltop Lab -http://www.rlmueller.net
> --
>
> "Matthew" <mkr...@newsgroup> wrote in message
>
> news:2854662b-6c8c-4f7f-8355-dbfa7caf8f10@newsgroup
> This should work,
>
>
Code:
> Option Explicit
> strPrinterArray = Array()
> ReDim *strPrinterArray(2)
> strPrinterArray(0) = "\\la-fs1\LA-Reception-Printer"
> strPrinterArray(1) = "\\la-ad1\Front"
> strPrinterArray(2) = "\\la-ad1\Boardroom"
>
> Dim intCounter
> intCounter = 0
>
> 'Main Add Printer Loop
> For Each objFile in strPrinterArray
> Wscript.StdOut.Write "Adding printer connection " & strPrinterArray
> (intCounter) & "... * "
> On Error Resume Next
> 'Add Printer
> objNetwork.AddWindowsPrinterConnection strPrinterArray(intCounter)
> 'If Successful, Note Success
> If (Err.Number = 0) Then
> On Error GoTo 0
> Wscript.StdOut.WriteLine "SUCCESS"
> 'If NOT Successful, Note Failure
> Else
> On Error GoTo 0
> Wscript.StdOut.WriteLine "FAILED"
> End If
> intCounter = intCounter + 1
> next
>
>
> Is there a elegant way in an array to specify in an array to map a
> printer or network share or anything else based upon AD permissions. I
> am on a multidomain environment, and trying to re-gear the script into
> a single one. If in LA, and part of this group, map this resource.
>
> I guess the array should read something like strPrinterArray(0) =
> ("ou=LA", "cn=Domain Administrators", "\\la-fs1\LA-Reception-
> Printer"')
> So if a the printer only would map for a LA Domain Admin.
>
> -Matt-
>
> On Oct 12, 5:29 pm, Matthew <mkr...@newsgroup> wrote:
>
Quote:

> > Thanks for the feedback. Its been two years since I have done any VBS,
> > so I totally forgot all the rules. Thanks for pointing me in the right
> > direction.
>
Quote:

> > On Oct 12, 5:19 pm, "Richard Mueller [MVP]" <rlmueller-
>
Quote:

> > nos...@newsgroup> wrote:
Quote:

> > > "Matthew" <mkr...@newsgroup> wrote in message
>
Quote:
Quote:

> > >news:6960b036-805f-4108-84b7-d72f392dc9a7@newsgroup
>
Quote:
Quote:

> > > > This should be simple I want toseeiftheprinterexists,ifso them
> > > > I want to map theprinterifnot report that it failed.
>
Quote:
Quote:

> > > >
Code:
> > > > On Error Resume Next
> > > > Dim strLAPrinter1, objNetwork
> > > > strLAPrinter1 = "\\la-fs1\LA-Reception-Printer2"
> > > > Set objNetwork = CreateObject("WScript.Network")
> > > > Wscript.StdOut.WriteLine "Addingprinterconnection " & strLAPrinter1
> > > > & "... "
> > > >ifobjNetwork.AddWindowsPrinterConnection strLAPrinter1 <> 0 THEN
> > > > objNetwork.AddWindowsPrinterConnection strLAPrinter1
> > > > Wscript.StdOut.WriteLine "SUCCESS"
> > > > elseif Wscript.StdOut.WriteLine "FAILED"
> > > >
>
Quote:
Quote:

> > > Several problems. First, there is no EndIf. Second, the
> > > AddWindowsPrinterConnection method is a subroutine that does not return
> > > values, so you need to test the Err object's Number property tocheckif
> > > there was an error. Third,iftheprintermapping fails you seem to make a
> > > second attempt, but then report "Success". I would suggest:
> > > ========
> > > Dim strLAPrinter1, objNetwork
>
Quote:
Quote:

> > > strLAPrinter1 = "\\la-fs1\LA-Reception-Printer2"
> > > Set objNetwork = CreateObject("WScript.Network")
>
Quote:
Quote:

> > > Wscript.StdOut.WriteLine "Addingprinterconnection " & strLAPrinter1 &
> > > "...
> > > "
> > > On Error Resume Next
> > > objNetwork.AddWindowsPrinterConnection strLAPrinter1If(Err.Number =0)
> > > Then
> > > On Error GoTo 0
> > > Wscript.StdOut.WriteLine "SUCCESS"
> > > Else
> > > On Error GoTo 0
> > > Wscript.StdOut.WriteLine "FAILED"
> > > EndIf
> > > =========Iftheprinteris not found, there will be a long timeout, but I
> > > don't know
> > > how to avoid that.
>
Quote:
Quote:

> > > --
> > > Richard Mueller
> > > MVP Directory Services
> > > Hilltop Lab -http://www.rlmueller.net
> > > --
My System SpecsSystem Spec
Reply

Thread Tools


Similar Threads
Thread Forum
Map network drive via logon script and launchapp.wsf error in scri Vista networking & sharing
Logon Script Causing Laptops To Hang - Problems in script? VB Script
Help with Logon script error VB Script
Error checking with WMI Lastreboot script PowerShell
Send-FTP Script with Error Checking? PowerShell


Vista Forums is an independent web site and has not been authorized,
sponsored, or otherwise approved by Microsoft Corporation.
"Windows Vista", the Start Orb, and related materials are trademarks of Microsoft Corp.
© Designer Media Ltd

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46