Jump to content
Sign in to follow this  
jben

Change computername AutoIT implementation

Recommended Posts

jben

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

Share this post


Link to post
Share on other sites
Jos

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


Visit the SciTE4AutoIt3 Download page for the latest versions  - Beta files                                How to post scriptsource        Forum Rules
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Share this post


Link to post
Share on other sites
LarryDalooza

WMI can get bios info and other info...

There are many ways render a kitten skinless.

Lar.


f_mrcleansmalm_77ce002.jpgAutoIt has helped make me wealthy

Share this post


Link to post
Share on other sites
jben

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

Share this post


Link to post
Share on other sites
spudw2k

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.

Share this post


Link to post
Share on other sites
Kerros

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.

Share this post


Link to post
Share on other sites
jben

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)

Share this post


Link to post
Share on other sites
Kerros

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.

Share this post


Link to post
Share on other sites
jben

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

Share this post


Link to post
Share on other sites
Kerros

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.

Share this post


Link to post
Share on other sites
jben

Ok no problem. I will try this out on Win 2k and XP soon.

Is it possible to fix some text before the serial?

as in PC-serialinfo

Share this post


Link to post
Share on other sites
Kerros

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.

Share this post


Link to post
Share on other sites
jben

Not sure where to stick that code.

Do you mean:

For $objItem In $colItems

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

next

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  

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.