trying to add logon.bat to under the AD users properties ....under Logon
Script field.

I ahve this Vb ...and I am not a VB guy ...can somebody please adddress for
me ...
I want the Logon.bat added Logon Script field to all my users in AD and the
ones which already have it shoudl be ignored.



On Error Resume Next

Const ADS_SCOPE_SUBTREE = 2

Set objConnection = CreateObject("ADODB.Connection")
Set objCommand = CreateObject("ADODB.Command")
objConnection.Provider = "ADsDSOObject"
objConnection.Open "Active Directory Provider"
Set objCommand.ActiveConnection = objConnection

objCommand.Properties("Page Size") = 1000
objCommand.Properties("Searchscope") = ADS_SCOPE_SUBTREE

objCommand.CommandText = _
"SELECT ADsPath FROM 'LDAP://cn=users,dc=lab,dc=local' WHERE
objectCategory='user' "
Set objRecordSet = objCommand.Execute
Const ADS_PROPERTY_APPEND = 3

objUser.PutEx ADS_PROPERTY_APPEND, _
objUser.scriptPath, ("logon.bat")
objUser.SetInfo


Advise Please. Thanks

Re: Add ScriptPath to AD user - [WP] by Richard

Richard
Fri Mar 07 14:01:47 CST 2008

WILDPACKET wrote:

> trying to add logon.bat to under the AD users properties ....under Logon
> Script field.
>
> I ahve this Vb ...and I am not a VB guy ...can somebody please adddress
> for
> me ...
> I want the Logon.bat added Logon Script field to all my users in AD and
> the
> ones which already have it shoudl be ignored.
>
>
>
> On Error Resume Next
>
> Const ADS_SCOPE_SUBTREE = 2
>
> Set objConnection = CreateObject("ADODB.Connection")
> Set objCommand = CreateObject("ADODB.Command")
> objConnection.Provider = "ADsDSOObject"
> objConnection.Open "Active Directory Provider"
> Set objCommand.ActiveConnection = objConnection
>
> objCommand.Properties("Page Size") = 1000
> objCommand.Properties("Searchscope") = ADS_SCOPE_SUBTREE
>
> objCommand.CommandText = _
> "SELECT ADsPath FROM 'LDAP://cn=users,dc=lab,dc=local' WHERE
> objectCategory='user' "
> Set objRecordSet = objCommand.Execute
> Const ADS_PROPERTY_APPEND = 3
>
> objUser.PutEx ADS_PROPERTY_APPEND, _
> objUser.scriptPath, ("logon.bat")
> objUser.SetInfo
>
>
> Advise Please. Thanks
>

I suggest the code below. I added a clause to the query to retrieve users
only if there is no value assigned to the scriptPath attribute. Note you
must enumerate the resulting recordset in a loop, then bind to each user
object (using the value of ADsPath retrieved), assign the value to the
scriptPath attribute, then invoke the SetInfo method to save changes.
==========
Const ADS_SCOPE_SUBTREE = 2

Set objConnection = CreateObject("ADODB.Connection")
Set objCommand = CreateObject("ADODB.Command")
objConnection.Provider = "ADsDSOObject"
objConnection.Open "Active Directory Provider"
Set objCommand.ActiveConnection = objConnection

objCommand.Properties("Page Size") = 1000
objCommand.Properties("Searchscope") = ADS_SCOPE_SUBTREE

objCommand.CommandText = _
"SELECT ADsPath " _
& "FROM 'LDAP://cn=users,dc=lab,dc=local' " _
& "WHERE objectCategory='user' AND NOT scriptPath='*'"
Set objRecordSet = objCommand.Execute

Do Until objRecordSet.EOF
Set objUser = GetObject(objRecordset.Fields("ADsPath").Value)
objUser.scriptPath = "logon.bat"
objUser.SetInfo
objRecordset.MoveNext
Loop

' Clean up.
objRecordset.Close
objConnection.Close

--
Richard Mueller
Microsoft MVP Scripting and ADSI
Hilltop Lab - http://www.rlmueller.net
--



Re: Add ScriptPath to AD user - [WP] by WILDPACKET

WILDPACKET
Fri Mar 07 14:23:01 CST 2008


Richard thanks for your response.

I ran the scriot as is and gives error on Line 24 and says character 5.

Advise Plz.





"Richard Mueller [MVP]" wrote:

