Sign in to follow this  
Followers 0
UniPer

Read serial form registry..If..Else does not work

7 posts in this topic

#1 ·  Posted (edited)

Hi all,

This is what I want:

I'm a total n00b with AutoIT and searched the forum for some example scripts but I couldn't find any that does what I want.

I want to retrieve the systems serialnumber from: HKEY_LOCAL_MACHINE\SOFTWARE\Organization\Setup "MachineSerial".

After that I want to change the PC name to this serialnumber using the 'netdom' command.

I really have no idea where and how to start.

Can someone help me out with this?

Kind regards,

Perry

Edited by UniPer

Share this post


Link to post
Share on other sites



Hi all,

This is what I want:

I'm a total n00b with AutoIT and searched the forum for some example scripts but I couldn't find any that does what I want.

I want to retrieve the systems serialnumber from: HKEY_LOCAL_MACHINE\SOFTWARE\Organization\Setup "MachineSerial".

After that I want to change the PC name to this serialnumber using the 'netdom' command.

I really have no idea where and how to start.

Can someone help me out with this?

Kind regards,

Perry

Hi there m8, welcome aboard :)

First i strongly recommend that you read the help file from AutoIT ans some tutorial in the forum.

Try some examples and modify them, use and abuse :)

Regarding your request, i recomend tha you see this forum topic.

Cheers


Old Scriptology

Visual Ping 1.8 - Mass Ping Program with export to txt delimited.

Desktop 2 RGB and YMCK - Pick a color in the desktop and get the RGB and YMCK code.

Desktop 2 RGB - Pick a color in the desktop and get the RGB code.

ShootIT 1.0 - Screen Capture full and partial screen

[font="'Arial Black';"]Remember Remember The Fifth of November.[/font]

Share this post


Link to post
Share on other sites

#3 ·  Posted (edited)

I created this code:

;This script will silently join the PC to the domain and rename it conform the Company Policy.
;Written with: SciTE4AutoIt3 Version 1.76
;Compiled with: AutoIt v3.2.12.1
;This script will run just once
;Variables must be declared before using them

AutoItSetOption("TrayMenuMode",1)

;The name of the application (used as title for message boxes)
Global $appName = "Domain Tool V1.0"
Global $logonFlag = 0; 0 - Interactive logon with no profile. 1 - Interactive logon with profile. 2 - Network Global $extraParameters = " /silent"; " /silent" ""
Global $runAsWaitFlag = @SW_SHOW; @SW_HIDE @SW_SHOW



If Not FileExists ( " C:\windows\stage1.chk" ) Then
;The registry will be overwritten with a fixed username and password and AutoLogon will be enabled
    RegDelete ( "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Winlogon", "DefaultDomainName")
    RegDelete ( "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Winlogon", "DefaultUserName")
    RegDelete ( "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Winlogon", "DefaultPassword")
    RegDelete ( "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Winlogon", "AutoAdminLogon")
    RegDelete ( "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Winlogon", "ForceAutoLogon")

    RegWrite ( "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Winlogon", "DefaultDomainName", "REG_SZ", "")
    RegWrite ( "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Winlogon", "DefaultUsername" , "REG_SZ", "*******")
    RegWrite ( "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Winlogon", "DefaultPassword" , "REG_SZ", "******")
    RegWrite ( "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Winlogon", "AutoAdminLogon" , "REG_SZ", "1")
    RegWrite ( "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Winlogon", "ForceAutoLogon" , "REG_SZ", "1")
    TrayTip($appName & " - Autologon is Enabled", "AutoLogon Enabled.. ", 6000)
    TraySetToolTip($appName & " - Autologon is Enabled")
    Sleep ( 3000 )
;Newsid.exe will run silently and will provide a new ID for the system
    ShellExecute ( "C:\temp\newsid", "/a" )
    TrayTip($appName & " - Your SystemID renewed ", "Your SystemID has been renewed", 6000)
    TraySetToolTip($appName & " - Your SystemID renewed " )
    
