Jump to content

Change computername AutoIT implementation


jben
 Share

Recommended Posts

Hey everyone. I've been working on a bit of code that automates a piece of software, however within this code i'm trying to work out how I can change the computer name based on information in the BIOS.

I found this utility called compname.exe which looks interesting but cant find enough information on it. I feel that I may need to import a runonce reg file from within AutoIT and then upon next login the runonce reg file will run and call compname.exe

Something like the following for runonce

"%systemdrive%\apps\rename\compname.exe /c ?s" /f

and then during my AutoIT installation i can copy a file to the above specified folder. Anyone have any ideas on this?

many thanks

Link to comment
Share on other sites

  • Developers

Why would you want to create a RunOnce in stead of just doing a FileInstall() for Compname.exe and then just running it?

_RunDOS("COMPNAME /c " & $NEWPCNAME)

Jos

SciTE4AutoIt3 Full installer Download page   - Beta files       Read before posting     How to post scriptsource   Forum etiquette  Forum Rules 
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Link to comment
Share on other sites

can WMI get bios information and use something from the BIOS to change the PC name though?....Trying to figure out how I could implement this.

thanks

You can query info from the WMI class Win32_BIOS, but really the only truly "unique" info you'd get would be a serial number.

Link to comment
Share on other sites

This is how I change the ComputerName under XP using the SN# of my Dell systems.

$wbemFlagReturnImmediately = 0x10
$wbemFlagForwardOnly = 0x20
$colItems = ""
$strComputer = "localhost"


$Output=""
$objWMIService = ObjGet("winmgmts:\\" & $strComputer & "\root\CIMV2")
$colItems = $objWMIService.ExecQuery("SELECT * FROM Win32_ComputerSystemProduct", "WQL", _
      $wbemFlagReturnImmediately + $wbemFlagForwardOnly)
For $objItem In $colItems
$Output = $objItem.IdentifyingNumber
next
RegWrite("HKEY_LOCAL_MACHINE\SYSTEM\ControlSet001\Control\ComputerName\ActiveComputerName","ComputerName","REG_SZ",$Output)
RegWrite("HKEY_LOCAL_MACHINE\SYSTEM\ControlSet001\Control\ComputerName\ComputerName","ComputerName","REG_SZ" ,$Output)
RegWrite("HKEY_LOCAL_MACHINE\SYSTEM\ControlSet001\Services\Eventlog","ComputerName","REG_SZ",$Output)
RegWrite("HKEY_LOCAL_MACHINE\SYSTEM\ControlSet001\Services\Tcpip\Parameters","Hostname","REG_SZ",$Output)
RegWrite("HKEY_LOCAL_MACHINE\SYSTEM\ControlSet001\Services\Tcpip\Parameters","NV Hostname","REG_SZ",$Output)
RegWrite("HKEY_LOCAL_MACHINE\SYSTEM\ControlSet002\Control\ComputerName\ComputerName","ComputerName","REG_SZ",$Output)
Regwrite("HKEY_LOCAL_MACHINE\SYSTEM\ControlSet002\Services\Eventlog","ComputerName","REG_SZ",$Output) 
RegWrite("HKEY_LOCAL_MACHINE\SYSTEM\ControlSet002\Services\Tcpip\Parameters","Hostname","REG_SZ",$Output)
RegWrite("HKEY_LOCAL_MACHINE\SYSTEM\ControlSet002\Services\Tcpip\Parameters","NV Hostname","REG_SZ",$Output)
RegWrite("HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\ComputerName\ActiveComputerName","ComputerName","REG_SZ",$Output)
RegWrite("HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\ComputerName\ComputerName","ComputerName","REG_SZ",$Output)
RegWrite("HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\Eventlog","ComputerName","REG_SZ",$Output)
RegWrite("HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\Tcpip\Parameters","Hostname","REG_SZ",$Output)
RegWrite("HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\Tcpip\Parameters","NV Hostname","REG_SZ",$Output)
Edited by Kerros