> WILDPACKET wrote:
>
> > trying to add logon.bat to under the AD users properties ....under Logon
> > Script field.
> >
> > I ahve this Vb ...and I am not a VB guy ...can somebody please adddress
> > for
> > me ...
> > I want the Logon.bat added Logon Script field to all my users in AD and
> > the
> > ones which already have it shoudl be ignored.
> >
> >
> >
> > On Error Resume Next
> >
> > Const ADS_SCOPE_SUBTREE = 2
> >
> > Set objConnection = CreateObject("ADODB.Connection")
> > Set objCommand = CreateObject("ADODB.Command")
> > objConnection.Provider = "ADsDSOObject"
> > objConnection.Open "Active Directory Provider"
> > Set objCommand.ActiveConnection = objConnection
> >
> > objCommand.Properties("Page Size") = 1000
> > objCommand.Properties("Searchscope") = ADS_SCOPE_SUBTREE
> >
> > objCommand.CommandText = _
> > "SELECT ADsPath FROM 'LDAP://cn=users,dc=lab,dc=local' WHERE
> > objectCategory='user' "
> > Set objRecordSet = objCommand.Execute
> > Const ADS_PROPERTY_APPEND = 3
> >
> > objUser.PutEx ADS_PROPERTY_APPEND, _
> > objUser.scriptPath, ("logon.bat")
> > objUser.SetInfo
> >
> >
> > Advise Please. Thanks
> >
>
> I suggest the code below. I added a clause to the query to retrieve users
> only if there is no value assigned to the scriptPath attribute. Note you
> must enumerate the resulting recordset in a loop, then bind to each user
> object (using the value of ADsPath retrieved), assign the value to the
> scriptPath attribute, then invoke the SetInfo method to save changes.
> ==========
> Const ADS_SCOPE_SUBTREE = 2
>
> Set objConnection = CreateObject("ADODB.Connection")
> Set objCommand = CreateObject("ADODB.Command")
> objConnection.Provider = "ADsDSOObject"
> objConnection.Open "Active Directory Provider"
> Set objCommand.ActiveConnection = objConnection
>
> objCommand.Properties("Page Size") = 1000
> objCommand.Properties("Searchscope") = ADS_SCOPE_SUBTREE
>
> objCommand.CommandText = _
> "SELECT ADsPath " _
> & "FROM 'LDAP://cn=users,dc=lab,dc=local' " _
> & "WHERE objectCategory='user' AND NOT scriptPath='*'"
> Set objRecordSet = objCommand.Execute
>
> Do Until objRecordSet.EOF
> Set objUser = GetObject(objRecordset.Fields("ADsPath").Value)
> objUser.scriptPath = "logon.bat"
> objUser.SetInfo
> objRecordset.MoveNext
> Loop
>
> ' Clean up.
> objRecordset.Close
> objConnection.Close
>
> --
> Richard Mueller
> Microsoft MVP Scripting and ADSI
> Hilltop Lab - http://www.rlmueller.net
> --
>
>
>

Re: Add ScriptPath to AD user - [WP] by baron1211

baron1211
Fri Mar 07 17:08:48 CST 2008

On Mar 7, 12:23=A0pm, WILDPACKET <WILDPAC...@discussions.microsoft.com>
wrote:
> Richard thanks for your response.
>
> I ran the scriot as is and gives error on Line 24 and says character 5.
>
> Advise Plz.
>
>
>
> "Richard Mueller [MVP]" wrote:
> > WILDPACKET wrote:
>
> > > trying to add logon.bat to under the AD users properties ....under Log=
on
> > > Script field.
>
> > > I ahve this Vb ...and I am not a VB guy ...can somebody please adddres=
s
> > > for
> > > me ...
> > > I want the Logon.bat added Logon Script field to all my users in AD an=
d
> > > the
> > > ones which already have it shoudl be ignored.
>
> > > On Error Resume Next
>
> > > Const ADS_SCOPE_SUBTREE =3D 2
>
> > > Set objConnection =3D CreateObject("ADODB.Connection")
> > > Set objCommand =3D =A0 CreateObject("ADODB.Command")
> > > objConnection.Provider =3D "ADsDSOObject"
> > > objConnection.Open "Active Directory Provider"
> > > Set objCommand.ActiveConnection =3D objConnection
>
> > > objCommand.Properties("Page Size") =3D 1000
> > > objCommand.Properties("Searchscope") =3D ADS_SCOPE_SUBTREE
>
> > > objCommand.CommandText =3D _
> > > =A0 =A0"SELECT ADsPath FROM 'LDAP://cn=3Dusers,dc=3Dlab,dc=3Dlocal' WH=
ERE
> > > objectCategory=3D'user' "
> > > Set objRecordSet =3D objCommand.Execute
> > > Const ADS_PROPERTY_APPEND =3D 3
>
> > > objUser.PutEx ADS_PROPERTY_APPEND, _
> > > objUser.scriptPath, ("logon.bat")
> > > objUser.SetInfo
>
> > > Advise Please. =A0Thanks
>
> > I suggest the code below. I added a clause to the query to retrieve user=
s
> > only if there is no value assigned to the scriptPath attribute. Note you=

> > must enumerate the resulting recordset in a loop, then bind to each user=

> > object (using the value of ADsPath retrieved), assign the value to the
> > scriptPath attribute, then invoke the SetInfo method to save changes.
> > =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D
> > Const ADS_SCOPE_SUBTREE =3D 2
>
> > Set objConnection =3D CreateObject("ADODB.Connection")
> > Set objCommand =3D =A0 CreateObject("ADODB.Command")
> > objConnection.Provider =3D "ADsDSOObject"
> > objConnection.Open "Active Directory Provider"
> > Set objCommand.ActiveConnection =3D objConnection
>
> > objCommand.Properties("Page Size") =3D 1000
> > objCommand.Properties("Searchscope") =3D ADS_SCOPE_SUBTREE
>
> > objCommand.CommandText =3D _
> > =A0 =A0 "SELECT ADsPath " _
> > =A0 =A0 & "FROM 'LDAP://cn=3Dusers,dc=3Dlab,dc=3Dlocal' " _
> > =A0 =A0 & "WHERE objectCategory=3D'user' AND NOT scriptPath=3D'*'"
> > Set objRecordSet =3D objCommand.Execute
>
> > Do Until objRecordSet.EOF
> > =A0 =A0 Set objUser =3D GetObject(objRecordset.Fields("ADsPath").Value)
> > =A0 =A0 objUser.scriptPath =3D "logon.bat"
> > =A0 =A0 objUser.SetInfo
> > =A0 =A0 objRecordset.MoveNext
> > Loop
>
> > ' Clean up.
> > objRecordset.Close
> > objConnection.Close
>
> > --
> > Richard Mueller
> > Microsoft MVP Scripting and ADSI
> > Hilltop Lab -http://www.rlmueller.net
> > --- Hide quoted text -
>
> - Show quoted text -

