Dear all,

       I find that it will be great if the computer can be shutdown after all installation. Due to some reason, if this feature is absent, those computers need to be switched on overnight.

      However, it seems that there are no such feature in the unattended.

      I made the following changes and hope this will be useful to other site.

      I have add a .shutdown directive to the todo.pl

      Depedening on the answer file, the install.pl may add a todo.pl .shutdown "after" (since it is a stack) the todo.pl .reboot (the final reboot)
     
      The detail changes are as follow:

add this function for shutdown the computer
sub shutdownComputer ($) {
    my ($timeout) = @_;
    AllowPriv (SE_SHUTDOWN_NAME, 1)
        or die "Unable to AllowPriv SE_SHUTDOWN_NAME: $^E";

    print "$0 is shutting down the system\n";
    InitiateSystemShutdown ('', "$0: Shutting down...", $timeout, 1, 0)
        or die "Unable to InitiateSystemShutdown: $^E";
    stop ();
}

add this "elsif block" to the do_cmd function

elsif ($cmd eq '.shutdown') {
    shutdownComputer(5);
    die 'Internal error';
}


after that the todo.pl should be able to shutdown the computer when we run
todo.pl .shutdown
todo.pl --go

However, if we need to shutdown the computer after the whole process, we can't use any of the top middle or bottom scripts.

That's why I need to modify the install.pl, the achieve the result that the todo.pl .shutdown will be added the the postinst.bat

In line 815, split the orginal push statement, in order the add the todo.pl .shutdown in the middle. The modified push statements are as follows. (1 push statement become 3 push statement) It read the $u->{'_meta'}->{'shutdown'} because I don't think it is a good idea to hardcode the shutdown here, I want to made it configurable using the answer file.

    push @postinst_lines,
    ('call %Z%\\scripts\\perl.bat',
     'PATH=%Z%\\bin;%PATH%');
    my $tempShutdown = $u->{'_meta'}->{'ntp_servers'};
    defined $tempShutdown && $tempShutdown ne ''
        and push @postinst_lines, 'todo.pl .shutdown';
    push @postinst_lines,
    (# Last step is always a reboot.
     'todo.pl .reboot',
     # Penultimate step is to disable automatic logon.
     ' todo.pl "' . $u->{'_meta'}->{'autolog'} . '"',
     # Antepenultimate step is to delete credentials file.
     "todo.pl \"del $tempcred\"",
     # After installing, re-enable System Restore.
     'todo.pl "srconfig.pl --enable"',
     # Before that, add users to the local Administrators group.
     (map { "todo.pl \"net localgroup \\\"%%Administrators%%\\\" \\\"$_\\\" /add\"" } @admins));

Hope this will be useful
-------------------------------------------------------------------------
Take Surveys. Earn Cash. Influence the Future of IT
Join SourceForge.net's Techsay panel and you'll get the chance to share your
opinions on IT & business topics through brief surveys -- and earn cash
http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV
_______________________________________________
unattended-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/unattended-devel

Reply via email to