Login Script 
Author Message
 Login Script

How can I change all the users login script using VBScript? We are running
NT 4.0 servers.
The last domain administrator created individual scripts for each user. I've
created one
login script for everyone and I need a way to automate the change.

Thanks



Wed, 02 Nov 2005 20:24:06 GMT  
 Login Script

Quote:

> How can I change all the users login script using vbscript? We are running
> NT 4.0 servers.
> The last domain administrator created individual scripts for each user.
I've
> created one
> login script for everyone and I need a way to automate the change.

Hi,

Using the LDAP provider, the attribute to modify is "scriptPath". I would
suggest two scripts. The first would dump out all user Distinguished Names.
This could output to a text file, but a spreadsheet would be even better.
You want to be able to review the list of users. You might delete guest
accounts, administrators, training, or whatever. You would add what you want
for logon script in the second column of the spreadsheet. You could make
them all the same, or have one logon script for guests, one for training,
one for normal users, and another for admins.

I have a program that dumps all user Distinguished Names to a spreadsheet.
The spreadsheet filename to be created is passed to the program as a
parameter:

http://www.rlmueller.net/Create%20User%20List%203.htm

After adding logon scripts to the second column of the spreadsheet, you need
a program that reads the spreadsheet, binds to the users specified by the DN
in the first column, and updates scriptPath with the value and in the second
column. I have a similar program that reads the spreadsheet created by the
above program and uses it to reset passwords:

http://www.rlmueller.net/Set%20Passwords%203.htm

This program can be modified to update scriptPath instead. Here is a
modified VBScript program to do that:

Option Explicit
Dim strExcelPath, objExcel, objSheet, intRow, strUserDN, strLogonScript
Dim objUser

' Check for required arguments.
If Wscript.Arguments.Count < 1 Then
  Wscript.Echo "Arguments <FileName> required. For example:" & vbCrLf _
    & "wscript CreateUserList3.vbs c:\MyFolder\UserList3.xls"
  Wscript.Quit(0)
End If

' Spreadsheet file.
strExcelPath = Wscript.Arguments(0)

' Bind to Excel object.
On Error Resume Next
Err.Clear
Set objExcel = CreateObject("Excel.Application")
If Err.Number <> 0 Then
  Err.Clear
  Wscript.Echo "Excel application not found."
  Wscript.Quit
End If
On Error GoTo 0

' Open spreadsheet.
On Error Resume Next
Err.Clear
objExcel.Workbooks.Open strExcelPath
If Err.Number <> 0 Then
  Err.Clear
  Wscript.Echo "Spreadsheet cannot be opened:" & vbCrLf & strExcelPath
  Wscript.Quit
End If

' Bind to worksheet.
Set objSheet = objExcel.ActiveWorkbook.Worksheets(1)

' The first row of the spreadsheet is skipped (column headings). Each
' row after the first is processed until the first blank entry in the
' first column is encountered. The first column is the Distinguished
' Name of the user, the second column is the logon script. The loop
' binds to each user object and sets scriptPath. intRow is the row
' number of the spreadsheet.
intRow = 2
Do While objSheet.Cells(intRow, 1).Value <> ""
  strUserDN = objSheet.Cells(intRow, 1).Value
  strLogonScript = objSheet.Cells(intRow, 2).Value
  On Error Resume Next
  Err.Clear
  Set objUser = GetObject("LDAP://" & strUserDN)
  If Err.Number <> 0 Then
    Err.Clear
    Wscript.Echo "User NOT found" & vbCrLf & strUserDN
  Else
    objUser.scriptPath = strLogonScript
    objUser.SetInfo
    If Err.Number <> 0 Then
      Err.Clear
      Wscript.Echo "LogonScript NOT set for " &vbCrLf & strUserDN
    End If
  End If
  On Error GoTo 0
  intRow = intRow + 1
Loop

' Close the workbook.
objExcel.ActiveWorkbook.Close

' Quit Excel.
objExcel.Application.Quit

' Clean up.
Set objUser = Nothing
Set objExcel = Nothing
Set objSheet = Nothing

Wscript.Echo "Done"

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



Thu, 03 Nov 2005 00:49:12 GMT  
 Login Script
We are currently running an NT 4.0 domain so we do not have Active
Directory.  Could you convert that script
to a non- ad format?