You could try using tis command. It works for my environment


objUser.put "Scriptpath", "Login.bat"

My 2 cents worth.


Re: Add ScriptPath to AD user - [WP] by Richard

Richard
Fri Mar 07 19:24:23 CST 2008

Line 24 in my copy of the script is a blank line near the end (after the
loop, before the clean up). The script runs for me without error. I pasted
it exactly from my post in the newsgroup, except I changed the base of the
search (line 14) to reflect my domain. I only have a few users in the
cn=Users container, but all now show logon.bat on the profile tab in ADUC,
unless they already had a logon script specified. Which line is line 24 in
your copy?

--
Richard Mueller
Microsoft MVP Scripting and ADSI
Hilltop Lab - http://www.rlmueller.net
--

"WILDPACKET" <WILDPACKET@discussions.microsoft.com> wrote in message
news:9CCBF0AD-29AC-4835-ADFC-DE179729E840@microsoft.com...
>
> Richard thanks for your response.
>
> I ran the scriot as is and gives error on Line 24 and says character 5.
>
> Advise Plz.
>
>
>
>
>
> "Richard Mueller [MVP]" wrote:
>
>> WILDPACKET wrote:
>>
>> > trying to add logon.bat to under the AD users properties ....under
>> > Logon
>> > Script field.
>> >
>> > I ahve this Vb ...and I am not a VB guy ...can somebody please adddress
>> > for
>> > me ...
>> > I want the Logon.bat added Logon Script field to all my users in AD and
>> > the
>> > ones which already have it shoudl be ignored.
>> >
>> >
>> >
>> > On Error Resume Next
>> >
>> > Const ADS_SCOPE_SUBTREE = 2
>> >
>> > Set objConnection = CreateObject("ADODB.Connection")
>> > Set objCommand = CreateObject("ADODB.Command")
>> > objConnection.Provider = "ADsDSOObject"
>> > objConnection.Open "Active Directory Provider"
>> > Set objCommand.ActiveConnection = objConnection
>> >
>> > objCommand.Properties("Page Size") = 1000
>> > objCommand.Properties("Searchscope") = ADS_SCOPE_SUBTREE
>> >
>> > objCommand.CommandText = _
>> > "SELECT ADsPath FROM 'LDAP://cn=users,dc=lab,dc=local' WHERE
>> > objectCategory='user' "
>> > Set objRecordSet = objCommand.Execute
>> > Const ADS_PROPERTY_APPEND = 3
>> >
>> > objUser.PutEx ADS_PROPERTY_APPEND, _
>> > objUser.scriptPath, ("logon.bat")
>> > objUser.SetInfo
>> >
>> >
>> > Advise Please. Thanks
>> >
>>
>> I suggest the code below. I added a clause to the query to retrieve users
>> only if there is no value assigned to the scriptPath attribute. Note you
>> must enumerate the resulting recordset in a loop, then bind to each user
>> object (using the value of ADsPath retrieved), assign the value to the
>> scriptPath attribute, then invoke the SetInfo method to save changes.
>> ==========
>> Const ADS_SCOPE_SUBTREE = 2
>>
>> Set objConnection = CreateObject("ADODB.Connection")
>> Set objCommand = CreateObject("ADODB.Command")
>> objConnection.Provider = "ADsDSOObject"
>> objConnection.Open "Active Directory Provider"
>> Set objCommand.ActiveConnection = objConnection
>>
>> objCommand.Properties("Page Size") = 1000
>> objCommand.Properties("Searchscope") = ADS_SCOPE_SUBTREE
>>
>> objCommand.CommandText = _
>> "SELECT ADsPath " _
>> & "FROM 'LDAP://cn=users,dc=lab,dc=local' " _
>> & "WHERE objectCategory='user' AND NOT scriptPath='*'"
>> Set objRecordSet = objCommand.Execute
>>
>> Do Until objRecordSet.EOF
>> Set objUser = GetObject(objRecordset.Fields("ADsPath").Value)
>> objUser.scriptPath = "logon.bat"
>> objUser.SetInfo
>> objRecordset.MoveNext
>> Loop
>>
>> ' Clean up.
>> objRecordset.Close
>> objConnection.Close
>>
>> --
>> Richard Mueller
>> Microsoft MVP Scripting and ADSI
>> Hilltop Lab - http://www.rlmueller.net
>> --
>>
>>
>>



Re: Add ScriptPath to AD user - [WP] by Richard

Richard
Fri Mar 07 19:26:02 CST 2008

baron1211 wrote:

..> snip

You could try using tis command. It works for my environment


objUser.put "Scriptpath", "Login.bat"

My 2 cents worth.

--------
Yes, either syntax works.

--
Richard Mueller
Microsoft MVP Scripting and ADSI
Hilltop Lab - http://www.rlmueller.net
--



Re: Add ScriptPath to AD user - [WP] by Wiseman82

Wiseman82
Sun Mar 09 13:26:50 CDT 2008

I've added this script for you:

http://www.wisesoft.co.uk/Scripts/display_script.aspx?id=372

I also have an app that is useful for these types of updates:

http://www.wisesoft.co.uk/Products/PasswordControl/BulkModify/

