mallen has asked for the wisdom of the Perl Monks concerning the following question:

After my script changes values in the registry I need to have their machine reboot. I have tried this code but it does not work. I have never used the reboot function before, so if someone could help me out.
use Win32::TieRegistry(Delimiter=>'/'); my $ms= $Registry->{'LMachine/SYSTEM/ControlSet001/Services/'}; $ms->{'Tcpip/'} = { 'Parameters/'=> {'/SearchList' => ['test','REG_ +SZ']}}; my $ms= $Registry->{'LMachine/SYSTEM/ControlSet001/Services/'}; $ms->{'Tcpip/'} = { 'Parameters/'=> {'/DhcpDomain' => ['','REG_SZ'] +}}; Win32::InitiateSystemShutdown( '', "\nAction Complete.\n\nSystem will +now Reboot\!", 20, 0, 1 );

Replies are listed 'Best First'.
Re: After changing registry values need to reboot systems
by ikegami (Patriarch) on Apr 08, 2005 at 16:12 UTC

    After adding use Win32;, your shutdown command worked for me (ActivePerl 5.6.1 on Win2k Pro SP4) with no changes. Keep in mind it doesn't work on all versions of Windows. The documentation states it only works on the following OSs:

    • WinXP
    • Win2003 Server
    • Win2k Pro & Server
    • WinNT Workstation & Server.

    It will not work on:

    • WinME
    • Win98
    • Win95

    By the way, it would be nice if you asked the user if he wanted to reboot before calling this command.

Re: After changing registry values need to reboot systems
by ikegami (Patriarch) on Apr 08, 2005 at 15:26 UTC

    I don't know anything about shutting down, but it looks to me that you are clobbering part of your registry in the first part of your script. I've never used TieRegistry, so take this with skepticisim, but it looks like
    $ms->{'Tcpip/'} = { 'Parameters/'=> ... };
    will erase everything that's inside of Tcpip. Try:
    $ms->{'Tcpip/'}{'Parameters/'}{'SearchList'} = ['test','REG_SZ'];
    and
    $ms->{'Tcpip/'}{'Parameters/'}{'DhcpDomain'} = ['','REG_SZ'];

    You have
    my $ms = $Registry->{'LMachine/SYSTEM/ControlSet001/Services/'};
    twice. The second one is not needed. In fact, it should give you a warning.

    Also, REG_SZ appears to the be default, so
    $ms->{'Tcpip/'}{'Parameters/'}{'SearchList'} = 'test';
    is sufficient.

    So, the final script is:

    use Win32::TieRegistry; my $ms = $Registry->{'LMachine/SYSTEM/ControlSet001/Services/'}; $ms->{'Tcpip/'}{'Parameters/'}{'SearchList'} = 'test; $ms->{'Tcpip/'}{'Parameters/'}{'DhcpDomain'} = ''; ...shutdown code...

    or we could eliminate some redundancy:

    use Win32::TieRegistry; my $ms = $Registry->{'LMachine/SYSTEM/ControlSet001/Services/'}; my $tcpip_param = $ms->{'Tcpip/Parameters/'}; $tcpip_param->{'SearchList'} = 'test; $tcpip_param->{'DhcpDomain'} = ''; ...shutdown code...