|
|
|
|
||||||
![]() |
|
|
LinkBack | Outils de la discussion |
|
|
#1 |
|
Messages: n/a
Hébergeur: |
Hello,
I am hosting an FTP site on a windows 2003 server. I need to rebuild this server. I have about 50 local user accounts on this server. I have a text file that contains the user account name, password, local path (for home directory), and description. I would like to be able to use a script to read the text file for the account usernames, passwords, local path, etc.. I am not that knowledgeable with scripting and am having trouble creating the script. any will be greatly appreciated. Thanks, PT |
|
|
|
#2 |
|
Messages: n/a
Hébergeur: |
PT wrote:
> I am hosting an FTP site on a windows 2003 server. I need to rebuild > this server. I have about 50 local user accounts on this server. I > have a text file that contains the user account name, password, local > path (for home directory), and description. > > I would like to be able to use a script to read the text file for the > account usernames, passwords, local path, etc.. I am not that > knowledgeable with scripting and am having trouble creating the > script. any will be greatly appreciated. A VBScript program to create a local user on a computer would be similar to: ============= ' Specify NetBIOS name of computer. strComputer = "MyComputer" ' Bind to the computer object. Set objComputer = GetObject("WinNT://" & strComputer) ' Create user JSmith. Set objUser = objComputer.Create("user", "JSmith") objUser.SetInfo ' Enable the account. objUser.AccountDisabled = False ' Assign Home Directory. objUser.homeDirectory = "\\MyServer\Home\JSmith" ' Set Password. objUser.SetPassword "xyz$321" ' Save changes. objUser.SetInfo ============ You can use the FileSystemObject to read from a text file. If the values are delimited by commas. Something similar to below can be used: ========= Const ForReading = 1 ' Specify NetBIOS name of computer. strComputer = "MyComputer" ' Bind to the computer object. Set objComputer = GetObject("WinNT://" & strComputer) ' Specify text file with local account information. ' Format assumed is: ' username,password,homedirectory strFile = "c:\scripts\localusers.txt" ' Open the file for read access. Set objFSO = CreateObject("Scripting.FileSystemObject") Set objFile = objFSO.OpenTextFile(strFile, ForReading) ' Read the file. Do Until objFile.AtEndOfStream strLine = Trim(objFile.ReadLine) ' Skip blank lines. If (strLine <> "") Then ' Parse values delimited by commas. arrValues = Split(strLine, ",") strName = arrValues(0) strPassword = arrValues(1) strHomeDir = arrValues(2) ' Create local user object. ' Trap error if user already exists or name is invalid. On Error Resume Next Set objUser = objComputer.Create("user", strName) objUser.SetInfo If (Err.Number <> 0) Then ' Restore normal error handling. On Error GoTo 0 Wscript.Echo "Unable to create user " & strName Else ' Restore normal error handling. On Error GoTo 0 ' Enable the account. objUser.AccountDisabled = False ' Assign Home Directory. objUser.homeDirectory = strHomeDir ' Set Password. objUser.SetPassword strPassword ' Save changes. objUser.SetInfo End If End If Loop ' Clean up. objFile.Close -- Richard Mueller Microsoft MVP Scripting and ADSI Hilltop Lab - http://www.rlmueller.net -- |
|
![]() |
| Outils de la discussion | |
|
|