Instructions for using Bulk Modify:
* In the Bulk Password Control dialog, goto File\Get Users\From Query
* In the "Custom LDAP Filter" textbox type "(!scriptPath=*)"
A list of user accounts without a "logon script" attribute will be
displayed.
* Click the "Bulk Modify" button
* Click the "Profile" Tab.
* Click the checkbox to enable the "logon script" attribute and type your
logon script "logon.bat"
* Click "OK" to perform the update.

Using Bulk Modify has an advantage over using a script - you get a log file
with detailed information about the update. The log file can be used to
rollback any changes made (It's still a good idea to have a backup of your
AD before making bulk changes - either with this app or with a script)

Bulk Modify is a freeware (fee) application and is currently a BETA release.
My website is a free resource for IT Professionals, with scripts and apps
that system admins will find useful.

As a side note, I think many system admins prefer to use group policy for
logon scripts. Both methods are valid though. :-)

Hope this helps,

David
http://www.wisesoft.co.uk


"WILDPACKET" <WILDPACKET@discussions.microsoft.com> wrote in message
news:2FC07730-482D-40C7-8754-A4477EEBB363@microsoft.com...
> trying to add logon.bat to under the AD users properties ....under Logon
> Script field.
>
> I ahve this Vb ...and I am not a VB guy ...can somebody please adddress
> for
> me ...
> I want the Logon.bat added Logon Script field to all my users in AD and
> the
> ones which already have it shoudl be ignored.
>
>
>
> On Error Resume Next
>
> Const ADS_SCOPE_SUBTREE = 2
>
> Set objConnection = CreateObject("ADODB.Connection")
> Set objCommand = CreateObject("ADODB.Command")
> objConnection.Provider = "ADsDSOObject"
> objConnection.Open "Active Directory Provider"
> Set objCommand.ActiveConnection = objConnection
>
> objCommand.Properties("Page Size") = 1000
> objCommand.Properties("Searchscope") = ADS_SCOPE_SUBTREE
>
> objCommand.CommandText = _
> "SELECT ADsPath FROM 'LDAP://cn=users,dc=lab,dc=local' WHERE
> objectCategory='user' "
> Set objRecordSet = objCommand.Execute
> Const ADS_PROPERTY_APPEND = 3
>
> objUser.PutEx ADS_PROPERTY_APPEND, _
> objUser.scriptPath, ("logon.bat")
> objUser.SetInfo
>
>
> Advise Please. Thanks
>


Re: Add ScriptPath to AD user - [WP] by WILDPACKET

WILDPACKET
Mon Mar 10 06:50:01 CDT 2008


Thank you Richard

Sorry its is line 21 not 24
in my Copy line 21 is this... objUser.SetInfo

When I run, it says ....

Line: 21
Char:5
Error: The requested opertation did nto satisfy one or more constraints
associated with the class of the object
code: 80072014

This is a test DC, I only have 3 users in users container. Only 1 user has
"logon.bat" defined under profile tab under ADUC.




"Richard Mueller [MVP]" wrote:

> Line 24 in my copy of the script is a blank line near the end (after the
> loop, before the clean up). The script runs for me without error. I pasted
> it exactly from my post in the newsgroup, except I changed the base of the
> search (line 14) to reflect my domain. I only have a few users in the
> cn=Users container, but all now show logon.bat on the profile tab in ADUC,
> unless they already had a logon script specified. Which line is line 24 in
> your copy?
>
> --
> Richard Mueller
> Microsoft MVP Scripting and ADSI
> Hilltop Lab - http://www.rlmueller.net
> --
>
> "WILDPACKET" <WILDPACKET@discussions.microsoft.com> wrote in message
> news:9CCBF0AD-29AC-4835-ADFC-DE179729E840@microsoft.com...
> >
> > Richard thanks for your response.
> >
> > I ran the scriot as is and gives error on Line 24 and says character 5.
> >
> > Advise Plz.
> >
> >
> >
> >
> >
> > "Richard Mueller [MVP]" wrote:
> >
> >> WILDPACKET wrote:
> >>
> >> > trying to add logon.bat to under the AD users properties ....under
> >> > Logon
> >> > Script field.
> >> >
> >> > I ahve this Vb ...and I am not a VB guy ...can somebody please adddress
> >> > for
> >> > me ...
> >> > I want the Logon.bat added Logon Script field to all my users in AD and
> >> > the
> >> > ones which already have it shoudl be ignored.
> >> >
> >> >
> >> >
> >> > On Error Resume Next
> >> >
> >> > Const ADS_SCOPE_SUBTREE = 2
> >> >
> >> > Set objConnection = CreateObject("ADODB.Connection")
> >> > Set objCommand = CreateObject("ADODB.Command")
> >> > objConnection.Provider = "ADsDSOObject"
> >> > objConnection.Open "Active Directory Provider"
> >> > Set objCommand.ActiveConnection = objConnection
> >> >
> >> > objCommand.Properties("Page Size") = 1000
> >> > objCommand.Properties("Searchscope") = ADS_SCOPE_SUBTREE
> >> >
> >> > objCommand.CommandText = _
> >> > "SELECT ADsPath FROM 'LDAP://cn=users,dc=lab,dc=local' WHERE
> >> > objectCategory='user' "
> >> > Set objRecordSet = objCommand.Execute
> >> > Const ADS_PROPERTY_APPEND = 3
> >> >
> >> > objUser.PutEx ADS_PROPERTY_APPEND, _
> >> > objUser.scriptPath, ("logon.bat")
> >> > objUser.SetInfo
> >> >
> >> >
> >> > Advise Please. Thanks
> >> >
> >>
> >> I suggest the code below. I added a clause to the query to retrieve users
> >> only if there is no value assigned to the scriptPath attribute. Note you
> >> must enumerate the resulting recordset in a loop, then bind to each user
> >> object (using the value of ADsPath retrieved), assign the value to the
> >> scriptPath attribute, then invoke the SetInfo method to save changes.
> >> ==========
> >> Const ADS_SCOPE_SUBTREE = 2
> >>
> >> Set objConnection = CreateObject("ADODB.Connection")
> >> Set objCommand = CreateObject("ADODB.Command")
> >> objConnection.Provider = "ADsDSOObject"
> >> objConnection.Open "Active Directory Provider"
> >> Set objCommand.ActiveConnection = objConnection
> >>
> >> objCommand.Properties("Page Size") = 1000
> >> objCommand.Properties("Searchscope") = ADS_SCOPE_SUBTREE
> >>
> >> objCommand.CommandText = _
> >> "SELECT ADsPath " _
> >> & "FROM 'LDAP://cn=users,dc=lab,dc=local' " _
> >> & "WHERE objectCategory='user' AND NOT scriptPath='*'"
> >> Set objRecordSet = objCommand.Execute
> >>
> >> Do Until objRecordSet.EOF
> >> Set objUser = GetObject(objRecordset.Fields("ADsPath").Value)
> >> objUser.scriptPath = "logon.bat"
> >> objUser.SetInfo
> >> objRecordset.MoveNext
> >> Loop
> >>
> >> ' Clean up.
> >> objRecordset.Close
> >> objConnection.Close
> >>
> >> --
> >> Richard Mueller
> >> Microsoft MVP Scripting and ADSI
> >> Hilltop Lab - http://www.rlmueller.net
> >> --
> >>
> >>
> >>
>
>
>

