Photo Gallery Member List Search Calendars FAQ Ticket List Log Out


Add Network Group as Local Administrators and Change local Administrator Password - Web Interface

 
Logged in as: Guest
arrSession:exec spGetSession 2,16,62161
 Active Users: There are 0 members and 0 guests.
 Users viewing this topic: none
 

 

 
  
  Printable Version
All Forums >> [Scripting] >> Post a VBScript >> Add Network Group as Local Administrators and Change local Administrator Password - Web Interface
  Do you like VisualBasicScript.com? Link to us and help spread the word about our forum. Thanks!
Page: [1]
Login
Message << Older Topic   Newer Topic >>
 Add Network Group as Local Administrators and Change lo... - 7/4/2008 1:23:49 AM   
  jeferson.propheta

 

Posts: 11
Score: 0
Joined: 8/27/2007
Status: offline
Hello Friends out there, here you'll find a Script that remotely add a domain group as member of local administrators groups, and also provide you as an option, changing the local administrator password.
In this script it's not needed write down user neither passwords in the code.
Special Thanks to Scott Mikesell and FF.
Enjoy yourself!!!



      


'*******************************************************************************************************
'Local Administrator Group ADD
'wrote by Jeferson Propheta and Scott Mikesell
'*******************************************************************************************************
On Error Resume Next
'*******************************************************************************************************
'Constants
'*******************************************************************************************************
Const ForWriting = 2
Const ADS_SECURE_AUTHENTICATION = &H1
'*******************************************************************************************************
'Sets
'*******************************************************************************************************
InterfaceFile    = "C:\LocalAdmin.htm"
AcceptLocalPass     = "NO"
Set     WshShell = WScript.CreateObject("WScript.Shell")
Set       objFSO = Wscript.CreateObject("Scripting.FileSystemObject")
Set  objExplorer = WScript.CreateObject("InternetExplorer.Application", "IE_")
Set  objHTMLFile = objFSO.OpenTextFile (InterfaceFile, ForWriting, True)
Set     HtmlFile = objFSO.GetFile(InterfaceFile)