Quote:

> > How can I change all the users login script using vbscript? We are
running
> > NT 4.0 servers.
> > The last domain administrator created individual scripts for each user.
> I've
> > created one
> > login script for everyone and I need a way to automate the change.

> Hi,

> Using the LDAP provider, the attribute to modify is "scriptPath". I would
> suggest two scripts. The first would dump out all user Distinguished
Names.
> This could output to a text file, but a spreadsheet would be even better.
> You want to be able to review the list of users. You might delete guest
> accounts, administrators, training, or whatever. You would add what you
want
> for logon script in the second column of the spreadsheet. You could make
> them all the same, or have one logon script for guests, one for training,
> one for normal users, and another for admins.

> I have a program that dumps all user Distinguished Names to a spreadsheet.
> The spreadsheet filename to be created is passed to the program as a
> parameter:

> http://www.rlmueller.net/Create%20User%20List%203.htm

> After adding logon scripts to the second column of the spreadsheet, you
need
> a program that reads the spreadsheet, binds to the users specified by the
DN
> in the first column, and updates scriptPath with the value and in the
second
> column. I have a similar program that reads the spreadsheet created by the
> above program and uses it to reset passwords:

> http://www.rlmueller.net/Set%20Passwords%203.htm

> This program can be modified to update scriptPath instead. Here is a
> modified VBScript program to do that:

> Option Explicit
> Dim strExcelPath, objExcel, objSheet, intRow, strUserDN, strLogonScript
> Dim objUser

> ' Check for required arguments.
> If Wscript.Arguments.Count < 1 Then
>   Wscript.Echo "Arguments <FileName> required. For example:" & vbCrLf _
>     & "wscript CreateUserList3.vbs c:\MyFolder\UserList3.xls"
>   Wscript.Quit(0)
> End If

> ' Spreadsheet file.
> strExcelPath = Wscript.Arguments(0)

> ' Bind to Excel object.
> On Error Resume Next
> Err.Clear
> Set objExcel = CreateObject("Excel.Application")
> If Err.Number <> 0 Then
>   Err.Clear
>   Wscript.Echo "Excel application not found."
>   Wscript.Quit
> End If
> On Error GoTo 0

> ' Open spreadsheet.
> On Error Resume Next
> Err.Clear
> objExcel.Workbooks.Open strExcelPath
> If Err.Number <> 0 Then
>   Err.Clear
>   Wscript.Echo "Spreadsheet cannot be opened:" & vbCrLf & strExcelPath
>   Wscript.Quit
> End If

> ' Bind to worksheet.
> Set objSheet = objExcel.ActiveWorkbook.Worksheets(1)

> ' The first row of the spreadsheet is skipped (column headings). Each
> ' row after the first is processed until the first blank entry in the
> ' first column is encountered. The first column is the Distinguished
> ' Name of the user, the second column is the logon script. The loop
> ' binds to each user object and sets scriptPath. intRow is the row
> ' number of the spreadsheet.
> intRow = 2
> Do While objSheet.Cells(intRow, 1).Value <> ""
>   strUserDN = objSheet.Cells(intRow, 1).Value
>   strLogonScript = objSheet.Cells(intRow, 2).Value
>   On Error Resume Next
>   Err.Clear
>   Set objUser = GetObject("LDAP://" & strUserDN)
>   If Err.Number <> 0 Then
>     Err.Clear
>     Wscript.Echo "User NOT found" & vbCrLf & strUserDN
>   Else
>     objUser.scriptPath = strLogonScript
>     objUser.SetInfo
>     If Err.Number <> 0 Then
>       Err.Clear
>       Wscript.Echo "LogonScript NOT set for " &vbCrLf & strUserDN
>     End If
>   End If
>   On Error GoTo 0
>   intRow = intRow + 1
> Loop

> ' Close the workbook.
> objExcel.ActiveWorkbook.Close

> ' Quit Excel.
> objExcel.Application.Quit

> ' Clean up.
> Set objUser = Nothing
> Set objExcel = Nothing
> Set objSheet = Nothing

> Wscript.Echo "Done"

> --
> Richard
> Microsoft MVP Scripting and ADSI
> http://www.rlmueller.net
> --



Thu, 03 Nov 2005 02:35:05 GMT  
 Login Script
Hi,

