dmaey2k Posted January 18, 2008 Share Posted January 18, 2008 Is it possible (and it probably is) to make a script that will run as administrator and change the username on the computer and set the password to blank or something else on a local machine? Link to comment Share on other sites More sharing options...
weaponx Posted January 18, 2008 Share Posted January 18, 2008 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/ Link to comment Share on other sites More sharing options...
dmaey2k Posted January 18, 2008 Author Share Posted January 18, 2008 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 More sharing options...
Xenobiologist Posted January 18, 2008 Share Posted January 18, 2008 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 More sharing options...
Developers Jos Posted January 18, 2008 Developers Share Posted January 18, 2008 (edited) 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 helpWhat 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 expandcollapse popup$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 January 18, 2008 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 More sharing options...
dmaey2k Posted January 18, 2008 Author Share Posted January 18, 2008 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 expandcollapse popup$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 More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now