Re: Zmiana nazwy uzytkownika

Autor: Michal Biek <mb_at_2.pl.invalid>
Data: Fri 29 Sep 2006 - 18:41:20 MET DST
Message-ID: <efjibb$bqm$1@opal.icpnet.pl>
Content-Type: text/plain; format=flowed; charset="iso-8859-2"; reply-type=response

Tomasz Onyszko log:
[...]
Sprytnie.
Z całym (ciąglym) szacunkiem i podziwem Tomaszu, ale wyszło i tak na moje:-)
Nie podałeś 5'-owego "gotowca" zatem "nie chcem, ale muszem" ;-)

Change_UserName2.vbs (do użycia bezpośrednio na local)
---------------------------------
sNewUser = "Aya"
Set oWshNet = CreateObject("WScript.Network")
sComputerName = oWshNet.ComputerName
sOldUser = "Bee"

On Error Resume Next
Set oUser = GetObject("WinNT://" & sComputerName & "/" _
     & sOldUser & ", user")
If LCase(sNewUser) <> LCase(sOldUser) Then
    Set oComputer = GetObject("WinNT://" & sComputerName)
    Set oNewUser = oComputer.MoveHere(oUser.ADsPath, sNewUser)
End If
On Error Goto 0

Function GetUserName(sComputerName)
    Dim sUserSID, oWshNetwork, oUserAccount

 Set oUserAccounts = GetObject( _
    "winmgmts:{impersonationLevel=impersonate}!//" _
    & sComputerName & "/root/cimv2").ExecQuery( _
    "Select Name, SID from Win32_UserAccount WHERE Domain = '" _
    & sComputerName & "'")

 On Error Resume Next
   For Each oUserAccount In oUserAccounts
     If Left(oUserAccount.SID, 9) = "S-1-5-21-" And _
       Right(oUserAccount.SID, 4) = "-205" Then
       GetUserName = oUserAccount.Name
      Exit For
    End if
  Next
End Function
------------------

-- 
Best regards! :-)
Received on Fri Sep 29 18:45:13 2006

To archiwum zostało wygenerowane przez hypermail 2.1.8 : Fri 29 Sep 2006 - 19:42:04 MET DST