'*******************************************************************************************************
'Writing Web Interface - Head
'*******************************************************************************************************
objHTMLFile.WriteLine     "<HTML>"
objHTMLFile.WriteLine     "<TITLE>Change Admin Group and Local Admin Pass</TITLE>"
objHTMLFile.WriteLine    "<SCRIPT LANGUAGE="  & Chr(34) & "VBScript" & Chr(34) & ">"
objHTMLFile.WriteLine     "Sub RunScript"
objHTMLFile.WriteLine     "OKClicked.Value = " & Chr(34) & "OK" & Chr(34) & ""
objHTMLFile.WriteLine     "End Sub"
objHTMLFile.WriteLine     "Sub CancelScript"
objHTMLFile.WriteLine     "OKClicked.Value = " & Chr(34) & "Cancelled" & Chr(34) & ""
objHTMLFile.WriteLine     "End Sub"
objHTMLFile.WriteLine     "</SCRIPT>"
objHTMLFile.WriteLine   "<SCRIPT LANGUAGE="  & Chr(34) & "VBScript" & Chr(34) & ">"
objHTMLFile.WriteLine   "Sub Window_OnLoad"
objHTMLFile.WriteLine   "iTimerID = window.setInterval(" & Chr(34) & "ShowSplash" & Chr(34) & ", 2000)"
objHTMLFile.WriteLine   "End Sub"
objHTMLFile.WriteLine   "Sub ShowSplash"
objHTMLFile.WriteLine   "Splash.Style.Display = " & Chr(34) & "None" & Chr(34)
objHTMLFile.WriteLine   "Main.Style.Display = "   & Chr(34) & "Inline" & Chr(34)
objHTMLFile.WriteLine   "End Sub"
objHTMLFile.WriteLine   "</SCRIPT>"
'*******************************************************************************************************
'Writing Web Interface - Body
'*******************************************************************************************************
objHTMLFile.WriteLine     "<BODY>"
objHTMLFile.WriteLine   "<DIV id=" & Chr(34) & "Splash" & Chr(34) & " STYLE=" & Chr(34) & "Background-color:buttonface;Height:200;Width:400;Border:0.1mm solid black;position:relative;top:100;left:200;font:14pt Tahoma;" & Chr(34) & ">"
objHTMLFile.WriteLine   "<CENTER>"
objHTMLFile.WriteLine   "<br><br>"
objHTMLFile.WriteLine   "Add Group as Local Admin and Change Local Admin Pass<br>"
objHTMLFile.WriteLine   "Version 1.1.008<br><br><br>"
objHTMLFile.WriteLine   "<font size="  & Chr(34) & "2" & Chr(34) & ">Copyright 2008. All rights reserved.</font>"
objHTMLFile.WriteLine   "</CENTER>"
objHTMLFile.WriteLine   "</DIV>"
objHTMLFile.WriteLine   "<DIV id="     & Chr(34) & "Main" & Chr(34) & " STYLE=" & Chr(34) & "display:none;position:absolute" & Chr(34) & ">"
objHTMLFile.WriteLine     "<font size="  & Chr(34) & "2" & Chr(34) & " face=" & Chr(34) & "Tahoma" & Chr(34) & ">"
objHTMLFile.WriteLine     "<H3> Add Network Group as Local Admin</h3>"
'*******************************************************************************************************
'Writing Web Interface - Form Inputs
'*******************************************************************************************************
objHTMLFile.WriteLine     "AD Domain<br>"
objHTMLFile.WriteLine   "<select id="      & Chr(34) & "Domain" & Chr(34) & " style=" & Chr(34) & "font-family: Tahoma; font-size: 8pt; border: 1px solid #000000;; background-color:#EEEEEE" & Chr(34) & " >"
objHTMLFile.WriteLine   "<optgroup label=" & Chr(34) & "North America" & Chr(34) & ">"
objHTMLFile.WriteLine   "<option value ="  & Chr(34) & "USA" & Chr(34) & ">USA</option>"
objHTMLFile.WriteLine   "<option value ="  & Chr(34) & "CAN" & Chr(34) & ">CANADA</option>"
objHTMLFile.WriteLine   "</optgroup>"
objHTMLFile.WriteLine   "<optgroup label=" & Chr(34) & "South America" & Chr(34) & ">"
objHTMLFile.WriteLine   "<option value ="  & Chr(34) & "BRA" & Chr(34) & ">BRAZIL</option>"
objHTMLFile.WriteLine   "<option value ="  & Chr(34) & "ARG" & Chr(34) & ">ARGENTINA</option>"
objHTMLFile.WriteLine   "</optgroup>"
objHTMLFile.WriteLine   "<optgroup label=" & Chr(34) & "Europe" & Chr(34) & ">"
objHTMLFile.WriteLine   "<option value ="  & Chr(34) & "ITA" & Chr(34) & ">ITALY</option>"
objHTMLFile.WriteLine   "<option value ="  & Chr(34) & "SPA" & Chr(34) & ">SPAIN</option>"
objHTMLFile.WriteLine   "</optgroup>"
objHTMLFile.WriteLine   "<optgroup label=" & Chr(34) & "Asia Pacific" & Chr(34) & ">"
objHTMLFile.WriteLine   "<option value ="  & Chr(34) & "JPN" & Chr(34) & ">JAPAN</option>"
objHTMLFile.WriteLine   "<option value ="  & Chr(34) & "CHI" & Chr(34) & ">CHINA</option>"
objHTMLFile.WriteLine   "</optgroup>"
objHTMLFile.WriteLine   "</select>"
objHTMLFile.WriteLine     "<br><br>Enter Group to add as Local Admin<br>"
objHTMLFile.WriteLine     "<input type="     & Chr(34) & "Text" & Chr(34) & " name=" & Chr(34) & "Group" & Chr(34) & " value=" & Chr(34) & "YOURGroup.Desktop.Admins" & Chr(34) & " size=" & Chr(34) & "40" & Chr(34) & " style=" & Chr(34) & "font-family: Tahoma; font-size: 8pt; border: 1px solid #000000;; background-color:#EEEEEE" & Chr(34) & "></p>"
objHTMLFile.WriteLine     "Enter Path and name of Computer List<br><small>(PlanText file with one computer name per line)<br></small>"
objHTMLFile.WriteLine     "<input type="     & Chr(34) & "File" & Chr(34) & " name=" & Chr(34) & "File" & Chr(34) & " value=" & Chr(34) & "C:\Computers.txt" & Chr(34) & " size=" & Chr(34) & "60" & Chr(34) & " style=" & Chr(34) & "font-family: Tahoma; font-size: 8pt; border: 1px solid #000000;; background-color:#EEEEEE" & Chr(34) & "></p>"
 If MsgBox("Do you want to change the Local Administrator Password?", vbQuestion + vbYesNo, "Local Administrator Password") = vbYes then
            objHTMLFile.WriteLine     "Local Admin Password<br>"
            objHTMLFile.WriteLine     "<small>New Pass:</small><input type=" & Chr(34) & "password" & Chr(34) & " name=" & Chr(34) & "LocalAdmPassword" & Chr(34) & " size=" & Chr(34) & "30" & Chr(34) & " style=" & Chr(34) & "font-family: Tahoma; font-size: 8pt; border: 1px solid #000000;; background-color:#EEEEEE" & Chr(34) & "> &nbsp;&nbsp;&nbsp;"
            objHTMLFile.WriteLine     "<small>Confirm:</small><input type="  & Chr(34) & "password" & Chr(34) & " name=" & Chr(34) & "LocalAdmPasswordCheck" & Chr(34) & " size=" & Chr(34) & "30" & Chr(34) & " style=" & Chr(34) & "font-family: Tahoma; font-size: 8pt; border: 1px solid #000000;; background-color:#EEEEEE" & Chr(34) & "></p>"
            AcceptLocalPass     = "YES"
 End IF
