use strict;
use Win32::OLE;
use Config;
use File::Basename;
my $szPerlScript = shift @ARGV;
my $szServiceName = shift @ARGV;
my $szSrvAnyPath = shift @ARGV;
unless (-e $szPerlScript) {
die "Please give me a script\n";
}
unless (-e $szSrvAnyPath) {
die "srvany.exe not found\n";
}
unless ($szServiceName) {
$szServiceName = basename($szPerlScript);
}
my $szComputer = '.';
my $szPerlPath = $Config{perlpath};
$szPerlScript =~ s/\//\\/g;
$szSrvAnyPath =~ s/\//\\/g;
$szPerlPath =~ s/\//\\/g;
use constant HKLM => 0x80000002;
# Service Type
use constant KERNEL_DRIVER => 1;
use constant FS_DRIVER => 2;
use constant ADAPTER => 4;
use constant RECOGNIZER_DRIVER => 8;
use constant OWN_PROCESS => 16;
use constant SHARE_PROCESS => 32;
use constant INTERACTIVE_PROCESS => 256;
my $INTERACT_WITH_DESKTOP = 0;
my $_NOTIFED;
# Error Control
use constant NOT_NOTIFIED => 0;
use constant USER_NOTIFIED => 1;
use constant SYSTEM_RESTARTED => 2;
use constant SYSTEM_STARTS => 3;
# Create Service
my $hWMI = Win32::OLE->GetObject('winmgmts:\\\\'.$szComputer.'\\root\\cimv2');
my $hService = $hWMI->Get('Win32_Service');
my $wResult = $hService->Create($szServiceName, $szServiceName, $szSrvAnyPath, OWN_PROCESS, !$_NOTIFED, 'Automatic', $INTERACT_WITH_DESKTOP, 'NT AUTHORITY\\LocalService', '');
if ($wResult > 0) {
print "Error creating service $szServiceName: $wResult\n";
exit 0;
}
else {
print "Successfully created service $szServiceName: $wResult\n";
}
# Create Registry Entry
my $szKeyPath = 'SYSTEM\\CurrentControlSet\\Services\\'.$szServiceName.'\\Parameters';
my $hReg = Win32::OLE->GetObject('winmgmts:\\\\'.$szComputer.'\\root\\default:StdRegProv');
$hReg->CreateKey(HKLM, $szKeyPath);
$hReg->SetStringValue(HKLM, $szKeyPath, 'Application', $szPerlPath);
$hReg->SetStringValue(HKLM, $szKeyPath, 'AppParameters', $szPerlScript);
print "Created registry values\n";
# Start Service
$hService = $hWMI->Get('Win32_Service.Name=\''.$szServiceName.'\'');
$wResult = $hService->StartService();
if ($wResult > 0) {
print "Error starting service $szServiceName: $wResult\n";
}
else {
print "Successfully started service $szServiceName\n";
}
####
my $szPath = 'C:\winzip.log';
while (1) {
unlink $szPath;
select(undef, undef, undef, 60);
}
####
use Wx qw(:everything);
use Wx::Locale qw(:default);
use Wx::Event qw(:everything);
my $hApp = Handler->new();
$hApp->MainLoop();
package Handler;
use strict;
use Wx qw(:everything);
use Wx::Event qw(EVT_TIMER);
use base qw(Wx::App);
sub new {
my ($class) = @_;
my $this = $class->SUPER::new();
return $this;
}
sub OnInit {
my ($this) = @_;
$this->{hWnd} = Wx::MessageDialog->new(undef, 'Timer Message');
$this->{wId} = Wx::NewId();
$this->{hTimer} = Wx::Timer->new($this, $this->{wId});
$this->{hTimer}->Start(1000);
EVT_TIMER($this, $this->{wId}, \&OnTimer);
return 1;
}
sub OnTimer {
my ($this, $hEvent) = @_;
# Stop Timer while processing
$this->{hTimer}->Stop();
if (-e 'c:/winzip.log') {
unlink 'c:/winzip.log';
}
$this->{hWnd}->ShowModal();
# Restart Timer for more
$this->{hTimer}->Start(1000);
}