Tom's Guide | Tom's Hardware | Tom's Games
![]() |
![]() |
![]() |
hi,
i am trying to rename a computer name on win2003server but faile with the error :
"
Rebooting system...
Not an ARRAY reference at C:\Documents and Settings\Administrator\Desktop\1.pl l
ine 53, <STDIN> line 1."
here is the script:########################################
use Sys::Hostname;$host = hostname();
#############
# Functions #
#############
sub change_hostname{print"Enter new computer name:\n";
chomp ($hostname=<STDIN>);
use Win32::OLE;
$Win32::OLE::Warn = 3;
$strComputer = $host;
$strNewName = $hostname;use constant HKLM => 0x80000002;
$strKeyPath = 'System\\CurrentControlSet\\Control\\ComputerName\\ComputerName';
$objReg = Win32::OLE->GetObject('winmgmts:\\\\' . $strComputer . '\\root\\default:StdRegProv');
$intRC = $objReg->SetStringValue(HKLM, $strKeyPath, 'ComputerName', $strNewName);
if ($intRC != 0) {
print 'Error setting ComputerName value: ' . $intRC, "\n";
}
else {
print "Successfully set ComputerName value to $strNewName\n";
}$strKeyPath = 'System\\CurrentControlSet\\Services\\Tcpip\\Parameters';
$intRC = $objReg->SetStringValue(HKLM, $strKeyPath, 'NV Hostname', $strNewName);
if ($intRC != 0) {
print 'Error setting NV Hostname value: ' . $intRC, "\n";
}
else {
print "Successfully set NV Hostname value to $strNewName\n";
}print "Rebooting system...\n";
$objWMI = Win32::OLE->GetObject('winmgmts:\\\\' . $strComputer . '\\root\\cimv2');
foreach my $objOS (@{$objWMI->InstancesOf('Win32_OperatingSystem')}) {
$objOS->Reboot();
}
}#end of sub change_hostname&change_hostname;
########################################please advice
thanks

What is on line 53 of your script?
Use the strict pragma!
Load your modules at the beginning of the script instead of inside the subroutine. If you load them at the beginning (outside of a sub), they load at compile time instead of run time and any module loading errors will be caught during compilation.
You might find it easier to use the Win32::TieRegistry module instead of Win32::OLE.
http://search.cpan.org/~adamk/Win32...The Windows Resource Kit has a reboot.exe (or it might be shutdown.exe) utility that will simplify the rebooting.

Always start your script with the following lines:
use strict;
use warnings;Also, when declaring variables use the 'my' keyword:
my $hostname=();It's not required, but it's good Perl scripting practice.
"Computer security." — Oxymoron

thanks guys for the tips
use strict;
use warnings; and my .and sorry for the late answer
i have managed by my self to found a way
to do it i am using :
Win32::InitiateSystemShutdown($host,300,0,0,1);thanks
anyway

![]() |
![]() |
![]() |

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.
| Ads by Google |