Login | |
|
 |
Re: Script to Change Local Administrator Password - 5/11/2005 4:54:47 AM
|
|
 |
|
| |
mbouchard
Posts: 1906
Score: 14
Joined: 5/15/2003
From: USA
Status: offline
|
Do you have active directory? If so, why not do this via policy?
|
|
| |
|
|
|
 |
Re: Script to Change Local Administrator Password - 5/12/2005 5:55:48 AM
|
|
 |
|
| |
Caer
Posts: 29
Score: 0
Joined: 4/26/2005
From: USA
Status: offline
|
Thanks! FYI the reason I was wanting to use a startup or logon script is because the domain im on is on a global scale from Germany, USA, Canada, and Mexico. For me to ensure that all of the remote users, folks with laptops, etc.. get the script ('cause they all log on at way different times) i have to have it run as a startup/logon script. Ok. Here is what i finally ended up with for my scripts. LocalAdminPasswordChange.vbs ****************************** '========================================================================== ' ' VBScript Source File -- Created with SAPIEN Technologies PrimalScript 3.1 ' ' NAME: Local Admin Password Change ' ' AUTHOR: PutYourNameHERE!!!! ' DATE : 4/22/2005 ' ' COMMENT: This script is designed to be used as a login script ' that will change the Password of the Local Administrator ' on the computer that it is run on using creditials from a ' specified user account and password. ' NOTE: It calls the ChangePassword.vbs from a specified path in this ' script. If the ChangePassword.vbs file is not in the path, Then ' the script will not change the local admin password. '========================================================================== '========================================================================== '********** IMPORTANT INFORMATION ********************** '* Because .vbs files are easy to view and this one contains a clear text '* password it is important to use the Microsoft Script encoder to keep '* sensitive information unavailable to someone using a text editor. '* The encoder can be found at: '* http://msdn.microsoft.com/library/default.asp?url=/downloads/list/webdev.asp '* It is a command line tool FYI. '========================================================================== ' ** First we set the variables for the script ** ' Dim WshShell, objFSO ' ** sUser is the Username ' ** sPass is the Users password ' ** sCommand is the command that you want run ' ** ' ** You can replace these string variables to any user/password/command ' ** combo that you need to run on a pc. ' ** NOTE: If you change the sPass field be sure to retain the ' ** quotes and the ~ at the end of the actual password, it ' ** is the carriage return character. sUser = "username@domain.net" sPass = "userpassword~" ' ** USAGE: sCommand = "wscript <path_to_scripts>\<your_script_here.vbs" ' ** or you can write in any command that needs to be run under ' ** a specific users account. sCommand = "wscript \\Servername\Sharename\changepassword.vbs" ' ** This is where we setup the working environment for the script to run in. Set objComputer = CreateObject("Shell.LocalMachine") Set WshNetwork = CreateObject("WScript.Network") Set WshShell = CreateObject("WScript.Shell") Set WshEnv = WshShell.Environment("Process") WinPath = WshEnv("SystemRoot")&"\System32\runas.exe" Set objFSO = CreateObject("Scripting.FileSystemObject") '** Here we will check to see if this script has run on this computer. '** If the file exist then we will end the script. If objFSO.FileExists("C:\ScriptLog.txt") Then WScript.Quit Else ' ** Here we open the Finished.txt and append the name of the computer ' ** that was just changed and the date it happened. Set objTextFile = objFSO.OpenTextFile("\\Servername\Sharename\Finished.txt", 8, True) objTextFile.WriteLine(objComputer.MachineName) & " " & Date() & " " & Time() & " " & (WshNetwork.UserName) objTextFile.Close ' ** Here we write a .txt file to the root of c: for verification that the script ' ** has been run on this computer. Set objFile = objFSO.CreateTextFile("C:\ScriptLog.txt") End If ' ** This is the meat of the program and where the actual command is run. rc = WshShell.Run ("runas /noprofile /user:" & sUser & " " & Chr(34) & sCommand & Chr(34)) ' ** This gives the command window the time to open. WScript.Sleep 900 ' ** This will grab the active command window to send the password to. WshShell.AppActivate(WinPath) ' ** This will send the password to the waiting window. WshShell.SendKeys sPass WScript.quit ********************************************* Changepassword.vbs ********************************************* '========================================================================== ' ' VBScript Source File -- Created with SAPIEN Technologies PrimalScript 3.1 ' ' NAME: Change Password ' ' AUTHOR: PutYourNameHERE!!!! ' DATE : 4/22/2005 ' ' COMMENT: This script is designed to work in conjuntion with ' the LocalAdminPasswordChange.vbs script as it must ' be run with administrative priviledges for the script ' to function properly. '========================================================================== '========================================================================== '********** IMPORTANT INFORMATION ********************** '* Because .vbs files are easy to view and this one contains a clear text '* password it is important to use the Microsoft Script encoder to keep '* sensitive information unavailable to someone using a text editor. '* The encoder can be found at: '* http://msdn.microsoft.com/library/default.asp?url=/downloads/list/webdev.asp '* It is a command line tool FYI. '========================================================================== ' ** Setup the variables and working environment for the script ** Set WshNetwork = WScript.CreateObject("WScript.Network") strComputer = WshNetwork.ComputerName '* This gets the name of the current computer and then '* retrieves the \\<computername>\Administrator account '* as the object that we want to work with. strComputer = "." Set objUser = GetObject("WinNT://" & strComputer & "/Administrator,user") ' ******* This sets the Administrator Password here ************************** ' ** NOTE: Type in quotes what you would like the new ' ** Local Administrator Account password to be set ' ** to, but keep in mind password complexity restrictions ' ** for your login server. objUser.SetPassword "new.password.goes.here" ' <--- this will be the new admin password. objUser.SetInfo ********************************************************** You guys are great! Thanks again! Caer ><
|
|
| |
|
|
|
 |
RE: Script to Change Local Administrator Password - 1/23/2007 2:25:08 AM
|
|
 |
|
| |
dm_4ever
Posts: 2593
Score: 46
Joined: 6/29/2006
From: Orange County, California
Status: offline
|
Loop through the administrators group perhaps? Set objGroup = GetObject("WinNT://" & strComputer & "/Administrators,group") For Each objMember In objGroup.Members Wscript.Echo objMember.Name Next
_____________________________
dm_4ever My philosophy: K.I.S.S - Keep It Simple Stupid Read Me: http://www.visualbasicscript.com/m_24727/tm.htm Frequently Asked Stuff: http://www.visualbasicscript.com/m_47117/tm.htm
|
|
| |
|
|
|
|
|