Skip to content

Commit

Permalink
add code for automatic restart as administrator
Browse files Browse the repository at this point in the history
  • Loading branch information
haarg committed Apr 7, 2010
1 parent 2782463 commit d93667d
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 4 deletions.
37 changes: 35 additions & 2 deletions bin/mjollnir.pl
@@ -1,11 +1,44 @@
#!perl
use Mjollnir;
use Getopt::Long qw(:config gnu_getopt no_auto_abbrev);

if ($^O eq 'MSWin32') {
require Win32;
if (! Win32::IsAdminUser()) {
Getopt::Long::GetOptions(
'respawn' => \(my $respawn),
);
require Win32::API;

my @parameters = ($0, @ARGV);
for my $param (@parameters) {
if ( $param =~ s/(["\\])/\\$1/g || $param =~ / / ) {
$param = qq{"$param"};
}
}
my $parameters = join ' ', @parameters;

my $ShellExecuteEx = Win32::API->new('shell32.dll', 'ShellExecuteEx', ['P'], 'N')
or die 'Get ShellExecuteEx: ' . Win32::FormatMessage(Win32::GetLastError());

my $lpVerb = pack 'A*', 'runas';
my $lpFile = pack 'A*', $^X;
my $lpParameters = pack 'A*', $parameters;

my $args = pack 'LLLPPPPLLLPLLLL';
$args = pack 'LLLPPPPLLLPLLLL', length $args, ($respawn ? 0x8000 : 0), 0, $lpVerb, $lpFile, $lpParameters, 0, 1, 0, 0, 0, 0, 0, 0, 0;

my $ret = $ShellExecuteEx->Call($args)
or die 'Call ShellExecuteEx: ' . Win32::FormatMessage(Win32::GetLastError());
exit;
}
}

require Mjollnir;
my $options = {};
Getopt::Long::GetOptions( $options, qw(
listen|l=s@
db_file|db|d=s
device|dev|D=s
respawn
)) || die "usage: $0 [ -l<host>:<port> ] [ -D<device> ] [ -d<database> ]\n";
Mjollnir->run($options);

5 changes: 3 additions & 2 deletions installer/installer.nsi
Expand Up @@ -81,6 +81,7 @@ Section ""
ExecWait '"$PLUGINSDIR\winpcap-nmap-4.11.exe" /S'
nsExec::ExecToLog 'C:\strawberry\perl\bin\perl.exe C:\strawberry\perl\bin\ppm.pl install Net::Pcap'
nsExec::ExecToLog 'C:\strawberry\perl\bin\perl.exe -MCPAN -e notest(@ARGV) install .'

CreateShortcut "$DESKTOP\Mjollnir.lnk" C:\strawberry\perl\bin\perl.exe C:\strawberry\perl\bin\mjollnir.pl "$SYSDIR\shell32.dll" 10

SetOutDir $SYSDIR
CreateShortcut "$DESKTOP\Mjollnir.lnk" C:\strawberry\perl\bin\perl.exe "C:\strawberry\perl\bin\mjollnir.pl --respawn" "$SYSDIR\shell32.dll" 10
SectionEnd

0 comments on commit d93667d

Please sign in to comment.