Discussion:
help with logon vbs script
(too old to reply)
t***@gmail.com
2009-03-12 16:54:12 UTC
Permalink
I have the script below which works fine.. however when the DOS prompt
opens up I get two error: access denied messages. Now the script
completely works for the groups posted and attaches the drives and
printers correctly... where am I getting these errors from? Can I
suppress them? Does it have to do with permissions... the users on the
network only are Domain Admins and the respective security group.

Option Explicit
'Declare variables
Dim objNetwork, objUser, CurrentUser
Dim strGroup

' Initialize Groups with Const
Const Accounting_Group = "cn=Accounting"
Const Private_Group = "cn=SM_Private"
Const Public_Group = "cn=SM_Public"
Const Technology_Group = "cn=SM_Technology"
Const Corporate_Group = "cn=SM_Corporate"

' Create objects and extract strGroup values
Set objNetwork = CreateObject("WScript.Network")
Set objUser = CreateObject("ADSystemInfo")
Set CurrentUser = GetObject("LDAP://" & objUser.UserName)

objNetwork.MapNetworkDrive "Q:", "\\server\Data"
objNetwork.MapNetworkDrive "I:", "\\server\Common"

strGroup = LCase(Join(CurrentUser.MemberOf))
' If logic testing strGroup for the values in Const groups
If InStr(strGroup, lcase(Corporate_Group)) Then
objNetwork.MapNetworkDrive "J:", "\\server\Corporate"
objNetwork.AddWindowsPrinterConnection "\\server\Executive-Suite"
objNetwork.SetDefaultPrinter "\\server\Executive-Suite"

ElseIf InStr(strGroup, lcase(Accounting_Group)) Then
objNetwork.MapNetworkDrive "K:", "\\server\Accounting"
objNetwork.AddWindowsPrinterConnection "\\server\Dell1815dn02"
objNetwork.AddWindowsPrinterConnection "\\server\XeroxWC7345"
objNetwork.SetDefaultPrinter "\\server\Dell1815dn02"

ElseIf InStr(strGroup, lcase(Public_Group)) Then
objNetwork.MapNetworkDrive "M:", "\\server\Public_Equity_Market"
objNetwork.AddWindowsPrinterConnection "\\server\1815dn"
objNetwork.AddWindowsPrinterConnection "\\server\XeroxWC4150"
objNetwork.SetDefaultPrinter "\\server\1815dn(trade)"

ElseIf InStr(strGroup, lcase(Private_Group)) Then
objNetwork.MapNetworkDrive "N:", "\\server\Private_Company_Market"
objNetwork.AddWindowsPrinterConnection "\\server\1815dn(trade)"
objNetwork.AddWindowsPrinterConnection "\\server\1815dn(trade)"
objNetwork.SetDefaultPrinter "\\server\1815dn(trade)"

ElseIf InStr(strGroup, lcase(Technology_Group)) Then
objNetwork.MapNetworkDrive "T:", "\\server\Tech"
objNetwork.AddWindowsPrinterConnection "\\server\Technology"
objNetwork.AddWindowsPrinterConnection "\\server\Dell3110"
objNetwork.SetDefaultPrinter "\\server\Technology"


End If