objHTMLFile.WriteLine     "<HR WIDTH="       & Chr(34) & "100%" & Chr(34) & " SIZE=" & Chr(34) & "1" & Chr(34) & " ALIGN=" & Chr(34) & "Right" & Chr(34) & " COLOR=" & Chr(34) & "Black" & Chr(34) & " NOSHADE=" & Chr(34) & "Noshade" & Chr(34) & "><BR>"
objHTMLFile.WriteLine     "Specify Domain credentials that have administrator rights on the remote computer<BR>(Username: [Domain]\[Username])<br>"
objHTMLFile.WriteLine     "<input type="     & Chr(34) & "Text" & Chr(34) & " name=" & Chr(34) & "RemoteDomain" & Chr(34) & " size=" & Chr(34) & "100" & Chr(34) & " style=" & Chr(34) & "font-family: Tahoma; font-size: 8pt; border: 1px solid #000000;; background-color:#EEEEEE" & Chr(34) & "></p>"
objHTMLFile.WriteLine     "Password<br>"
objHTMLFile.WriteLine     "<input type="     & Chr(34) & "password" & Chr(34) & " name=" & Chr(34) & "UserPassword" & Chr(34) & " size=" & Chr(34) & "60" & Chr(34) & " style=" & Chr(34) & "font-family: Tahoma; font-size: 8pt; border: 1px solid #000000;; background-color:#EEEEEE" & Chr(34) & "></p>"
objHTMLFile.WriteLine     "<input type="     & Chr(34) & "hidden" & Chr(34) & " name=" & Chr(34) & "OKClicked" & Chr(34) & " size = " & Chr(34) & "20" & Chr(34) & ">"
objHTMLFile.WriteLine     "<input id=runbutton class=" & Chr(34) & "button" & Chr(34) & " type=" & Chr(34) & "button" & Chr(34) & " value=" & Chr(34) & " OK " & Chr(34) & " name=" & Chr(34) & "ok_button" & Chr(34) & " onClick=" & Chr(34) & "RunScript" & Chr(34) & " style=" & Chr(34) & "font-family: Tahoma; font-size: 8pt; border: 1px solid #000000;; background-color:#EEEEEE" & Chr(34) & ">"
objHTMLFile.WriteLine     "&nbsp;&nbsp;&nbsp;"
objHTMLFile.WriteLine     "<input id=runbutton class=" & Chr(34) & "button" & Chr(34) & " type=" & Chr(34) & "button" & Chr(34) & " value=" & Chr(34) & "Cancel" & Chr(34) & " name=" & Chr(34) & "cancel_button" & Chr(34) & " onClick=" & Chr(34) & "CancelScript" & Chr(34) & " style=" & Chr(34) & "font-family: Tahoma; font-size: 8pt; border: 1px solid #000000;; background-color:#EEEEEE" & Chr(34) & ">"
objHTMLFile.WriteLine     "<br>"
objHTMLFile.WriteLine     "<h6> Created by Jeferson Propheta and Scott Mikesell</h6>"
objHTMLFile.WriteLine     "</Font>"
objHTMLFile.WriteLine     "</font>"
objHTMLFile.WriteLine   "</DIV>"
objHTMLFile.WriteLine     "</BODY>"
objHTMLFile.WriteLine     "</HTML>"
objHTMLFile.Close
'*******************************************************************************************************
'Configuring IE Settings
'*******************************************************************************************************
objExplorer.Navigate  "file:///" & InterfaceFile
objExplorer.ToolBar   = 0
objExplorer.StatusBar = 0
objExplorer.Width     = 800
objExplorer.Height    = 550
objExplorer.Left      = 250
objExplorer.Top       = 100
objExplorer.Visible   = 1            
objExplorer.Document.Title = "Corporation"  
Do While (objExplorer.Document.Body.All.OKClicked.Value = "")
    Wscript.Sleep 250                
