Startup script doesn´t run
Folks, I´m trying to use the following code as a startup script: '''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''' '========================================================================== ' ' NAME: Local Admin Password Change.vbs ' ' AUTHOR: Gene Magerr ' EMAIL: genemagerr@hotmail.com ' ' COMMENT: This script will change the local administrators password ' on all of the computers in the c:\servers.txt file. ' ' VERSION HISTORY: ' 1.0 01/17/2008 Initial release ' 1.1 01/24/2008 Did some work on the formatting in email. ' '========================================================================== '========================================================================== ' OPTIONS '========================================================================== Option Explicit On Error Resume Next '========================================================================== ' VARIABLE DECLARATIONS '========================================================================== Dim objFSO, strUser, strPassword, objTextFile Dim strComputer, objUser, objGroup, arrComputers, wshnetwork Dim objMessages, objMessage, objEmail, strMessage, AdminName, colAccounts Set objFSO = CreateObject("Scripting.FilesystemObject") '========================================================================== ' STATIC VARIABLE ASSIGNMENTS '========================================================================== Const FOR_READING = 1, FOR_WRITING = 2, FOR_APPENDING = 8 '========================================================================== ' INITIAL SETUP '========================================================================== ' Define a conta local que terá sua senha redefinida. strUser = "ADMIN" ' Define hostname da máquina local. set wshnetwork = createobject("wscript.network") strComputer = wshnetwork.computername If Not objFSO.FileExists("c:\passwordChanger.log") Then objFSO.CreateTextFile("c:\passwordChanger.log") End If Set objMessages = objFSO.OpenTextFile("c:\passwordChanger.log", 2) objMessages.WriteLine(Now & vbTab & "Starting script..." & vbCrLf) '========================================================================== ' MAIN SCRIPT CODE '========================================================================== If QueryForUser(strUser) = 0 Then Set colAccounts = GetObject("WinNT://" & strComputer & "") Set objUser = colAccounts.Create("User", strUser) strPassword = generatePassword(strComputer) objUser.SetPassword strPassword objUser.SetInfo 'add to administrators group Set objGroup = GetObject("WinNT://" & strComputer & "/Administrators,Group") objGroup.Add objUser.ADsPath If Err.Number <> 0 Then 'Display an error message & clear the error objMessages.WriteLine Now & vbTab & "Unable to create " & strUser & " user object on server " & strComputer objMessages.WriteLine "Error #" & Err.Number objMessages.WriteLine "Error Message : " & Err.Description objMessages.WriteLine "========================================================================" Err.Clear Else objMessages.WriteLine Now & vbTab & "User " & strUser & " created on: " & strComputer objMessages.WriteLine Now & vbTab & "Password is:" & strPassword objMessages.WriteLine "========================================================================" End If Else 'Connect to Administrator acccount on server using WinNT provider Set objUser = GetObject("WinNT://" & strComputer & "/" & strUser & ",User") 'Check if we connected to the user object successfully If Err.Number <> 0 Then 'Display an error message & clear the error objMessages.WriteLine Now & vbTab & "Unable to connect to " & strUser & " user object on server " & strComputer objMessages.WriteLine "Error #" & Err.Number objMessages.WriteLine "Error Message : " & Err.Description objMessages.WriteLine "========================================================================" Err.Clear Else 'Change the password strPassword = generatePassword(strComputer) objUser.SetPassword strPassword objUser.SetInfo ' Save Changes If Err.Number <> 0 Then 'Display an error message & clear the error objMessages.WriteLine Now & vbTab & "Unable to change the " & strUser & " password on server " & strComputer objMessages.WriteLine "Error #" & Err.Number objMessages.WriteLine "Error Message : " & Err.Description objMessages.WriteLine "========================================================================" Err.Clear Else objMessages.WriteLine Now & vbTab & "Password successfully changed for " & strUser & " user on: " & strComputer objMessages.WriteLine Now & vbTab & "New password is:" & strPassword objMessages.WriteLine "========================================================================" End If End If End If objMessages.WriteLine vbCrLf & Now & vbTab & "Ending script..." objMessages.Close Set objMessages = objFSO.OpenTextFile("C:\passwordChanger.log", 1) strMessage = objMessages.ReadAll objMessages.Close Set objEmail = CreateObject("CDO.Message") objEmail.Sender = "passwordChanger@corp.arcon.com.br" objEmail.To = "dsantos@corp.arcon.com.br" objEmail.Subject = "Local Administrators Password Change Results (DEBUG)" objEmail.TextBody = objEmail.TextBody & strMessage objEmail.TextBody = objEmail.TextBody & "Script ran on " & Date() objEmail.Configuration.Fields.Item ("http://schemas.microsoft.com/cdo/configuration/sendusing") = 2 objEmail.Configuration.Fields.Item ("http://schemas.microsoft.com/cdo/configuration/smtpserver") = "10.21.0.64" objEmail.Configuration.Fields.Item ("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = 25 objEmail.Configuration.Fields.Update 'objEmail.CC = "DL-infraestrutura@corp.arcon.com.br" objEmail.Send Set objEmail = Nothing '========================================================================== ' SUBS AND FUNCTIONS '========================================================================== Function generatePassword(byval strComputer) generatePassword = "XXX#2011-" & LCASE(strComputer) End Function Function QueryForUser(byval strUserName) Dim found found = 0 Set objlocal = GetObject("WinNT://.") objlocal.Filter = Array("user") For Each User In objlocal If lcase(User.Name) = lcase(strUserName) Then found = 1 End If Next If found = 1 Then QueryForUser = 1 Else QueryForUser = 0 End If End Function '''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''' The code runs ok when launched locally, but when it runs at the startup through the gpo process the passwordChanger.log is only created and never writen. Any suggestions?
May 10th, 2011 8:39pm

You might ask them here. http://social.technet.microsoft.com/Forums/en-US/ITCG/threads Regards, Dave Patrick .... Microsoft Certified Professional Microsoft MVP [Windows]
Free Windows Admin Tool Kit Click here and download it now
May 10th, 2011 11:13pm

Startup scripts run with System privileges on the local computer. Does SYSTEM have write permission in c:\ ? Also, rather than creating the log file in one statement, then opening it another, would it help to just open the file? If it does not exist, it will get created, and if it does exist it will get overwritten, if you use: Set objMessages = objFSO.OpenTextFile("c:\passwordChanger.log, 2, True) Finally, you could do this remotely yourself in bulk, as long as the computers are available. I have example VBScript programs to reset the password for the local Administrator user on all computers in the domain (or in a list) linked here: http://www.rlmueller.net/Reset_Local_Admin_Passwords.htm The program writes a log, and maintains a list of computers that have not been processed. You can run the program repeatedly until the list is empty, or start with a text file of computer names if you don't want to process all computers in the domain. As long as you are a member of "Domain Admins", and this group is a member of the local Administrators group on all computers, you can reset the passwords, and also create accounts remotely.Richard Mueller - MVP Directory Services
May 10th, 2011 11:33pm

This topic is archived. No further replies will be accepted.

Other recent topics Other recent topics