Sign in to follow this  
Followers 0
DJ VenGenCe

Pre-domain Script

9 posts in this topic

#1 ·  Posted (edited)

Ok to keep it quick, I am writing a pre-domain script that will do the following

  • Change the Time Zone to Eastern
  • Change the Computer Name Based on Input from Input box (Gui version later)
  • Rename the local Admin Account and Set the Password
  • Write a registry entry to run Netdom.exe upon restart in RunOnce Key
My Question is, is the formatting for RegWrite correct in the UpdateRegistry() Function?

I am going to test in an XP Environment, so comments are definitly welcome!

Here's what I got for code so far: Sloppy, yes... will be cleaned up once it is functional

;ChangeLocalAdmin();Function Not Complete
ChangeTimeZone()
ChangeComputerName()
CopyFiles();See Function Description
UpdateRegistry()


Func ChangeTimeZone()
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;                                            ;
; Function to change Time Zone to Eastern Time;
;                                            ;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

$path = "HKEY_LOCAL_MACHINE\SYSTEM\currentcontrolset\Control\TimeZoneInformation"
RegWrite ($path,"Bias", "REG_DWORD", 300)
RegWrite ($path,"StandardBias", "REG_DWORD", 00)
RegWrite ($path,"StandardName", "REG_SZ", "Eastern Standard Time")
RegWrite ($path,"DaylightName", "REG_SZ", "Eastern Daylight Time")
RegWrite ($path,"Active Time Bias", "REG_DWORD", 240)

EndFunc

Func ChangeComputerName( )
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; Function to Change Computer Name Via VBScript Converted to;
; AutoIT.
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

;The following are test inputs, which will be changed when the GUI is built.

$Name = InputBox("Enter computer Name", "", "Enter New Computer Name")
$User = InputBox("Enter Admin Name", "Local Admin Acct Login", "Account")
$Password = InputBox("Password", "Enter password to login: "& $User, "")


$objWMIService = ObjGet("Winmgmts:root\cimv2")
; Call always gets only one Win32_ComputerSystem object.

For $objComputer in _
    $objWMIService.InstancesOf("Win32_ComputerSystem")
        $ret = $objComputer.rename($Name,$Password,$User)
        If $ret <> 0 Then
;If Failed, display error box
           MsgBox(4, "Error:" ,"Rename failed. Error = " & @error)
        Else
;It went ok!
        MsgBox(0, "Done!" ,"Reboot to for changes to take effect!")
    EndIf
Next
EndFunc

Func CopyFileS()
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; Function to Copy Files to Local c: Drive under D Directory;
; to allow the registry to call "NETDOM.EXE" And Cleanup vbs;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

FileCopy ("netdom.exe", "C:\D\netdom.exe",1 )
FileCopy ("runme.vbs", "C:\D\runme.vbs",1 )

EndFunc

Func UpdateRegistry()
;Registry Function to write to the RunOnce entry in the registry to run the "netdom.exe" then reboot.
;This is what is run after initial Startup
;
; The Variables $username, $domain, and $password are passed through Inputboxes (GUI To Come)
$domain = Inputbox("Domain Prompt", "Domain:", "")
$username = InputBox("Username Prompt", "Username Enter", "")
$password = InputBox("Password Prompt", "Password for this account", "")
;
;
$cmd = "C:\D\netdom.exe join " & @ComputerName & " /userd:" & $domain & "\" & $username & " /passwordd:" & $password & " /force /reboot:5"
RegWrite("HKEY_LOCAL_MACHINE\SOFTWARÉ\Microsoft\Windows\CurrentVersion", "RunOnce", "REG_SZ", $cmd )
;
;

EndFunc

Func ChangeLocalAdmin( )
;Function not written yet.. Work In Progress
EndFunc
Edited by DJ VenGenCe

Share this post


Link to post
Share on other sites



I believe you are missing some important reg entries for the time zone settings. All these should be copied over:

Bias                REG_DWORD
StandardName        REG_SZ   
StandardBias        REG_DWORD 
StandardStart       REG_BINARY
DaylightName        REG_SZ   
DaylightBias        REG_DWORD 
DaylightStart       REG_BINARY
ActiveTimeBias      REG_DWORD