Re: Add ScriptPath to AD user - [WP] by WILDPACKET

WILDPACKET
Mon Mar 10 07:04:00 CDT 2008



Thank You Wiseman82 for the links.




"Wiseman82" wrote:

> I've added this script for you:
>
> http://www.wisesoft.co.uk/Scripts/display_script.aspx?id=372
>
> I also have an app that is useful for these types of updates:
>
> http://www.wisesoft.co.uk/Products/PasswordControl/BulkModify/
>
> Instructions for using Bulk Modify:
> * In the Bulk Password Control dialog, goto File\Get Users\From Query
> * In the "Custom LDAP Filter" textbox type "(!scriptPath=*)"
> A list of user accounts without a "logon script" attribute will be
> displayed.
> * Click the "Bulk Modify" button
> * Click the "Profile" Tab.
> * Click the checkbox to enable the "logon script" attribute and type your
> logon script "logon.bat"
> * Click "OK" to perform the update.
>
> Using Bulk Modify has an advantage over using a script - you get a log file
> with detailed information about the update. The log file can be used to
> rollback any changes made (It's still a good idea to have a backup of your
> AD before making bulk changes - either with this app or with a script)
>
> Bulk Modify is a freeware (fee) application and is currently a BETA release.
> My website is a free resource for IT Professionals, with scripts and apps
> that system admins will find useful.
>
> As a side note, I think many system admins prefer to use group policy for
> logon scripts. Both methods are valid though. :-)
>
> Hope this helps,
>
> David
> http://www.wisesoft.co.uk
>
>
> "WILDPACKET" <WILDPACKET@discussions.microsoft.com> wrote in message
> news:2FC07730-482D-40C7-8754-A4477EEBB363@microsoft.com...
> > trying to add logon.bat to under the AD users properties ....under Logon
> > Script field.
> >
> > I ahve this Vb ...and I am not a VB guy ...can somebody please adddress
> > for
> > me ...
> > I want the Logon.bat added Logon Script field to all my users in AD and
> > the
> > ones which already have it shoudl be ignored.
> >
> >
> >
> > On Error Resume Next
> >
> > Const ADS_SCOPE_SUBTREE = 2
> >
> > Set objConnection = CreateObject("ADODB.Connection")
> > Set objCommand = CreateObject("ADODB.Command")
> > objConnection.Provider = "ADsDSOObject"
> > objConnection.Open "Active Directory Provider"
> > Set objCommand.ActiveConnection = objConnection
> >
> > objCommand.Properties("Page Size") = 1000
> > objCommand.Properties("Searchscope") = ADS_SCOPE_SUBTREE
> >
> > objCommand.CommandText = _
> > "SELECT ADsPath FROM 'LDAP://cn=users,dc=lab,dc=local' WHERE
> > objectCategory='user' "
> > Set objRecordSet = objCommand.Execute
> > Const ADS_PROPERTY_APPEND = 3
> >
> > objUser.PutEx ADS_PROPERTY_APPEND, _
> > objUser.scriptPath, ("logon.bat")
> > objUser.SetInfo
> >
> >
> > Advise Please. Thanks
> >
>

Re: Add ScriptPath to AD user - [WP] by WILDPACKET

WILDPACKET
Mon Mar 10 07:06:00 CDT 2008


Hi Richard:

It works now after I added the following line at the very top of the script
....

On Error Resume next

and all is Kosher!

Thank you for your support.



"Richard Mueller [MVP]" wrote:

> Line 24 in my copy of the script is a blank line near the end (after the
> loop, before the clean up). The script runs for me without error. I pasted
> it exactly from my post in the newsgroup, except I changed the base of the
> search (line 14) to reflect my domain. I only have a few users in the
> cn=Users container, but all now show logon.bat on the profile tab in ADUC,
> unless they already had a logon script specified. Which line is line 24 in
> your copy?
>
> --
> Richard Mueller
> Microsoft MVP Scripting and ADSI
> Hilltop Lab - http://www.rlmueller.net
> --
>
> "WILDPACKET" <WILDPACKET@discussions.microsoft.com> wrote in message
> news:9CCBF0AD-29AC-4835-ADFC-DE179729E840@microsoft.com...
> >
> > Richard thanks for your response.
> >
> > I ran the scriot as is and gives error on Line 24 and says character 5.
> >
> > Advise Plz.
> >
> >
> >
> >
> >
> > "Richard Mueller [MVP]" wrote:
> >
> >> WILDPACKET wrote:
> >>
> >> > trying to add logon.bat to under the AD users properties ....under
> >> > Logon
> >> > Script field.
> >> >
> >> > I ahve this Vb ...and I am not a VB guy ...can somebody please adddress
> >> > for
> >> > me ...
> >> > I want the Logon.bat added Logon Script field to all my users in AD and
> >> > the
> >> > ones which already have it shoudl be ignored.
> >> >
> >> >
> >> >
> >> > On Error Resume Next
> >> >
> >> > Const ADS_SCOPE_SUBTREE = 2
> >> >
> >> > Set objConnection = CreateObject("ADODB.Connection")
> >> > Set objCommand = CreateObject("ADODB.Command")
> >> > objConnection.Provider = "ADsDSOObject"
> >> > objConnection.Open "Active Directory Provider"
> >> > Set objCommand.ActiveConnection = objConnection
> >> >
> >> > objCommand.Properties("Page Size") = 1000
> >> > objCommand.Properties("Searchscope") = ADS_SCOPE_SUBTREE
> >> >
> >> > objCommand.CommandText = _
> >> > "SELECT ADsPath FROM 'LDAP://cn=users,dc=lab,dc=local' WHERE
> >> > objectCategory='user' "
> >> > Set objRecordSet = objCommand.Execute
> >> > Const ADS_PROPERTY_APPEND = 3
> >> >
> >> > objUser.PutEx ADS_PROPERTY_APPEND, _
> >> > objUser.scriptPath, ("logon.bat")
> >> > objUser.SetInfo
> >> >
> >> >
> >> > Advise Please. Thanks
> >> >
> >>
> >> I suggest the code below. I added a clause to the query to retrieve users
> >> only if there is no value assigned to the scriptPath attribute. Note you
> >> must enumerate the resulting recordset in a loop, then bind to each user
> >> object (using the value of ADsPath retrieved), assign the value to the
> >> scriptPath attribute, then invoke the SetInfo method to save changes.
> >> ==========
> >> Const ADS_SCOPE_SUBTREE = 2
> >>
> >> Set objConnection = CreateObject("ADODB.Connection")
> >> Set objCommand = CreateObject("ADODB.Command")
> >> objConnection.Provider = "ADsDSOObject"
> >> objConnection.Open "Active Directory Provider"
> >> Set objCommand.ActiveConnection = objConnection
> >>
> >> objCommand.Properties("Page Size") = 1000
> >> objCommand.Properties("Searchscope") = ADS_SCOPE_SUBTREE
> >>
> >> objCommand.CommandText = _
> >> "SELECT ADsPath " _
> >> & "FROM 'LDAP://cn=users,dc=lab,dc=local' " _
> >> & "WHERE objectCategory='user' AND NOT scriptPath='*'"
> >> Set objRecordSet = objCommand.Execute
> >>
> >> Do Until objRecordSet.EOF
> >> Set objUser = GetObject(objRecordset.Fields("ADsPath").Value)
> >> objUser.scriptPath = "logon.bat"
> >> objUser.SetInfo
> >> objRecordset.MoveNext
> >> Loop
> >>
> >> ' Clean up.
> >> objRecordset.Close
> >> objConnection.Close
> >>
> >> --
> >> Richard Mueller
> >> Microsoft MVP Scripting and ADSI
> >> Hilltop Lab - http://www.rlmueller.net
> >> --
> >>
> >>
> >>
>
>
>

Re: Add ScriptPath to AD user - [WP] by Richard

Richard
Mon Mar 10 11:19:53 CDT 2008

The most likely cause of the error on the SetInfo statement is that your
query retrieves both user and contact objects. Contact objects do not have a
scriptPath attribute. This can be avoided by using:

objCommand.CommandText = _
"SELECT ADsPath " _
& "FROM 'LDAP://cn=users,dc=lab,dc=local' " _
& "WHERE objectCategory='person' AND objectClass='user' AND NOT
scriptPath='*'"

--
Richard Mueller
Microsoft MVP Scripting and ADSI
Hilltop Lab - http://www.rlmueller.net
--