Loop  
'*******************************************************************************************************
'Getting Informations from Interface
'*******************************************************************************************************
    strPassword                = objExplorer.Document.Body.All.UserPassword.Value
    strDomain                 = objExplorer.Document.Body.All.Domain.Value
    strAdminGrp             = objExplorer.Document.Body.All.Group.Value
    strTxtFile                 = objExplorer.Document.Body.All.File.Value
    strUser                 = objExplorer.Document.Body.All.RemoteDomain.Value
    strButton                 = objExplorer.Document.Body.All.OKClicked.Value
    strLocalAdmPAssword        = objExplorer.Document.Body.All.LocalAdmPassword.Value
    strLocalAdmPasswordCheck= objExplorer.Document.Body.All.LocalAdmPasswordCheck.Value
   
    objExplorer.Quit
    Wscript.Sleep 250
If strButton = "Cancelled" Then
    HtmlFile.Delete
    Wscript.Quit
Else
    HtmlFile.Delete
    If strAdminGrp     = "" Then
       HtmlFile.Delete
       WScript.Quit(1)
    End IF  
    If strTxtFile      = "" Then
       HtmlFile.Delete
       WScript.Quit(1)   
    End IF
   
       Set objTextFile = objFSO.OpenTextFile(strTxtFile, 1)
    If Err.Number      = "53" Then
       msgerror= MsgBox("Computer List File Not Found" & vbCrLf & "Now Aborting..." & vbCrLf & "Please Try Again." , vbCritical + vbOKOnly, "Script Error")
       HtmlFile.Delete
       WScript.Quit(1)
    End IF
   
    If strLocalAdmPasswordCheck <> strLocalAdmPAssword Then
       msgerror= MsgBox("New Password and Confirm must match! Please re-type them " & vbCrLf & "Now Aborting..." & vbCrLf & "Please Try Again.", vbCritical + vbOKOnly, "Script Error")
       HtmlFile.Delete
       WScript.Quit(1)
    End IF
'*******************************************************************************************************
'Starting Excel to Generate Report
'*******************************************************************************************************
  Set objExcel = CreateObject("Excel.Application")
      objExcel.Visible = True
      objExcel.Workbooks.Add
      objExcel.Columns(1).ColumnWidth = 3
      objExcel.Columns(2).ColumnWidth = 25
      objExcel.Columns(3).ColumnWidth = 40
      objExcel.Columns(4).ColumnWidth = 40
      objExcel.ActiveCell.Font.Size = 12
      objExcel.ActiveCell.Font.Bold = True
      objExcel.ActiveCell.Value = "Computer List  - Local Group ADD( " & Date & " -  " & Time & " )"
      objExcel.ActiveCell.Offset(1,0).Activate
      objExcel.ActiveCell.Value = "File: " & strTxtFile & "  -  " & "Adding Group: " & strAdminGrp & " | Changing Local Password: " & AcceptLocalPass
      objExcel.ActiveCell.Offset(2,0).Activate
      objExcel.ActiveCell.Value = "#"
      objExcel.ActiveCell.Offset(0,1).Activate
      objExcel.ActiveCell.Value = "Computer Name"
      objExcel.ActiveCell.Offset(0,1).Activate
      objExcel.ActiveCell.Value = "Group Adding Status"
      objExcel.ActiveCell.Offset(0,1).Activate
      objExcel.ActiveCell.Value = "Password Changing Status"
      objExcel.ActiveCell.Offset(1,-4).Activate
 
      objExcel.Range("A4:D4").Select
      objExcel.Selection.Font.Bold = True
      objExcel.Selection.Interior.ColorIndex = 15