WScript.Quit
Pegasus [MVP]
2009-03-12 17:18:21 UTC
Permalink
Post by t***@gmail.com
I have the script below which works fine.. however when the DOS prompt
opens up I get two error: access denied messages. Now the script
completely works for the groups posted and attaches the drives and
printers correctly... where am I getting these errors from? Can I
suppress them? Does it have to do with permissions... the users on the
network only are Domain Admins and the respective security group.
Option Explicit
'Declare variables
Dim objNetwork, objUser, CurrentUser
Dim strGroup
' Initialize Groups with Const
Const Accounting_Group = "cn=Accounting"
Const Private_Group = "cn=SM_Private"
Const Public_Group = "cn=SM_Public"
Const Technology_Group = "cn=SM_Technology"
Const Corporate_Group = "cn=SM_Corporate"
' Create objects and extract strGroup values
Set objNetwork = CreateObject("WScript.Network")
Set objUser = CreateObject("ADSystemInfo")
Set CurrentUser = GetObject("LDAP://" & objUser.UserName)
objNetwork.MapNetworkDrive "Q:", "\\server\Data"
objNetwork.MapNetworkDrive "I:", "\\server\Common"
strGroup = LCase(Join(CurrentUser.MemberOf))
' If logic testing strGroup for the values in Const groups
If InStr(strGroup, lcase(Corporate_Group)) Then
objNetwork.MapNetworkDrive "J:", "\\server\Corporate"
objNetwork.AddWindowsPrinterConnection "\\server\Executive-Suite"
objNetwork.SetDefaultPrinter "\\server\Executive-Suite"
ElseIf InStr(strGroup, lcase(Accounting_Group)) Then
objNetwork.MapNetworkDrive "K:", "\\server\Accounting"
objNetwork.AddWindowsPrinterConnection "\\server\Dell1815dn02"
objNetwork.AddWindowsPrinterConnection "\\server\XeroxWC7345"
objNetwork.SetDefaultPrinter "\\server\Dell1815dn02"
ElseIf InStr(strGroup, lcase(Public_Group)) Then
objNetwork.MapNetworkDrive "M:", "\\server\Public_Equity_Market"
objNetwork.AddWindowsPrinterConnection "\\server\1815dn"
objNetwork.AddWindowsPrinterConnection "\\server\XeroxWC4150"
objNetwork.SetDefaultPrinter "\\server\1815dn(trade)"
ElseIf InStr(strGroup, lcase(Private_Group)) Then
objNetwork.MapNetworkDrive "N:", "\\server\Private_Company_Market"
objNetwork.AddWindowsPrinterConnection "\\server\1815dn(trade)"
objNetwork.AddWindowsPrinterConnection "\\server\1815dn(trade)"
objNetwork.SetDefaultPrinter "\\server\1815dn(trade)"
ElseIf InStr(strGroup, lcase(Technology_Group)) Then
objNetwork.MapNetworkDrive "T:", "\\server\Tech"
objNetwork.AddWindowsPrinterConnection "\\server\Technology"
objNetwork.AddWindowsPrinterConnection "\\server\Dell3110"
objNetwork.SetDefaultPrinter "\\server\Technology"
End If
WScript.Quit
Yes, this error message is related to permissions. You need to perform a
little bit of trouble shooting to find out where the problem lies. You could
do it like so:

Option Explicit
'Declare variables
Dim objNetwork, objUser, CurrentUser
Dim strGroup

' Initialize Groups with Const
Const Accounting_Group = "cn=Accounting"
Const Private_Group = "cn=SM_Private"
Const Public_Group = "cn=SM_Public"
Const Technology_Group = "cn=SM_Technology"
Const Corporate_Group = "cn=SM_Corporate"

' Create objects and extract strGroup values
Set objNetwork = CreateObject("WScript.Network")
Set objUser = CreateObject("ADSystemInfo")
Set CurrentUser = GetObject("LDAP://" & objUser.UserName)

wscript.echo "Label 1"
objNetwork.MapNetworkDrive "Q:", "\\server\Data"
objNetwork.MapNetworkDrive "I:", "\\server\Common"

wscript.echo "Label 2"
strGroup = LCase(Join(CurrentUser.MemberOf))
' If logic testing strGroup for the values in Const groups
If InStr(strGroup, lcase(Corporate_Group)) Then
objNetwork.MapNetworkDrive "J:", "\\server\Corporate"
objNetwork.AddWindowsPrinterConnection "\\server\Executive-Suite"
objNetwork.SetDefaultPrinter "\\server\Executive-Suite"

wscript.echo "Label 3"
ElseIf InStr(strGroup, lcase(Accounting_Group)) Then
objNetwork.MapNetworkDrive "K:", "\\server\Accounting"
objNetwork.AddWindowsPrinterConnection "\\server\Dell1815dn02"
objNetwork.AddWindowsPrinterConnection "\\server\XeroxWC7345"
objNetwork.SetDefaultPrinter "\\server\Dell1815dn02"

wscript.echo "Label 4"
ElseIf InStr(strGroup, lcase(Public_Group)) Then
objNetwork.MapNetworkDrive "M:", "\\server\Public_Equity_Market"
objNetwork.AddWindowsPrinterConnection "\\server\1815dn"
objNetwork.AddWindowsPrinterConnection "\\server\XeroxWC4150"
objNetwork.SetDefaultPrinter "\\server\1815dn(trade)"

wscript.echo "Label 5"
ElseIf InStr(strGroup, lcase(Private_Group)) Then
objNetwork.MapNetworkDrive "N:", "\\server\Private_Company_Market"
objNetwork.AddWindowsPrinterConnection "\\server\1815dn(trade)"
objNetwork.AddWindowsPrinterConnection "\\server\1815dn(trade)"
objNetwork.SetDefaultPrinter "\\server\1815dn(trade)"

