Jump to content

Recommended Posts

Posted

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

Posted

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

Posted

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.

Posted (edited)

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.

Posted

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)
Posted (edited)

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.

Posted

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

Posted

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.

Posted

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

Posted

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.

Posted

Not sure where to stick that code.

Do you mean:

For $objItem In $colItems

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

next

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
×
×
  • Create New...