'*******************************************************************************************************
'Open Text File and Execute while not EOF
'*******************************************************************************************************
      Do While objTextFile.AtEndOfStream <> True
               objExcel.ActiveCell.Offset(1,0).Activate
               PCCount = PCCount + 1
               objExcel.ActiveCell.Value = PCCount

               strComputerID = objTextFile.ReadLine
               strComputerID = UCase(strComputerID)
             
               objExcel.ActiveCell.Offset(0,1).Activate
               objExcel.ActiveCell.Value = strComputerID
          
               call adminGroup(strComputerID)
      Loop
'*******************************************************************************************************
'Finishing Report
'*******************************************************************************************************
        objExcel.ActiveCell.Offset(2,0).Activate
        objExcel.ActiveCell.Value = "Finished at( " & Date & " -  " & Time & " )"
        HtmlFile.Delete
                   
                strFinished =    MsgBox("Done!!!!!" & vbCrLf &  "At " & Now(), vbInformation + vbOKOnly, "Finished!!!")      
'*******************************************************************************************************
'Routine:  AdminGroup
'*******************************************************************************************************
Sub adminGroup(strComputer)
    ' Bind to domain group with WinNT provider.
    Set objDomainGroup = GetObject("WinNT://" & strDomain & "/" & strAdminGrp & ",group")
 
    If Err.Number = "-2147024843" Then
       msgerror= MsgBox("Domain or Admin Group Not Found." & vbCrLf & "Now Aborting..." & vbCrLf & "Please Try Again.", vbCritical + vbOKOnly, "Script Error")      
       WScript.Quit(1)
    End IF
    ' Bind to local Administrators group on remote computer.
    ' Use alternate credentials.
    Set objNS = GetObject("WinNT:")
    On Error Resume Next

    Set objLocalGroup = objNS.OpenDSObject("WinNT://" & strComputer & "/Administrators,group", strUser, strPassword, ADS_SECURE_AUTHENTICATION)
        If Err.Number = "-2147022676" Then
            Err.Clear
            Set objLocalGroup = objNS.OpenDSObject("WinNT://" & strComputer & "/Administradores,group", strUser, strPassword, ADS_SECURE_AUTHENTICATION)
        End If
            If Err.Number <> 0 Then
                 Select Case Hex(Err.Number)

                Case "80070035"    :
                                 objExcel.ActiveCell.Offset(0,1).Activate
                                 objExcel.ActiveCell.Value = "Computer is not Reachable - " & Hex(Err.Number)
                                 objExcel.ActiveCell.Font.Bold = True
                                 objExcel.ActiveCell.Font.ColorIndex = 3
                                  objExcel.ActiveCell.Offset(0,1).Activate
                                 objExcel.ActiveCell.Value = "N/A"
                                 ExcellineBack
               
                Case "800708AC"    :
                                 objExcel.ActiveCell.Offset(0,1).Activate
                                 objExcel.ActiveCell.Value = "Local Administrator Group Name is Wrong - " & Hex(Err.Number)
                                  objExcel.ActiveCell.Offset(0,1).Activate
                                 objExcel.ActiveCell.Value = "N/A"
                                 ExcellineBack

                Case "80070562"    :
                                 objExcel.ActiveCell.Offset(0,1).Activate
                                 objExcel.ActiveCell.Value = "Group is Already Member."
                                 objExcel.ActiveCell.Offset(0,1).Activate
                                 objExcel.ActiveCell.Value = "N/A"
                                 ExcellineBack
               
                Case Else         :
                                 objExcel.ActiveCell.Offset(0,1).Activate
                                 objExcel.ActiveCell.Value = "Unknown Error: " & Hex(Err.Number) & " - " & Err.Description & " - " & Err.Source
                                 ExcellineBack
                End Select
             Else
             objLocalGroup.Add(objDomainGroup.AdsPath)

             If Err.Number = 0 Then
                objExcel.ActiveCell.Offset(0,1).Activate
                objExcel.ActiveCell.Value = "Added Successfully"
             Else
                Select Case Hex(Err.Number)
                   
                Case "800708AC"    :
                                 objExcel.ActiveCell.Offset(0,1).Activate
                                 objExcel.ActiveCell.Value = "Local Administrator Group Name is Wrong."
                   
                Case "80070562"    :
                                 objExcel.ActiveCell.Offset(0,1).Activate
                                  objExcel.ActiveCell.Value = "Group is Already Member."
                Case Else         :
                                 objExcel.ActiveCell.Offset(0,1).Activate
                                 objExcel.ActiveCell.Value = "Unknown Error: " & Hex(Err.Number) & " - " & Err.Description & " - " & Err.Source
                End Select
             End IF
             
             IF AcceptLocalPass     = "YES" Then
                Err.Clear
                Set objUser = objNS.OpenDSObject("WinNT://" & strComputer & "/Administrator", strUser, strPassword, ADS_SECURE_AUTHENTICATION)
                    If Err.Number <> 0 Then
                       Err.Clear
                       Set objUser = objNS.OpenDSObject("WinNT://" & strComputer & "/Administrador", strUser, strPassword, ADS_SECURE_AUTHENTICATION)

                           If Err.Number = 0 Then
                              objUser.SetPassword(strLocalAdmPAssword)
                                       
                                If     Err.Number = 0 Then
                                    objExcel.ActiveCell.Offset(0,1).Activate
                                    objExcel.ActiveCell.Value = "Successfully Changed"
                                    ExcellineBack
                                Else
                                    objExcel.ActiveCell.Offset(0,1).Activate
                                    objExcel.ActiveCell.Value = "Error: " & Hex(Err.Number)
                                    ExcellineBack
                                End IF   
                           Else
                              objExcel.ActiveCell.Offset(0,1).Activate
                              objExcel.ActiveCell.Value = "Error! Cannot find Admin Users - "& Hex(Err.Number)
                              ExcellineBack
                           End IF
                    Else   
                        objUser.SetPassword(strLocalAdmPAssword)
                                If     Err.Number = 0 Then
                                    objExcel.ActiveCell.Offset(0,1).Activate
                                    objExcel.ActiveCell.Value = "Successfully Changed"
                                    ExcellineBack
                                Else
                                    objExcel.ActiveCell.Offset(0,1).Activate
                                    objExcel.ActiveCell.Value = "Error: " & Hex(Err.Number)
                                    ExcellineBack
                                End IF   
                    End IF       
            Else
                 objExcel.ActiveCell.Offset(0,1).Activate
                 objExcel.ActiveCell.Value = "Password was not changed..."
                 ExcellineBack
            End IF                          