If you want some more information check out this webpage.

Share this post


Link to post
Share on other sites

#3 ·  Posted (edited)

I believe you are missing some important reg entries for the time zone settings. All these should be copied over:

Bias                REG_DWORD
StandardName        REG_SZ   
StandardBias        REG_DWORD 
StandardStart       REG_BINARY
DaylightName        REG_SZ   
DaylightBias        REG_DWORD 
DaylightStart       REG_BINARY
ActiveTimeBias      REG_DWORD

If you want some more information check out this webpage.

Modified version to add DaylightBias, DaylightStart, and StandardStart:

; Function to change Time Zone to Eastern Time
Func ChangeTimeZone()
    $path = "HKEY_LOCAL_MACHINE\SYSTEM\currentcontrolset\Control\TimeZoneInformation"
; RegWrite($path, "ActiveTimeBias", "REG_DWORD", 240); Allow system to adjust this
    RegWrite($path, "Bias", "REG_DWORD", 300)
    RegWrite($path, "StandardName", "REG_SZ", "Eastern Standard Time")
    RegWrite($path, "StandardStart", "REG_BINARY", "00000400010002000000000000000000")
    RegWrite($path, "StandardBias", "REG_DWORD", 00)
    RegWrite($path, "DaylightName", "REG_SZ", "Eastern Daylight Time")
    RegWrite($path, "DaylightStart", "REG_BINARY", "00000a00050002000000000000000000")
    RegWrite($path, "DaylightBias", "REG_DWORD", -60)
EndFunc ;==>ChangeTimeZone

I'm not sure you have to mess with ActiveTimeBias (note to DJ VenGenCe: no spaces in that). That should adjust by itself. Otherwise you will have to make it conditional based on what time of year you are running it.

Hope that helps! :)

Edited by PsaltyDS

Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law

Share this post


Link to post
Share on other sites

Thanks for the Help guys.. anyone get a chance to look at the other "RegWrite" area for the Netdom.exe ?

Share this post


Link to post
Share on other sites

You should also consider here adding a check with domain .. if current computer name you are trying to give exists already. At least in my company it's common mistake by administrators that they often give computer name the same that already exists in domain. It isn't a problem if user has 1 computer. But if he has more then one computer replacing computer that exists in domain and is being used will make the user to not be able to login to his computer next time he tries to login. It happens because old computer was thrown out of domain so it doesn't have contact with domain anymore. Hope that was helpfull.. but maybe you don't need that.


My little company: Evotec (PL version: Evotec)

Share this post


Link to post
Share on other sites

@MadBoy:

Thanks for your reply, but the machines I deal with have Asset Numbers on them and they are part of the computer name. Each computer name is unique and part of a naming convention. Although this was helpful, it is not applicable in this situation.

If I could get the Regwrite netdom execution to work, this would so make my day.

Share this post


Link to post
Share on other sites

@MadBoy:

Thanks for your reply, but the machines I deal with have Asset Numbers on them and they are part of the computer name. Each computer name is unique and part of a naming convention. Although this was helpful, it is not applicable in this situation.

If I could get the Regwrite netdom execution to work, this would so make my day.

Try running this from a cmd prompt to make sure it works. I copied this straight from your script, so just change the parts in red and nothing else and see if it will run.

C:\D\netdom.exe join ComputerName /userd:Domain\Username /passwordd:Password /force /reboot:5

Share this post


Link to post
Share on other sites

Try running this from a cmd prompt to make sure it works. I copied this straight from your script, so just change the parts in red and nothing else and see if it will run.

C:\D\netdom.exe join ComputerName /userd:Domain\Username /passwordd:Password /reboot:5 executes the command then reboots after 5 seconds. System Shutdown warning comes up.

Share this post


Link to post
Share on other sites

C:\D\netdom.exe join ComputerName /userd:Domain\Username /passwordd:Password /reboot:5 executes the command then reboots after 5 seconds. System Shutdown warning comes up.

Did your computer join a domain? It appears to me that the /domain: command is missing from the syntax. The syntax is NETDOM JOIN machine /Domain:domain [/OU:ou path] /UserD:user /PasswordD:password /REBoot:(time in seconds).

Share this post


Link to post
Share on other sites

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 account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0