;Stage1.chk will be copied to the Windows directory to be sure the script came this far
    FileCopy("C:\temp\chk\stage1.chk", "C:\windows\")
    Sleep ( 3000 )
    TrayTip($appName & " - System reboot..", "System will reboot in a few minutes..", 6000)
    TraySetToolTip($appName & " - System reboot.." )
    Sleep ( 9999999 )
Else
;Script will check if file 'stage1.chk' is stored in the Windows dir, if not, script will stop
    If FileExists ( " C:\windows\stage1.chk" ) Then
        If Not FileExists ( "C:\windows\stage2.chk" ) Then
;System will be joined to the Domain
            ShellExecute ( "C:\temp\netdom", "join . /Domain:GROUPINFRA.COM /UserD: /PasswordD:" )
;Stage2.chk will be copied to the Windows directory to be sure the script came this far
            FileCopy("C:\temp\chk\stage2.chk", "C:\windows\")
            TrayTip($appName & " - System joined GROUPINFRA", "System joined the GROUPINFRA.COM Domain", 6000)
            TraySetToolTip($appName & " - System joined GROUPINFRA")
            Sleep ( 3000 )
            TrayTip($appName & " - System reboot..", "System will reboot in a few seconds..", 6000)
            TraySetToolTip($appName & " - System reboot..")
            Shutdown (2)
        
    Else
        MsgBox ( 4096, "Failure", " SystemID Upgrade Failed.. " )
        Else
;Script will check if file 'stage2.chk' is stored in the Windows dir, if not, script will stop
            If FileExists ( "C:\stage2.chk" ) Then
    ;Script will read the Machine Serialnumber from the registry to convert it into variable $reg
                Dim $reg = RegRead("HKEY_LOCAL_MACHINE\SOFTWARE\Organization\Setup", "MachineSerial")
    ;$reg will be changed with so that the new serial is: NL-XXXXXXX after that this will be converted to variable $serial 
                Dim $serial="NL-"& $reg
                TrayTip($appName & " - Systemserial is:", "The Machines Serial is "& $serial, 6000)
                TraySetToolTip($appName & " - Systemserial is:")
    ;System will be renamed to $serial
                RunWait ( "C:\temp\netdom renamecomputer . /newname:"& $serial )
                TrayTip($appName & " - System renamed", "System succesfully renamed to "& $serial, 6000 )
                TraySetToolTip($appName & " - System renamed")
                FileCopy("C:\temp\chk\stage3.chk", "C:\windows\")
    ;The Registry will be restored to his old original state and AutoLogon will be disabled
                Run ( "C:\windows\regedit", "-s C:\temp\restore_reg.reg" )
                TrayTip($appName & " - Autologon is Disabled", "Autologon disabled again", 6000)
                TraySetToolTip($appName & " - Autologon is Disabled")
                Sleep ( 3000 )
                TrayTip($appName & " - System reboot..", "System will reboot in a few seconds..", 6000)
                TraySetToolTip($appName & " - System reboot..")
                Shutdown (2)
            Else
                MsgBox ( 4096, "Failure", " PC is not joined to GROUPINFRA.COM " )
            EndIf
        Endif
    EndIf
EndIf

The problem is that the If..Else statements don't work, can someone please help me out here?

Kind Regards,

Edited by UniPer

Share this post


Link to post
Share on other sites

To make it easier for everybody to read I'll add the script here:

betav1.0.au3

Share this post


Link to post
Share on other sites

The logical flow of the script is a little messed up... pls describe what you want to achive... what to do / not to do if file exists / does not exist...

If you use the SciTE au3 editor you can easily see the nesting of the IF statements (after running the Tidy function).

Share this post


Link to post
Share on other sites

#6 ·  Posted (edited)

This topic can be closed and I'll make a separate post to make it more easier to understand for everybody.

Edited by UniPer

Share this post


Link to post
Share on other sites

Don't know nothing about the RegValues etc... but from what I read and understood the logical flow should run like this:

;This script will silently join the PC to the domain and rename it conform the Company Policy.
;Written with: SciTE4AutoIt3 Version 1.76
;Compiled with: AutoIt v3.2.12.1
;This script will run just once
;Variables must be declared before using them

AutoItSetOption("TrayMenuMode", 1)

;The name of the application (used as title for message boxes)
Global $appName = "Domain Tool V1.1"
Global $logonFlag = 0 ; 0 - Interactive logon with no profile. 1 - Interactive logon with profile. 2 - Network Global $extraParameters = " /silent" ; " /silent" ""
Global $runAsWaitFlag = @SW_SHOW ; @SW_HIDE @SW_SHOW

If Not FileExists("C:\windows\stage1.chk") Then
    ;The registry will be overwritten with a fixed username and password and AutoLogon will be enabled
    
        RegDelete ( "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Winlogon", "DefaultDomainName")
        RegDelete ( "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Winlogon", "DefaultUserName")
        RegDelete ( "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Winlogon", "DefaultPassword")
        RegDelete ( "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Winlogon", "AutoAdminLogon")
        RegDelete ( "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Winlogon", "ForceAutoLogon")
        
        RegWrite ( "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Winlogon", "DefaultDomainName", "REG_SZ", "")
        RegWrite ( "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Winlogon", "DefaultUsername" , "REG_SZ", "******")
        RegWrite ( "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Winlogon", "DefaultPassword" , "REG_SZ", "******")
        RegWrite ( "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Winlogon", "AutoAdminLogon" , "REG_SZ", "1")
        RegWrite ( "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Winlogon", "ForceAutoLogon" , "REG_SZ", "1")
        TrayTip($appName & " - Autologon is Enabled", "AutoLogon Enabled.. ", 6000)
        TraySetToolTip($appName & " - Autologon is Enabled")
        Sleep ( 3000 )
        ;Newsid.exe will run silently and will provide a new ID for the system
        ShellExecute ( "C:\temp\newsid", "/a" )
        TrayTip($appName & " - Your SystemID renewed ", "Your SystemID has been renewed", 6000)
        TraySetToolTip($appName & " - Your SystemID renewed " )
        ;Stage1.chk will be copied to the Windows directory to be sure the script came this far
        FileCopy("C:\temp\chk\stage1.chk", "C:\windows\")
        Sleep ( 3000 )
        TrayTip($appName & " - System reboot..", "System will reboot in a few minutes..", 6000)
        TraySetToolTip($appName & " - System reboot.." )
        Sleep ( 9999999 )

ElseIf FileExists("C:\windows\stage1.chk") And Not FileExists("C:\windows\stage2.chk") Then

        ;System will be joined to the Domain
        ShellExecute ( "C:\temp\netdom", "join . /Domain:GROUPINFRA.COM /UserD: /PasswordD:" )
        ;Stage2.chk will be copied to the Windows directory to be sure the script came this far
        FileCopy("C:\temp\chk\stage2.chk", "C:\windows\")
        TrayTip($appName & " - System joined GROUPINFRA", "System joined the GROUPINFRA.COM Domain", 6000)
        TraySetToolTip($appName & " - System joined GROUPINFRA")
        Sleep ( 3000 )
        TrayTip($appName & " - System reboot..", "System will reboot in a few seconds..", 6000)
        TraySetToolTip($appName & " - System reboot..")
        Shutdown (2)

ElseIf FileExists("C:\stage2.chk") Then
        ;Script will check if file 'stage2.chk' is stored in the Windows dir, if not, script will stop
        
        ;Script will read the Machine Serialnumber from the registry to convert it into variable $reg
        Dim $reg = RegRead("HKEY_LOCAL_MACHINE\SOFTWARE\Organization\Setup", "MachineSerial")
        ;$reg will be changed with so that the new serial is: NL-XXXXXXX after that this will be converted to variable $serial
        Dim $serial="NL-"& $reg
        TrayTip($appName & " - Systemserial is:", "The Machines Serial is "& $serial, 6000)
        TraySetToolTip($appName & " - Systemserial is:")
        ;System will be renamed to $serial
        RunWait ( "C:\temp\netdom renamecomputer . /newname:"& $serial )
        TrayTip($appName & " - System renamed", "System succesfully renamed to "& $serial, 6000 )
        TraySetToolTip($appName & " - System renamed")
        FileCopy("C:\temp\chk\stage3.chk", "C:\windows\")
        ;The Registry will be restored to his old original state and AutoLogon will be disabled
        Run ( "C:\windows\regedit", "-s C:\temp\restore_reg.reg" )
        TrayTip($appName & " - Autologon is Disabled", "Autologon disabled again", 6000)
        TraySetToolTip($appName & " - Autologon is Disabled")
        Sleep ( 3000 )
        TrayTip($appName & " - System reboot..", "System will reboot in a few seconds..", 6000)
        TraySetToolTip($appName & " - System reboot..")
        Shutdown (2)

ElseIf Not FileExists("C:\stage2.chk") Then
    
    MsgBox(4096, "Failure", " PC is not joined to GROUPINFRA.COM ")


EndIf

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