End If
'*******************************************************************************************************
'Cleaning UP
'*******************************************************************************************************
            Set objDomainGroup = Nothing
            Set objLocalGroup = Nothing
            Set objNS = Nothing
                Err.clean
                ExcellineBack
End Sub   
End If

Function     ExcellineBack()
            objExcel.ActiveCell.Offset(0,-1).Activate
            objExcel.ActiveCell.Offset(0,-2).Activate
            objExcel.ActiveCell.Offset(0,-3).Activate
            objExcel.ActiveCell.Offset(0,-4).Activate
            objExcel.ActiveCell.Offset(0,-5).Activate
End Function

_____________________________

Wscript.Echo("Just4 Fun")
 
 
Post #: 1
 
 
 
  

If you found our site useful please link to us <a href="http://www.visualbasicscript.com">VisualBasicScript.com</a>.
All Forums >> [Scripting] >> Post a VBScript >> Add Network Group as Local Administrators and Change local Administrator Password - Web Interface Page: [1]
Jump to:





New Messages No New Messages
Hot Topic w/ New Messages Hot Topic w/o New Messages
Locked w/ New Messages Locked w/o New Messages
 Post New Thread
 Reply to Message
 Post New Poll
 Submit Vote
 Delete My Own Post
 Delete My Own Thread
 Rate Posts