PHWinfo banniere

Titres
PORTAIL ANNUAIRE ARTICLES COMPARATEUR HÉBERGEURS DEVIS FORUMS RÉDUCTEUR D'URL
Précédent   PHWinfo > Forums Hébergement > Forum Hébergement serveur > ms..win.server.scripting > Script to recreate local accounts
S'inscrire FAQ Membres Recherche Messages du jour Marquer les forums comme lus
Script to recreate local accounts

Réponse
 
LinkBack Outils de la discussion
Vieux 29/11/2007, 23h41   #1
2222gggg@ureach.com
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Script to recreate local accounts

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
  Réponse avec citation
Vieux 30/11/2007, 00h44   #2
Richard Mueller [MVP]
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: Script to recreate local accounts

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
--


  Réponse avec citation
Réponse


Outils de la discussion

Règles de messages
Vous ne pouvez pas créer de nouvelles discussions
Vous ne pouvez pas envoyer des réponses
Vous ne pouvez pas envoyer des pièces jointes
Vous ne pouvez pas modifier vos messages

Les balises BB sont activées : oui
Les smileys sont activés : oui
La balise [IMG] est activée : oui
Le code HTML peut être employé : non
Trackbacks are oui
Pingbacks are oui
Refbacks are oui


Fuseau horaire GMT +1. Il est actuellement 03h11.


Édité par : vBulletin® version 3.7.2
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.2.0 RC5 Tous droits réservés.
Version française #16 par l'association vBulletin francophone
PHWinfo est un site Éducation Sans Frontières
Ad Management by RedTyger
©Tous droits réservés par les parties respectives
Page generated in 0,09649 seconds with 10 queries