"WILDPACKET" <WILDPACKET@discussions.microsoft.com> wrote in message
news:352EA347-E70B-4000-94C8-FB59406D7991@microsoft.com...
>
> Hi Richard:
>
> It works now after I added the following line at the very top of the
> script
> ....
>
> On Error Resume next
>
> and all is Kosher!
>
> Thank you for your support.
>
>
>
> "Richard Mueller [MVP]" wrote:
>
>> Line 24 in my copy of the script is a blank line near the end (after the
>> loop, before the clean up). The script runs for me without error. I
>> pasted
>> it exactly from my post in the newsgroup, except I changed the base of
>> the
>> search (line 14) to reflect my domain. I only have a few users in the
>> cn=Users container, but all now show logon.bat on the profile tab in
>> ADUC,
>> unless they already had a logon script specified. Which line is line 24
>> in
>> your copy?
>>
>> --
>> Richard Mueller
>> Microsoft MVP Scripting and ADSI
>> Hilltop Lab - http://www.rlmueller.net
>> --
>>
>> "WILDPACKET" <WILDPACKET@discussions.microsoft.com> wrote in message
>> news:9CCBF0AD-29AC-4835-ADFC-DE179729E840@microsoft.com...
>> >
>> > Richard thanks for your response.
>> >
>> > I ran the scriot as is and gives error on Line 24 and says character 5.
>> >
>> > Advise Plz.
>> >
>> >
>> >
>> >
>> >
>> > "Richard Mueller [MVP]" wrote:
>> >
>> >> WILDPACKET wrote:
>> >>
>> >> > trying to add logon.bat to under the AD users properties ....under
>> >> > Logon
>> >> > Script field.
>> >> >
>> >> > I ahve this Vb ...and I am not a VB guy ...can somebody please
>> >> > adddress
>> >> > for
>> >> > me ...
>> >> > I want the Logon.bat added Logon Script field to all my users in AD
>> >> > and
>> >> > the
>> >> > ones which already have it shoudl be ignored.
>> >> >
>> >> >
>> >> >
>> >> > On Error Resume Next
>> >> >
>> >> > Const ADS_SCOPE_SUBTREE = 2
>> >> >
>> >> > Set objConnection = CreateObject("ADODB.Connection")
>> >> > Set objCommand = CreateObject("ADODB.Command")
>> >> > objConnection.Provider = "ADsDSOObject"
>> >> > objConnection.Open "Active Directory Provider"
>> >> > Set objCommand.ActiveConnection = objConnection
>> >> >
>> >> > objCommand.Properties("Page Size") = 1000
>> >> > objCommand.Properties("Searchscope") = ADS_SCOPE_SUBTREE
>> >> >
>> >> > objCommand.CommandText = _
>> >> > "SELECT ADsPath FROM 'LDAP://cn=users,dc=lab,dc=local' WHERE
>> >> > objectCategory='user' "
>> >> > Set objRecordSet = objCommand.Execute
>> >> > Const ADS_PROPERTY_APPEND = 3
>> >> >
>> >> > objUser.PutEx ADS_PROPERTY_APPEND, _
>> >> > objUser.scriptPath, ("logon.bat")
>> >> > objUser.SetInfo
>> >> >
>> >> >
>> >> > Advise Please. Thanks
>> >> >
>> >>
>> >> I suggest the code below. I added a clause to the query to retrieve
>> >> users
>> >> only if there is no value assigned to the scriptPath attribute. Note
>> >> you
>> >> must enumerate the resulting recordset in a loop, then bind to each
>> >> user
>> >> object (using the value of ADsPath retrieved), assign the value to the
>> >> scriptPath attribute, then invoke the SetInfo method to save changes.
>> >> ==========
>> >> Const ADS_SCOPE_SUBTREE = 2
>> >>
>> >> Set objConnection = CreateObject("ADODB.Connection")
>> >> Set objCommand = CreateObject("ADODB.Command")
>> >> objConnection.Provider = "ADsDSOObject"
>> >> objConnection.Open "Active Directory Provider"
>> >> Set objCommand.ActiveConnection = objConnection
>> >>
>> >> objCommand.Properties("Page Size") = 1000
>> >> objCommand.Properties("Searchscope") = ADS_SCOPE_SUBTREE
>> >>
>> >> objCommand.CommandText = _
>> >> "SELECT ADsPath " _
>> >> & "FROM 'LDAP://cn=users,dc=lab,dc=local' " _
>> >> & "WHERE objectCategory='user' AND NOT scriptPath='*'"
>> >> Set objRecordSet = objCommand.Execute
>> >>
>> >> Do Until objRecordSet.EOF
>> >> Set objUser = GetObject(objRecordset.Fields("ADsPath").Value)
>> >> objUser.scriptPath = "logon.bat"
>> >> objUser.SetInfo
>> >> objRecordset.MoveNext
>> >> Loop
>> >>
>> >> ' Clean up.
>> >> objRecordset.Close
>> >> objConnection.Close
>> >>
>> >> --
>> >> Richard Mueller
>> >> Microsoft MVP Scripting and ADSI
>> >> Hilltop Lab - http://www.rlmueller.net
>> >> --
>> >>
>> >>
>> >>
>>
>>
>>



Re: Add ScriptPath to AD user - [WP] by WILDPACKET

WILDPACKET
Mon Mar 10 20:43:09 CDT 2008


I will check this out.
Thanks,


"Richard Mueller [MVP]" wrote:

> The most likely cause of the error on the SetInfo statement is that your
> query retrieves both user and contact objects. Contact objects do not have a
> scriptPath attribute. This can be avoided by using:
>
> objCommand.CommandText = _
> "SELECT ADsPath " _
> & "FROM 'LDAP://cn=users,dc=lab,dc=local' " _
> & "WHERE objectCategory='person' AND objectClass='user' AND NOT
> scriptPath='*'"
>
> --
> Richard Mueller
> Microsoft MVP Scripting and ADSI
> Hilltop Lab - http://www.rlmueller.net
> --
>
> "WILDPACKET" <WILDPACKET@discussions.microsoft.com> wrote in message
> news:352EA347-E70B-4000-94C8-FB59406D7991@microsoft.com...
> >
> > Hi Richard:
> >
> > It works now after I added the following line at the very top of the
> > script
> > ....
> >
> > On Error Resume next
> >
> > and all is Kosher!
> >
> > Thank you for your support.
> >
> >
> >
> > "Richard Mueller [MVP]" wrote:
> >
> >> Line 24 in my copy of the script is a blank line near the end (after the
> >> loop, before the clean up). The script runs for me without error. I
> >> pasted
> >> it exactly from my post in the newsgroup, except I changed the base of
> >> the
> >> search (line 14) to reflect my domain. I only have a few users in the
> >> cn=Users container, but all now show logon.bat on the profile tab in
> >> ADUC,
> >> unless they already had a logon script specified. Which line is line 24
> >> in
> >> your copy?
> >>
> >> --
> >> Richard Mueller
> >> Microsoft MVP Scripting and ADSI
> >> Hilltop Lab - http://www.rlmueller.net
> >> --
> >>
> >> "WILDPACKET" <WILDPACKET@discussions.microsoft.com> wrote in message
> >> news:9CCBF0AD-29AC-4835-ADFC-DE179729E840@microsoft.com...
> >> >
> >> > Richard thanks for your response.
> >> >
> >> > I ran the scriot as is and gives error on Line 24 and says character 5.
> >> >
> >> > Advise Plz.
> >> >
> >> >
> >> >
> >> >
> >> >
> >> > "Richard Mueller [MVP]" wrote:
> >> >
> >> >> WILDPACKET wrote:
> >> >>
> >> >> > trying to add logon.bat to under the AD users properties ....under
> >> >> > Logon
> >> >> > Script field.
> >> >> >
> >> >> > I ahve this Vb ...and I am not a VB guy ...can somebody please
> >> >> > adddress
> >> >> > for
> >> >> > me ...
> >> >> > I want the Logon.bat added Logon Script field to all my users in AD
> >> >> > and
> >> >> > the
> >> >> > ones which already have it shoudl be ignored.
> >> >> >
> >> >> >
> >> >> >
> >> >> > On Error Resume Next
> >> >> >
> >> >> > Const ADS_SCOPE_SUBTREE = 2
> >> >> >
> >> >> > Set objConnection = CreateObject("ADODB.Connection")
> >> >> > Set objCommand = CreateObject("ADODB.Command")
> >> >> > objConnection.Provider = "ADsDSOObject"
> >> >> > objConnection.Open "Active Directory Provider"
> >> >> > Set objCommand.ActiveConnection = objConnection
> >> >> >
> >> >> > objCommand.Properties("Page Size") = 1000
> >> >> > objCommand.Properties("Searchscope") = ADS_SCOPE_SUBTREE
> >> >> >
> >> >> > objCommand.CommandText = _
> >> >> > "SELECT ADsPath FROM 'LDAP://cn=users,dc=lab,dc=local' WHERE
> >> >> > objectCategory='user' "
> >> >> > Set objRecordSet = objCommand.Execute
> >> >> > Const ADS_PROPERTY_APPEND = 3
> >> >> >
> >> >> > objUser.PutEx ADS_PROPERTY_APPEND, _
> >> >> > objUser.scriptPath, ("logon.bat")
> >> >> > objUser.SetInfo
> >> >> >
> >> >> >
> >> >> > Advise Please. Thanks
> >> >> >
> >> >>
> >> >> I suggest the code below. I added a clause to the query to retrieve
> >> >> users
> >> >> only if there is no value assigned to the scriptPath attribute. Note
> >> >> you
> >> >> must enumerate the resulting recordset in a loop, then bind to each
> >> >> user
> >> >> object (using the value of ADsPath retrieved), assign the value to the
> >> >> scriptPath attribute, then invoke the SetInfo method to save changes.
> >> >> ==========
> >> >> Const ADS_SCOPE_SUBTREE = 2
> >> >>
> >> >> Set objConnection = CreateObject("ADODB.Connection")
> >> >> Set objCommand = CreateObject("ADODB.Command")
> >> >> objConnection.Provider = "ADsDSOObject"
> >> >> objConnection.Open "Active Directory Provider"
> >> >> Set objCommand.ActiveConnection = objConnection
> >> >>
> >> >> objCommand.Properties("Page Size") = 1000
> >> >> objCommand.Properties("Searchscope") = ADS_SCOPE_SUBTREE
> >> >>
> >> >> objCommand.CommandText = _
> >> >> "SELECT ADsPath " _
> >> >> & "FROM 'LDAP://cn=users,dc=lab,dc=local' " _
> >> >> & "WHERE objectCategory='user' AND NOT scriptPath='*'"
> >> >> Set objRecordSet = objCommand.Execute
> >> >>
> >> >> Do Until objRecordSet.EOF
> >> >> Set objUser = GetObject(objRecordset.Fields("ADsPath").Value)
> >> >> objUser.scriptPath = "logon.bat"
> >> >> objUser.SetInfo
> >> >> objRecordset.MoveNext
> >> >> Loop
> >> >>
> >> >> ' Clean up.
> >> >> objRecordset.Close
> >> >> objConnection.Close
> >> >>
> >> >> --
> >> >> Richard Mueller
> >> >> Microsoft MVP Scripting and ADSI
> >> >> Hilltop Lab - http://www.rlmueller.net
> >> >> --
> >> >>
> >> >>
> >> >>
> >>
> >>
> >>
>
>
>