Find Jobs
Hire Freelancers

AutoIt Script Help - Computer Rename GUI

$2-30 USD / hour

Closed
Posted over 13 years ago

$2-30 USD / hour

I was wondering if there is a way to have a popup prompt asking for a new computer name? Here's my situation; I have automated our entire imaging, and scripted install process for computers at my company moving to Windows 7. When they finish imaging, they are sitting at the desktop of the local administrator account already joined to the domain, activated with Microsoft, and they have a generic computer name. What I would like is to have a script I can edit later if needed and then compile to an EXE using AutoIt, that will pop up a window that states "Please enter a new computer name.", a place to enter it, and a submit button. Then upon succesful entry and change of the computers name, prompt for reboot. It must be able to change the computer name of a machine that is joined to an Active Directory domain. ## Deliverables I found the code below over at experts-exchange, but it has Windows activation included in it as well, which I don't need because? my computers? auto activate.? This is for reference only... [CODE] #NoTrayIcon #Region ;**** Directives created by AutoIt3Wrapper_GUI **** #AutoIt3Wrapper_icon=[login to view URL] #AutoIt3Wrapper_outfile=[login to view URL] #AutoIt3Wrapper_Compression=4 #AutoIt3Wrapper_UseUpx=n #AutoIt3Wrapper_Res_Description=Change Computer Names. Used for Windows 7 Imaging #AutoIt3Wrapper_Res_Fileversion=0.0.0.0 #AutoIt3Wrapper_Res_LegalCopyright=SaLus ;Please keep copyright info here. Thank you :) #EndRegion ;**** Directives created by AutoIt3Wrapper_GUI **** #include <[login to view URL]> #include <[login to view URL]> #include <[login to view URL]> #include <[login to view URL]> #include <[login to view URL]> #include <[login to view URL]> Opt("GUIOnEventMode", 1) Const $JOIN_DOMAIN = 1 Const $ACCT_CREATE = 2 Const $ACCT_DELETE ? ? ? ? ? ? = 4 Const $WIN9X_UPGRADE ? ? ? ? ? = 16 Const $DOMAIN_JOIN_IF_JOINED ? = 32 Const $JOIN_UNSECURE ? ? ? ? ? = 64 Const $MACHINE_PASSWORD_PASSED = 128 Const $DEFERRED_SPN_SET ? ? ? ? = 256 Const $INSTALL_INVOCATION ? ? ? = 262144 Dim $oMyError Dim $UserName Dim $Password Dim $objComputer Dim $objNetwork Dim $ComputerName Dim $objWMIService Dim $res Dim $result Dim $ret $Form1 = GUICreate("Image Finisher", 456, 217, 192, 124) $Group1 = GUICtrlCreateGroup(" Computer Name ", 10, 10, 246, 51) $ComputerName = GUICtrlCreateInput("[MyComputerName]", 20, 30, 226, 21) GUICtrlCreateGroup("", -99, -99, 1, 1) $Button1 = GUICtrlCreateButton("Set Configuration", 145, 175, 160, 25, $WS_GROUP) GUICtrlSetOnEvent($Button1,"_SetCompName") $Group3 = GUICtrlCreateGroup(" Activation Type ", 10, 75, 246, 50) $KMSAct = GUICtrlCreateRadio("KMS", 20, 90, 100, 25) GUICtrlSetOnEvent($KMSAct, "_UseKMS") $MAKAct = GUICtrlCreateRadio("MAK", 120, 90, 100, 25) GUICtrlSetOnEvent($MAKAct, "_UseMAK") $MAKKey = GUICtrlCreateEdit("", 270, 17, 170, 110, BitOR($ES_AUTOVSCROLL,$ES_WANTRETURN)) GUICtrlSetData(-1, "If the computer is going to be off the network for > 180 days, choose MAK and input key here.") GUICtrlSetState(-1, $GUI_DISABLE) GUICtrlCreateGroup("", -99, -99, 1, 1) GUISetOnEvent($GUI_EVENT_CLOSE,"_Exit") GUISetState(@SW_SHOW) While 1 ? ? Sleep(10) WEnd $oMyError = ObjEvent("[login to view URL]","MyErrFunc") Func _UseMAK() ? ? GUICtrlSetState($MAKKey, $GUI_ENABLE) EndFunc Func _UseKMS() ? ? GUICtrlSetState($MAKKey, $GUI_DISABLE) EndFunc Func _SetCompName() ? ? GUICtrlSetData($Button1,"Adding Computer") ? ? GUICtrlSetState($Button1,$GUI_DISABLE) ? ? GUICtrlSetState($ComputerName,$GUI_DISABLE) ? ? If GUICtrlRead($ComputerName) == "[MyComputerName]" Or GUICtrlRead($ComputerName) == "" Then ? ? ? ? MsgBox(16,"ERROR","Please name the computer!") ? ? ? ? GUICtrlSetData($Button1,"Set Computer Name") ? ? ? ? GUICtrlSetState($Button1,$GUI_ENABLE) ? ? ? ? GUICtrlSetState($ComputerName,$GUI_ENABLE) ? ? Else ? ? ? ? If NOT BitAND(GUICtrlRead($KMSAct),$GUI_CHECKED) OR NOT BitAND(GUICtrlRead($MAKAct),$GUI_CHECKED) Then ? ? ? ? ? ? MsgBox(16,"ERROR","Please choose an Activation Method") ? ? ? ? ? ? GUICtrlSetData($Button1,"Set Computer Name") ? ? ? ? ? ? GUICtrlSetState($Button1,$GUI_ENABLE) ? ? ? ? ? ? GUICtrlSetState($ComputerName,$GUI_ENABLE) ? ? ? ? Else ? ? ? ? ? ? $objNetwork = ObjCreate("[login to view URL]") ? ? ? ? ? ? $strComputer = $[login to view URL] ? ? ? ? ? ? $objWMIService = ObjGet("Winmgmts:root\cimv2") ? ? ? ? ? ? For $objComputer In $[login to view URL]("Win32_ComputerSystem") ? ? ? ? ? ? ? ? ; Add your credentials here ? ? ? ? ? ? ? ? $res = $[login to view URL](GUICtrlRead($ComputerName),"{PASSWORD}","{DOMAIN\USERNAME}") ? ? ? ? ? ? ? ? If $res <> 0 Then ? ? ? ? ? ? ? ? ? ? If $res = 2224 Then ? ? ? ? ? ? ? ? ? ? ? ? MsgBox(16,"Error","Error Code: " & $res & @CR & "Account already exists. Please delete from Active Directory.") ? ? ? ? ? ? ? ? ? ? ? ? GUICtrlSetState($Button1,$GUI_ENABLE) ? ? ? ? ? ? ? ? ? ? ? ? GUICtrlSetState($ComputerName,$GUI_ENABLE) ? ? ? ? ? ? ? ? ? ? ? ? GUICtrlSetData($Button1,"Set Computer Name") ? ? ? ? ? ? ? ? ? ? ElseIf $res == 5 Then ? ? ? ? ? ? ? ? ? ? ? ? MsgBox(16,"Error","Error Code: " & $res & @CR & "Access Denied.") ? ? ? ? ? ? ? ? ? ? ? ? GUICtrlSetState($Button1,$GUI_ENABLE) ? ? ? ? ? ? ? ? ? ? ? ? GUICtrlSetState($ComputerName,$GUI_ENABLE) ? ? ? ? ? ? ? ? ? ? ? ? GUICtrlSetData($Button1,"Set Computer Name") ? ? ? ? ? ? ? ? ? ? Else ? ? ? ? ? ? ? ? ? ? ? ? MsgBox(16,"Error","Error renaming or adding the computer to the domain" & @CR & "Error Code: " & $res) ? ? ? ? ? ? ? ? ? ? ? ? GUICtrlSetState($Button1,$GUI_ENABLE) ? ? ? ? ? ? ? ? ? ? ? ? GUICtrlSetState($ComputerName,$GUI_ENABLE) ? ? ? ? ? ? ? ? ? ? ? ? GUICtrlSetData($Button1,"Set Computer Name") ? ? ? ? ? ? ? ? ? ? EndIf ? ? ? ? ? ? ? ? Else ? ? ? ? ? ? ? ? ? ? GUICtrlSetState($Button1,$GUI_DISABLE) ? ? ? ? ? ? ? ? ? ? GUICtrlSetState($ComputerName,$GUI_DISABLE) ? ? ? ? ? ? ? ? ? ? MsgBox(64,"Success","Computer has been renamed to: " & GUICtrlRead($ComputerName)) ? ? ? ? ? ? ? ? ? ? RunOnce() ? ? ? ? ? ? ? ? EndIf ? ? ? ? ? ? Next ? ? ? ? EndIf ? ? EndIf EndFunc Func RunOnce() ? ? $file = FileOpen("C:\Users\Public\Documents\[login to view URL]", 2) ? ? FileWrite( $file, "Del C:\Users\Public\Documents\[login to view URL]" & @CRLF) ? ? FileWrite( $file, "Attrib -r" & @CRLF) ? ? FileWrite( $file, "DEL %0") ? ? FileClose($file) ? ? RegWrite("HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\RunOnce", "applysettings", "REG_SZ", "C:\Users\Public\Documents\[login to view URL]") ? ? If BitAND(GUICtrlRead($KMSAct), $GUI_CHECKED) Then ? ? ? ? $DoActivate = MsgBox(36,"Activation","Activate Windows 7 with KMS?" & _ ? ? ? ? ? ? @CRLF & "NOTE: If this machine is going to be off campus for more than 180 days DO NOT ACTIVATE. Please use a MAK Key instead") ? ? ? ? If $DoActivate = 6 Then ? ? ? ? ? ? MsgBox(64,"Processing...","Activation will continue after you hit OK. Please wait for the confirmation box to appear before restarting." & _ ? ? ? ? ? ? ? ? ? ? @CR & "Activation takes between 10-30 seconds.") ? ? ? ? ? ? Run(@ComSpec & " /c slmgr /ato") ? ? ? ? ? ? GUICtrlSetData($Button1,"REBOOT COMPUTER") ? ? ? ? ? ? GUICtrlSetState($Button1,$GUI_ENABLE) ? ? ? ? ? ? GUICtrlSetOnEvent($Button1,"_Reboot") ? ? ? ? Else ? ? ? ? ? ? $OKReboot = MsgBox(1,"Reboot Needed","This machine must reboot to complete configuration") ? ? ? ? ? ? If $OKReboot = 1 Then ? ? ? ? ? ? ? ? _Reboot() ? ? ? ? ? ? Else ? ? ? ? ? ? ? ? Exit ? ? ? ? ? ? EndIf ? ? ? ? EndIf ? ? Else ? ? ? ? $GetMAKKey = GUICtrlRead($MAKKey) ? ? ? ? Run(@ComSpec & " /c slmgr /ipk " & $GetMAKKey) ? ? ? ? GUICtrlSetData($Button1,"REBOOT COMPUTER") ? ? ? ? GUICtrlSetState($Button1,$GUI_ENABLE) ? ? ? ? GUICtrlSetOnEvent($Button1,"_Reboot") ? ? EndIf EndFunc Func _Reboot() ? ? Run(@ComSpec & " /c " & 'shutdown -r -f -t 05', "", @SW_HIDE) EndFunc Func MyErrFunc() ? ? $HexNumber = hex($[login to view URL],8) ? ? Msgbox(0,"","We intercepted a COM Error !" & @CRLF & _ ? ? ? ? ? ? "Number is: " & $HexNumber & @CRLF & _ ? ? ? ? ? ? "Windescription is: " & $[login to view URL] ) EndFunc Func _Exit() ? ? Exit EndFunc [/CODE] Any help would be greatly appreciated!
Project ID: 3695994

About the project

1 proposal
Remote project
Active 13 yrs ago

Looking to make some money?

Benefits of bidding on Freelancer

Set your budget and timeframe
Get paid for your work
Outline your proposal
It's free to sign up and bid on jobs
1 freelancer is bidding on average $23 USD/hour for this job
User Avatar
See private message.
$22.75 USD in 2 days
4.5 (7 reviews)
2.9
2.9

About the client

Flag of UNITED STATES
United States
0.0
0
Member since Sep 2, 2010

Client Verification

Thanks! We’ve emailed you a link to claim your free credit.
Something went wrong while sending your email. Please try again.
Registered Users Total Jobs Posted
Freelancer ® is a registered Trademark of Freelancer Technology Pty Limited (ACN 142 189 759)
Copyright © 2024 Freelancer Technology Pty Limited (ACN 142 189 759)
Loading preview
Permission granted for Geolocation.
Your login session has expired and you have been logged out. Please log in again.