NT domains are a bit easier, since they have a flat namespace. This makes it
easier to enumerate users. The WinNT provider must be used. With this
provider the attribute name is "LoginScript". The first program to enumerate
users and populate a spreadsheeet would be:

============= start of code ==============
Option Explicit

Dim strExcelPath, strNetBIOSDomain, objDomain, objUser
Dim objExcel, objSheet, k, objNetwork

' Check for required arguments.
If Wscript.Arguments.Count < 1 Then
  Wscript.Echo "Arguments <FileName> required. For example:" _
    & vbCrLf _
    & "wscript CreateUserList3.vbs c:\MyFolder\UserList3.xls"
  Wscript.Quit(0)
End If

' Spreadsheet file to be created.
strExcelPath = Wscript.Arguments(0)

' Bind to Excel object.
Set objExcel = CreateObject("Excel.Application")
objExcel.Workbooks.Add

' Bind to worksheet.
Set objSheet = objExcel.ActiveWorkbook.Worksheets(1)
objSheet.Name = "Domain User"
objSheet.Cells(1, 1).Value = "User NT Logon Name"

' Determine NetBIOS domain name from WshNetwork object.
' Only works on NT clients or above.
' On Win9x clients you can hard code strNetBIOSDomain.
Set objNetwork = CreateObject("Wscript.Network")
strNetBIOSDomain = objNetwork.UserDomain

' Bind to domain.
Set objDomain = GetObject("WinNT://" & strNetBIOSDomain)

' Enumerate all users in domain.
' Write user NT logon names to spreadsheet.
objDomain.Filter = Array("user")
k = 2
For Each objUser In objDomain
  objSheet.Cells(k, 1).Value = objUser.Name
  k = k + 1
Next

' Format the spreadsheet.
objSheet.Range("A1:A1").Font.Bold = True
objSheet.Select
objExcel.Columns(1).ColumnWidth = 20

' Save the spreadsheet.
objExcel.ActiveWorkbook.SaveAs strExcelPath
objExcel.ActiveWorkbook.Close

' Quit Excel.
objExcel.Application.Quit

' Clean up.
Set objNetwork = Nothing
Set objDomain = Nothing
Set objUser = Nothing
Set objSheet = Nothing
Set objExcel = Nothing

Wscript.Echo "Done"
============================== end of code ===============

Next, the program to read the resulting spreadsheet and modify "loginScript"
would be the same as before, with just two lines changed. First, the user
object objUser must be bound with the WinNT provider. This line becomes:

  Set objUser = GetObject("WinNT://" & strUserDN)

Next, the attribute name changes from "scriptPath" to "loginScript". The new
line becomes:

  objUser.loginScript = strLogonScript

I tested the program to create the spreadsheet above. I didn't test the new
code to assign "loginScript", so let me know if there is a problem.

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


Quote:
> We are currently running an NT 4.0 domain so we do not have Active
> Directory.  Could you convert that script
> to a non- ad format?




> > > How can I change all the users login script using vbscript? We are
> running
> > > NT 4.0 servers.
> > > The last domain administrator created individual scripts for each
user.
> > I've
> > > created one
> > > login script for everyone and I need a way to automate the change.

> > Hi,

> > Using the LDAP provider, the attribute to modify is "scriptPath". I
would
> > suggest two scripts. The first would dump out all user Distinguished
> Names.
> > This could output to a text file, but a spreadsheet would be even
better.
> > You want to be able to review the list of users. You might delete guest
> > accounts, administrators, training, or whatever. You would add what you
> want
> > for logon script in the second column of the spreadsheet. You could make
> > them all the same, or have one logon script for guests, one for
training,
> > one for normal users, and another for admins.

> > I have a program that dumps all user Distinguished Names to a
spreadsheet.
> > The spreadsheet filename to be created is passed to the program as a
> > parameter:

> > http://www.rlmueller.net/Create%20User%20List%203.htm

> > After adding logon scripts to the second column of the spreadsheet, you
> need
> > a program that reads the spreadsheet, binds to the users specified by
the
> DN
> > in the first column, and updates scriptPath with the value and in the
> second
> > column. I have a similar program that reads the spreadsheet created by
the
> > above program and uses it to reset passwords:

> > http://www.rlmueller.net/Set%20Passwords%203.htm

