use Win32::TieRegistry( Delimiter=>"#", ArrayValues=>0 );
$pound= $Registry->Delimiter("/");
# Este script configura Winbdows 2000 tras pasar el programa ImageCast
# Lo primero es preguntar por la IP
while ($dir_ip = &prompt)
{
if ( ($dir_ip =~ /^(\d{1,3})$/) && ($dir_ip > 0 ) && ($dir_ip < 255 ) )
{
system "cls";
print "\n Configurando PC$dir_ip con IP 192.168.1.$dir_ip\n";
&nombre($dir_ip);
&direccion($dir_ip);
exit 0;
}
}
# Pantalla para introducir la IP
sub prompt
{
local($respuesta) = "";
while ($respuesta eq "")
{
system "cls";
print "\n\n Programa para configurar Windows 2000 tras ImageCast \n";
print "\n Dime la IP de este PC [1-30]: ";
chop($respuesta = );
}
return($respuesta);
}
# Cambia el nombre en el registro
sub nombre
{
local($nombrepc) = @_;
print "\n## Cambiamos el nombre en el registro ##\n";
# Accedemos donde estan los nombres del equipo
# print "\nEntrada HKEY_LOCAL_MACHINE\\System\\CurrentControlSet\\Control\\ComputerName\\ComputerName\n";
$nombre1Key= $Registry->{"LMachine/System/CurrentControlSet/Control/ComputerName/ComputerName"} or die "Can't read LMachine/System/CurrentControlSet/Control/ComputerName/ComputerName key: $^E\n";
foreach(keys %$nombre1Key)
{
if ($_ =~ "^/ComputerName")
{
$actual = $nombre1Key->{$_};
print "\n ComputerName es $actual .";
$nuevo = "PC" . $nombrepc;
print " Ahora ComputerName sera $nuevo\n";
$nombre1Key->SetValue("ComputerName", $nuevo);
}
}
# print "\nEntrada HKEY_LOCAL_MACHINE\\System\\CurrentControlSet\\Services\\Tcpip\\Parameters\n";
$nombre2Key= $Registry->{"LMachine/System/CurrentControlSet/Services/Tcpip/Parameters"} or die "Can't read LMachine/System/CurrentControlSet/Services/Tcpip/Parameters key: $^E\n";
foreach(keys %$nombre2Key)
{
if ($_ =~ "^/Hostname")
{
$actual = $nombre2Key->{$_};
print " Hostname es $actual .";
$nuevo = "pc" . $nombrepc;
print " Ahora Hostname ser $nuevo\n";
$nombre2Key->SetValue("Hostname", $nuevo);
}
if ($_ =~ "^/NV Hostname")
{
$actual = $nombre2Key->{$_};
print " NV Hostname es $actual .";
$nuevo = "pc" . $nombrepc;
print " Ahora NV Hostname ser $nuevo\n";
$nombre2Key->SetValue("NV Hostname", $nuevo);
}
}
# Primero nos pillamos el nombre del servicio
# print "\nEntrada HKEY_LOCAL_MACHINE\\Software\\Microsoft\\Windows NT\\CurrentVersion\\NetworkCards\\1\n";
$cardKey= $Registry->{"LMachine/Software/Microsoft/Windows NT/CurrentVersion/NetworkCards/1"} or die "Can't read LMachine/Software/Microsoft/Windows NT/CurrentVersion/NetworkCards/1 key: $^E\n";
foreach( keys %$cardKey)
{
if ($_ =~ "ServiceName")
{
$servicename = $cardKey->{$_};
}
}
# print "ServiceName es ", $servicename, "\n";
# Ahora accedemos donde esta el nombre
# print "\nEntrada HKEY_LOCAL_MACHINE\\System\\CurrentControlSet\\Services\\Tcpip\\Parameters\\DNSRegisteredAdapters\\$servicename\n";
$nombre3Key= $Registry->{"LMachine/System/CurrentControlSet/Services/Tcpip/Parameters/DNSRegisteredAdapters/$servicename"} or die "Can't read LMachine/System/CurrentControlSet/Services/Tcpip/Parameters/DNSRegisteredAdapters/$servicename key: $^E\n";
foreach(keys %$nombre3Key)
{
if ($_ =~ "^/HostName")
{
$actual = $nombre3Key->{$_};
print " HostName es $actual .";
$nuevo = "pc" . $nombrepc;
print " Ahora HostName ser $nuevo\n";
$nombre3Key->SetValue("HostName", $nuevo);
}
}
print "\n## Cambiamos el nombre con el comando netsh ##\n";
$actual =~ s/pc//g;
print "\n La IP es 192.168.1.$actual .";
}
# Cambia la direccion IP en el registro
sub direccion
{
local($numero) = @_;
system "netsh interface ip set address \"Conexion de area local\" static 192.168.1.$numero 255.255.255.0 192.168.1.100 1";
print "\n Ahora la IP ser 192.168.1.$numero\n";
}