Kerros===============================================================How to learn scripting: Figure out enough to be dangerous, then ask for assistance.

Link to comment
Share on other sites

Cheers but what sort of code is that. AutoIT?....Because I pasted in AutoIT and it chucked an error back at me..

This is how I change the ComputerName under XP using the SN# of my Dell systems.

$Output=""
$objWMIService = ObjGet("winmgmts:\\" & $strComputer & "\root\CIMV2")
$colItems = $objWMIService.ExecQuery("SELECT * FROM Win32_ComputerSystemProduct", "WQL", _
      $wbemFlagReturnImmediately + $wbemFlagForwardOnly)
For $objItem In $colItems
$Output = $objItem.IdentifyingNumber
next
RegWrite("HKEY_LOCAL_MACHINE\SYSTEM\ControlSet001\Control\ComputerName\ActiveComputerName","ComputerName","REG_SZ",$Output)
RegWrite("HKEY_LOCAL_MACHINE\SYSTEM\ControlSet001\Control\ComputerName\ComputerName","ComputerName","REG_SZ" ,$Output)
RegWrite("HKEY_LOCAL_MACHINE\SYSTEM\ControlSet001\Services\Eventlog","ComputerName","REG_SZ",$Output)
RegWrite("HKEY_LOCAL_MACHINE\SYSTEM\ControlSet001\Services\Tcpip\Parameters","Hostname","REG_SZ",$Output)
RegWrite("HKEY_LOCAL_MACHINE\SYSTEM\ControlSet001\Services\Tcpip\Parameters","NV Hostname","REG_SZ",$Output)
RegWrite("HKEY_LOCAL_MACHINE\SYSTEM\ControlSet002\Control\ComputerName\ComputerName","ComputerName","REG_SZ",$Output)
Regwrite("HKEY_LOCAL_MACHINE\SYSTEM\ControlSet002\Services\Eventlog","ComputerName","REG_SZ",$Output) 
RegWrite("HKEY_LOCAL_MACHINE\SYSTEM\ControlSet002\Services\Tcpip\Parameters","Hostname","REG_SZ",$Output)
RegWrite("HKEY_LOCAL_MACHINE\SYSTEM\ControlSet002\Services\Tcpip\Parameters","NV Hostname","REG_SZ",$Output)
RegWrite("HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\ComputerName\ActiveComputerName","ComputerName","REG_SZ",$Output)
RegWrite("HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\ComputerName\ComputerName","ComputerName","REG_SZ",$Output)
RegWrite("HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\Eventlog","ComputerName","REG_SZ",$Output)
RegWrite("HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\Tcpip\Parameters","Hostname","REG_SZ",$Output)
RegWrite("HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\Tcpip\Parameters","NV Hostname","REG_SZ",$Output)
Link to comment
Share on other sites

Copy the code above again.

That code is just a small part of a larger script... I added some constants above.

Edit:

Sorry about missing the constants.

Also remember as they are registry changes you will need to reboot to make them active.

Kerros

Edited by Kerros

Kerros===============================================================How to learn scripting: Figure out enough to be dangerous, then ask for assistance.

Link to comment
Share on other sites

Thats interesting. Just tried it on my PC and then restarted and the PC just looped and looped until i choose last known good configuration.

I am using Vista with this though, maybe it doesn't work with Vista??....Not a problem as I want to use this on XP and 2K but doesn't seem to work on vista for some reason

Link to comment
Share on other sites

I've never tried changing the computer name in vista, as this script was originally written to allow for ghosted images to change the computer name so that there is never more then one on the network. Vista doesn't seem to care if the systems have the same name so I didn't Put this portion of the script into my Vista images.

Kerros

Kerros===============================================================How to learn scripting: Figure out enough to be dangerous, then ask for assistance.

Link to comment
Share on other sites

Sure just do the following after the for loop

$output = 'PC-Serial:'&$output

Kerros===============================================================How to learn scripting: Figure out enough to be dangerous, then ask for assistance.

Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...