wscript.echo "Label 6"
ElseIf InStr(strGroup, lcase(Technology_Group)) Then
objNetwork.MapNetworkDrive "T:", "\\server\Tech"
objNetwork.AddWindowsPrinterConnection "\\server\Technology"
objNetwork.AddWindowsPrinterConnection "\\server\Dell3110"
objNetwork.SetDefaultPrinter "\\server\Technology"
end if

msgbox "End of script"
Richard Mueller [MVP]
2009-03-12 18:07:41 UTC
Permalink
Post by Pegasus [MVP]
Post by t***@gmail.com
I have the script below which works fine.. however when the DOS prompt
opens up I get two error: access denied messages. Now the script
completely works for the groups posted and attaches the drives and
printers correctly... where am I getting these errors from? Can I
suppress them? Does it have to do with permissions... the users on the
network only are Domain Admins and the respective security group.
Option Explicit
'Declare variables
Dim objNetwork, objUser, CurrentUser
Dim strGroup
' Initialize Groups with Const
Const Accounting_Group = "cn=Accounting"
Const Private_Group = "cn=SM_Private"
Const Public_Group = "cn=SM_Public"
Const Technology_Group = "cn=SM_Technology"
Const Corporate_Group = "cn=SM_Corporate"
' Create objects and extract strGroup values
Set objNetwork = CreateObject("WScript.Network")
Set objUser = CreateObject("ADSystemInfo")
Set CurrentUser = GetObject("LDAP://" & objUser.UserName)
objNetwork.MapNetworkDrive "Q:", "\\server\Data"
objNetwork.MapNetworkDrive "I:", "\\server\Common"
strGroup = LCase(Join(CurrentUser.MemberOf))
' If logic testing strGroup for the values in Const groups
If InStr(strGroup, lcase(Corporate_Group)) Then
objNetwork.MapNetworkDrive "J:", "\\server\Corporate"
objNetwork.AddWindowsPrinterConnection "\\server\Executive-Suite"
objNetwork.SetDefaultPrinter "\\server\Executive-Suite"
ElseIf InStr(strGroup, lcase(Accounting_Group)) Then
objNetwork.MapNetworkDrive "K:", "\\server\Accounting"
objNetwork.AddWindowsPrinterConnection "\\server\Dell1815dn02"
objNetwork.AddWindowsPrinterConnection "\\server\XeroxWC7345"
objNetwork.SetDefaultPrinter "\\server\Dell1815dn02"
ElseIf InStr(strGroup, lcase(Public_Group)) Then
objNetwork.MapNetworkDrive "M:", "\\server\Public_Equity_Market"
objNetwork.AddWindowsPrinterConnection "\\server\1815dn"
objNetwork.AddWindowsPrinterConnection "\\server\XeroxWC4150"
objNetwork.SetDefaultPrinter "\\server\1815dn(trade)"
ElseIf InStr(strGroup, lcase(Private_Group)) Then
objNetwork.MapNetworkDrive "N:", "\\server\Private_Company_Market"
objNetwork.AddWindowsPrinterConnection "\\server\1815dn(trade)"
objNetwork.AddWindowsPrinterConnection "\\server\1815dn(trade)"
objNetwork.SetDefaultPrinter "\\server\1815dn(trade)"
ElseIf InStr(strGroup, lcase(Technology_Group)) Then
objNetwork.MapNetworkDrive "T:", "\\server\Tech"
objNetwork.AddWindowsPrinterConnection "\\server\Technology"
objNetwork.AddWindowsPrinterConnection "\\server\Dell3110"
objNetwork.SetDefaultPrinter "\\server\Technology"
End If
WScript.Quit
Yes, this error message is related to permissions. You need to perform a
little bit of trouble shooting to find out where the problem lies. You
Option Explicit
'Declare variables
Dim objNetwork, objUser, CurrentUser
Dim strGroup
' Initialize Groups with Const
Const Accounting_Group = "cn=Accounting"
Const Private_Group = "cn=SM_Private"
Const Public_Group = "cn=SM_Public"
Const Technology_Group = "cn=SM_Technology"
Const Corporate_Group = "cn=SM_Corporate"
' Create objects and extract strGroup values
Set objNetwork = CreateObject("WScript.Network")
Set objUser = CreateObject("ADSystemInfo")
Set CurrentUser = GetObject("LDAP://" & objUser.UserName)
wscript.echo "Label 1"
objNetwork.MapNetworkDrive "Q:", "\\server\Data"
objNetwork.MapNetworkDrive "I:", "\\server\Common"
wscript.echo "Label 2"
strGroup = LCase(Join(CurrentUser.MemberOf))
' If logic testing strGroup for the values in Const groups
If InStr(strGroup, lcase(Corporate_Group)) Then
objNetwork.MapNetworkDrive "J:", "\\server\Corporate"
objNetwork.AddWindowsPrinterConnection "\\server\Executive-Suite"
objNetwork.SetDefaultPrinter "\\server\Executive-Suite"
wscript.echo "Label 3"
ElseIf InStr(strGroup, lcase(Accounting_Group)) Then
objNetwork.MapNetworkDrive "K:", "\\server\Accounting"
objNetwork.AddWindowsPrinterConnection "\\server\Dell1815dn02"
objNetwork.AddWindowsPrinterConnection "\\server\XeroxWC7345"
objNetwork.SetDefaultPrinter "\\server\Dell1815dn02"
wscript.echo "Label 4"
ElseIf InStr(strGroup, lcase(Public_Group)) Then
objNetwork.MapNetworkDrive "M:", "\\server\Public_Equity_Market"
objNetwork.AddWindowsPrinterConnection "\\server\1815dn"
objNetwork.AddWindowsPrinterConnection "\\server\XeroxWC4150"
objNetwork.SetDefaultPrinter "\\server\1815dn(trade)"
wscript.echo "Label 5"
ElseIf InStr(strGroup, lcase(Private_Group)) Then
objNetwork.MapNetworkDrive "N:", "\\server\Private_Company_Market"
objNetwork.AddWindowsPrinterConnection "\\server\1815dn(trade)"
objNetwork.AddWindowsPrinterConnection "\\server\1815dn(trade)"
objNetwork.SetDefaultPrinter "\\server\1815dn(trade)"
wscript.echo "Label 6"
ElseIf InStr(strGroup, lcase(Technology_Group)) Then
objNetwork.MapNetworkDrive "T:", "\\server\Tech"
objNetwork.AddWindowsPrinterConnection "\\server\Technology"
objNetwork.AddWindowsPrinterConnection "\\server\Dell3110"
objNetwork.SetDefaultPrinter "\\server\Technology"
end if
msgbox "End of script"
I would also point out that the following statement will raise an error if
the user is not a member of at least two groups(not counting the "primary"
group):

