#!perl -w use strict; use FindBin; use Config; while(1) { print "Please enter your script's name:\n"; my $srvname = <>; chomp $srvname; my($srv) = $srvname =~ /^(\w+)/; if ($srv =~ /[a-z]\w+/i) { my $dir = $FindBin::Bin; $dir =~ s/\//\\\\/g; my $ret = `instsrv $srv $dir\\srvany.exe`; if ($ret =~ /success/i) { my $perlpath = $Config{perlpath}; $perlpath =~ s/\\/\\\\/g; my $srvpath = $FindBin::Bin; $srvpath =~ s/(?<=\\)[^\\]+$//; $srvpath =~ s/\//\\\\/g; $srvpath .= "\\\\$srvname"; my $reg = qq( REGEDIT4 [HKEY_LOCAL_MACHINE\\SYSTEM\\CurrentControlSet\\Servic +es\\) .$srvname.qq(\\Parameters] "Application"="$perlpath" "AppParameters"="$srvpath" ); $reg =~ s/^\n//; my ($space) = $reg =~ /^(\s+)/; $reg =~ s/^$space//gm; open (OUT, ">reg.reg") or die $!; print OUT $reg."\n"; close OUT; my $errormsg = qq( Couldn't automatically add necessary inf +ormation to registry... generating necessary regi +stry file, please add manually by double-clic +king on it. ); $errormsg =~ s/(?<=\n)\s+//g; system ("reg.reg") and die $errormsg; unlink "reg.reg"; print "\n\n$ret"; exit 0; } else { die qq(Error installing $srvname as service: "$ret"\n); } } else { my $errormsg = qq( Error: Your script's name must start with a + letter, and can only contain letters, numbers, and +the underscore. Please try again. ); $errormsg =~ s/(?<=\n)\s+//g; print $errormsg; } }
In reply to Install a perl script as a Win NT/2000/XP service. by jryan
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |