Jump to content

User Permissions


dmaey2k
 Share

Recommended Posts

I'm not sure about the username change but you can change the password from the command line using (net user):

http://www.allthingsmarked.com/2006/08/21/...e-command-line/

Thanks Weapon,

But i guess i need to be more specific ... i want to remotely connect to a PC ... user runas command to run as the local administrator and then change the Administrator username back to Administrator (most of our users change the local account to some other name - like Bozo :-)) ... and then change the password to something else ...

I am a good network admin but not too good at scripting ... i used to write batch files for Novell a long .. long time ago ... but if you don't use it you lose it ... thanks for all the help

Link to comment
Share on other sites

Hi,

if you are working in a domain. Then create a kind of logon script which checks the name and does your job.

So long,

Mega

Scripts & functions Organize Includes Let Scite organize the include files

Yahtzee The game "Yahtzee" (Kniffel, DiceLion)

LoginWrapper Secure scripts by adding a query (authentication)

_RunOnlyOnThis UDF Make sure that a script can only be executed on ... (Windows / HD / ...)

Internet-Café Server/Client Application Open CD, Start Browser, Lock remote client, etc.

MultipleFuncsWithOneHotkey Start different funcs by hitting one hotkey different times

Link to comment
Share on other sites

  • Developers

Thanks Weapon,

But i guess i need to be more specific ... i want to remotely connect to a PC ... user runas command to run as the local administrator and then change the Administrator username back to Administrator (most of our users change the local account to some other name - like Bozo :-)) ... and then change the password to something else ...

I am a good network admin but not too good at scripting ... i used to write batch files for Novell a long .. long time ago ... but if you don't use it you lose it ... thanks for all the help

What admin level account would you use to run the script when you don't know the administrator's name and password ?

This script will:

- retrieve current administrator account name

- Change it to what you want it to be and sets the password

$AdminUsername = "Administrator"
$AdminPassword = "StayOFF"
;
$oMyError = ObjEvent("AutoIt.Error","MyErrFunc"); Install a custom error handler 
; Get current Admin account
$Admin = GetAdministratorName(@ComputerName)
ConsoleWrite('Current Administrator accountname = ' & $Admin & @lf)
; Rename User
If $Admin <> $AdminUsername Then
    $NewUser = $AdminUsername
    $oUser = ObjGet("WinNT://" & @ComputerName & "/" & $Admin & ",user")
    $oComputer = ObjGet("WinNT://" & @ComputerName)
    $oNewUser = $oComputer.MoveHere($oUser.ADsPath, $NewUser)
; Set Password
    $oUser = ObjGet("WinNT://" & @ComputerName & "/" & $AdminUsername & ",user")
    $oUser.SetPassword ($AdminPassword)
    $oUser.SetInfo
; check it rename was successful
    $Admin = GetAdministratorName(@ComputerName)
    ConsoleWrite('New Administrator accountname = ' & $Admin & @lf)
EndIf

Func GetAdministratorName($ComputerName)
    Dim $UserSID, $oWshNetwork, $oUserAccount
    $objWMIService = objGet( "winmgmts:{impersonationLevel=impersonate}!//"  & $ComputerName & "/root/cimv2")
    $oUserAccounts = $objWMIService.ExecQuery("Select Name, SID from Win32_UserAccount WHERE Domain = '" & $ComputerName & "'")
    For $oUserAccount In $oUserAccounts
        If StringLeft($oUserAccount.SID, 9) = "S-1-5-21-" And _
            StringRight($oUserAccount.SID, 4) = "-500" Then
            Return $oUserAccount.Name
        Endif
    Next
EndFunc

Func MyErrFunc() 
   $HexNumber=hex($oMyError.number,8) 
   Msgbox(0,"","We intercepted a COM Error !" & @CRLF & _
                "Number is: " & $HexNumber & @CRLF & _
                "Linenbr is: " & $oMyError.scriptline  & @CRLF & _
                "Description is: " & $oMyError.description  & @CRLF & _
                "Windescription is: " & $oMyError.windescription ) 

   SetError(1); something to check for when this function returns 
Endfunc
Edited by Jos

SciTE4AutoIt3 Full installer Download page   - Beta files       Read before posting     How to post scriptsource   Forum etiquette  Forum Rules 
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Link to comment
Share on other sites

What admin level account would you use to run the script when you don't know the administrator's name and password ?

This script will:

- retrieve current administrator account name

- Change it to what you want it to be and sets the password

$AdminUsername = "Administrator"
$AdminPassword = "StayOFF"
;
$oMyError = ObjEvent("AutoIt.Error","MyErrFunc"); Install a custom error handler 
; Get current Admin account
$Admin = GetAdministratorName(@ComputerName)
ConsoleWrite('Current Administrator accountname = ' & $Admin & @lf)
; Rename User
If $Admin <> $AdminUsername Then
    $NewUser = $AdminUsername
    $oUser = ObjGet("WinNT://" & @ComputerName & "/" & $Admin & ",user")
    $oComputer = ObjGet("WinNT://" & @ComputerName)
    $oNewUser = $oComputer.MoveHere($oUser.ADsPath, $NewUser)
; Set Password
    $oUser = ObjGet("WinNT://" & @ComputerName & "/" & $AdminUsername & ",user")
    $oUser.SetPassword ($AdminPassword)
    $oUser.SetInfo
; check it rename was successful
    $Admin = GetAdministratorName(@ComputerName)
    ConsoleWrite('New Administrator accountname = ' & $Admin & @lf)
EndIf

Func GetAdministratorName($ComputerName)
    Dim $UserSID, $oWshNetwork, $oUserAccount
    $objWMIService = objGet( "winmgmts:{impersonationLevel=impersonate}!//"  & $ComputerName & "/root/cimv2")
    $oUserAccounts = $objWMIService.ExecQuery("Select Name, SID from Win32_UserAccount WHERE Domain = '" & $ComputerName & "'")
    For $oUserAccount In $oUserAccounts
        If StringLeft($oUserAccount.SID, 9) = "S-1-5-21-" And _
            StringRight($oUserAccount.SID, 4) = "-500" Then
            Return $oUserAccount.Name
        Endif
    Next
EndFunc

Func MyErrFunc() 
   $HexNumber=hex($oMyError.number,8) 
   Msgbox(0,"","We intercepted a COM Error !" & @CRLF & _
                "Number is: " & $HexNumber & @CRLF & _
                "Linenbr is: " & $oMyError.scriptline  & @CRLF & _
                "Description is: " & $oMyError.description  & @CRLF & _
                "Windescription is: " & $oMyError.windescription ) 

   SetError(1); something to check for when this function returns 
Endfunc

Many THANKS Jos ...

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...