strGroup = LCase(Join(CurrentUser.MemberOf))

The Join method expects an array, so a type mismatch error results if
CurrentUser.memberOf has no DN's or one DN. A fix would be:
======
Dim arrGroups
On Error Resume Next

arrGroups = objCurrentUser.GetEx("memberOf")

If (Err.Number <> 0) Then

On Error GoTo 0

strGroup = ""

Else

On Error GoTo 0

strGroup = LCase(Join(arrGroups))

End If

======

The GetEx method only raises an error if memberOf has no DN's, and it
returns an array even if there is only one DN (unlike CurrentUser.memberOf
which returns a "String" if there is one DN). Remember, if you see that a
user is a member of two groups in ADUC, memberOf will have only one DN
because one of the groups is the "primary" (generally Domain Users) and is
never included in memberOf.
--
Richard Mueller
MVP Directory Services
Hilltop Lab - http://www.rlmueller.net
--
kayanat
2009-03-18 09:59:06 UTC
Permalink
How to use Logon Script and best freeware? Which is a good freeware i
any or any of them for a logon script and how do they work? Because
have found a few but they create them but they dont work one i click i
and save it as a .vbs file. Also, How do I get it so that I can copy th
script into where it says Logon Script under profiles? Anybody knows
Please Hel

--
kayana
-----------------------------------------------------------------------
kayanat's Profile: http://forums.techarena.in/members/kayanat.ht
View this thread: http://forums.techarena.in/server-scripting/1139356.ht

http://forums.techarena.i
Richard Mueller [MVP]
2009-03-19 02:27:47 UTC
Permalink
How to use Logon Script and best freeware? Which is a good freeware if
any or any of them for a logon script and how do they work? Because i
have found a few but they create them but they dont work one i click it
and save it as a .vbs file. Also, How do I get it so that I can copy the
script into where it says Logon Script under profiles? Anybody knows?
Please Help
Some of your questions may be answered here:

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