> > This program can be modified to update scriptPath instead. Here is a
> > modified VBScript program to do that:

> > Option Explicit
> > Dim strExcelPath, objExcel, objSheet, intRow, strUserDN, strLogonScript
> > Dim objUser

> > ' Check for required arguments.
> > If Wscript.Arguments.Count < 1 Then
> >   Wscript.Echo "Arguments <FileName> required. For example:" & vbCrLf _
> >     & "wscript CreateUserList3.vbs c:\MyFolder\UserList3.xls"
> >   Wscript.Quit(0)
> > End If

> > ' Spreadsheet file.
> > strExcelPath = Wscript.Arguments(0)

> > ' Bind to Excel object.
> > On Error Resume Next
> > Err.Clear
> > Set objExcel = CreateObject("Excel.Application")
> > If Err.Number <> 0 Then
> >   Err.Clear
> >   Wscript.Echo "Excel application not found."
> >   Wscript.Quit
> > End If
> > On Error GoTo 0

> > ' Open spreadsheet.
> > On Error Resume Next
> > Err.Clear
> > objExcel.Workbooks.Open strExcelPath
> > If Err.Number <> 0 Then
> >   Err.Clear
> >   Wscript.Echo "Spreadsheet cannot be opened:" & vbCrLf & strExcelPath
> >   Wscript.Quit
> > End If

> > ' Bind to worksheet.
> > Set objSheet = objExcel.ActiveWorkbook.Worksheets(1)

> > ' The first row of the spreadsheet is skipped (column headings). Each
> > ' row after the first is processed until the first blank entry in the
> > ' first column is encountered. The first column is the Distinguished
> > ' Name of the user, the second column is the logon script. The loop
> > ' binds to each user object and sets scriptPath. intRow is the row
> > ' number of the spreadsheet.
> > intRow = 2
> > Do While objSheet.Cells(intRow, 1).Value <> ""
> >   strUserDN = objSheet.Cells(intRow, 1).Value
> >   strLogonScript = objSheet.Cells(intRow, 2).Value
> >   On Error Resume Next
> >   Err.Clear
> >   Set objUser = GetObject("LDAP://" & strUserDN)
> >   If Err.Number <> 0 Then
> >     Err.Clear
> >     Wscript.Echo "User NOT found" & vbCrLf & strUserDN
> >   Else
> >     objUser.scriptPath = strLogonScript
> >     objUser.SetInfo
> >     If Err.Number <> 0 Then
> >       Err.Clear
> >       Wscript.Echo "LogonScript NOT set for " &vbCrLf & strUserDN
> >     End If
> >   End If
> >   On Error GoTo 0
> >   intRow = intRow + 1
> > Loop

> > ' Close the workbook.
> > objExcel.ActiveWorkbook.Close

> > ' Quit Excel.
> > objExcel.Application.Quit

> > ' Clean up.
> > Set objUser = Nothing
> > Set objExcel = Nothing
> > Set objSheet = Nothing

> > Wscript.Echo "Done"

> > --
> > Richard
> > Microsoft MVP Scripting and ADSI
> > http://www.rlmueller.net
> > --



Thu, 03 Nov 2005 02:53:12 GMT  
 Login Script
Maybe I did not make myself clear as to what I was trying to accomplish.
Currently in User Manager for Domains
the login script everyone is using is called %username%.bat. Username.bat
mounts the users home drive then makes
a call to another file called general.bat. This batch files mounts all the
global shares. I've created a single login batch
file called loginscript.bat which uses environment varibles instead of two
seperate batch files.

Now, how do I change the users login script name from eg. bobsmith.bat to
loginscript.bat? We currently have over
600 users so I wanted to use vbscript to make the changes.

Thanks



Thu, 03 Nov 2005 19:34:48 GMT  
 Login Script
Hi,

What I posted should do that. You want to change the "loginScript" attribute
of all users to "loginscript.bat". I was thinking that this is what you
would place in the second column of the spreadsheet created by the first
program (the program outputs each users NT logon name in the first column).
Then, the second program reads the spreadsheet and changes everyone's
"loginScript" attribute to the value in the second column,
"loginscript.bat".

This could be done with one program, and skip the spreadsheet, as long as
it's OK to change everyone in the domain:

' Determine NetBIOS domain name from WshNetwork object.
' Only works on NT clients or above.
' On Win9x clients you can hard code strNetBIOSDomain.
Set objNetwork = CreateObject("Wscript.Network")
strNetBIOSDomain = objNetwork.UserDomain

' Bind to domain.
Set objDomain = GetObject("WinNT://" & strNetBIOSDomain)

' Enumerate all users in domain.
' Modify loginScript attribute.
objDomain.Filter = Array("user")
For Each objUser In objDomain
  objUser.loginScript = "loginscript.bat"
  objUser.SetInfo
Next

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

Quote:
> Maybe I did not make myself clear as to what I was trying to accomplish.
> Currently in User Manager for Domains
> the login script everyone is using is called %username%.bat. Username.bat
> mounts the users home drive then makes
> a call to another file called general.bat. This batch files mounts all the
> global shares. I've created a single login batch
> file called loginscript.bat which uses environment varibles instead of two
> seperate batch files.

> Now, how do I change the users login script name from eg. bobsmith.bat to
> loginscript.bat? We currently have over
> 600 users so I wanted to use vbscript to make the changes.

> Thanks



Thu, 03 Nov 2005 23:43:14 GMT  
 Login Script
Thanks Rich, I'll try it Monday.

--

** Exchange Administrator in Training **


Quote:
> Hi,

> What I posted should do that. You want to change the "loginScript"
attribute
> of all users to "loginscript.bat". I was thinking that this is what you
> would place in the second column of the spreadsheet created by the first
> program (the program outputs each users NT logon name in the first
column).
> Then, the second program reads the spreadsheet and changes everyone's
> "loginScript" attribute to the value in the second column,
> "loginscript.bat".

> This could be done with one program, and skip the spreadsheet, as long as
> it's OK to change everyone in the domain:

> ' Determine NetBIOS domain name from WshNetwork object.
> ' Only works on NT clients or above.
> ' On Win9x clients you can hard code strNetBIOSDomain.
> Set objNetwork = CreateObject("Wscript.Network")
> strNetBIOSDomain = objNetwork.UserDomain

> ' Bind to domain.
> Set objDomain = GetObject("WinNT://" & strNetBIOSDomain)

> ' Enumerate all users in domain.
> ' Modify loginScript attribute.
> objDomain.Filter = Array("user")
> For Each objUser In objDomain
>   objUser.loginScript = "loginscript.bat"
>   objUser.SetInfo
> Next

> --
> Richard
> Microsoft MVP Scripting and ADSI
> http://www.rlmueller.net
> --


> > Maybe I did not make myself clear as to what I was trying to accomplish.
> > Currently in User Manager for Domains
> > the login script everyone is using is called %username%.bat.
Username.bat
> > mounts the users home drive then makes
> > a call to another file called general.bat. This batch files mounts all
the
> > global shares. I've created a single login batch
> > file called loginscript.bat which uses environment varibles instead of
two
> > seperate batch files.

> > Now, how do I change the users login script name from eg. bobsmith.bat
to
> > loginscript.bat? We currently have over
> > 600 users so I wanted to use vbscript to make the changes.

> > Thanks



Fri, 04 Nov 2005 07:06:33 GMT  
 Login Script

Quote:

>How can I change all the users login script using vbscript? We are running
>NT 4.0 servers.
>The last domain administrator created individual scripts for each user. I've
>created one
>login script for everyone and I need a way to automate the change.

You may kill yourself...  :)

Create the new script and place it in the Netlogon share of each
domain controller (normally \\winnt\system32\repl\import\scripts).  In
the User Manager for Doamins for your domain, highlight all the users
you wish to change to the new single login script.  Click on User ->
Properties.  Change the login script name to your new name.  Click
Okay.  Have a beer.

Jeff



Fri, 04 Nov 2005 22:17:29 GMT  
 
 [ 8 post ] 

 Relevant Pages 

1. vbscript login scripts - starting a script from the Windows 95 command prompt

2. Script to remove login script by OU.

3. Using a WSH Script as a Login Script

4. Login script - Script running before user logs on.

5. Login script - Script running before user logs on.

6. Executing a WSH script as a login script

7. VBScript NT Login Script - checking for group membership

8. Login Script

9. help me on the login script

10. WSH/VBS Login Script Calls

11. Starting explorer with login script

12. Fake Login Script

 

 
Powered by phpBB® Forum Software