This perl script uses srvany and instsrv (two free programs from Microsoft; put on my perlmonk.org website for ease of linking) to install a perl script as a Windows NT/2000/XP service. Pretty handy, if you ask me.
#!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;
}
}
-
Are you posting in the right place? Check out Where do I post X? to know for sure.
-
Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
<code> <a> <b> <big>
<blockquote> <br /> <dd>
<dl> <dt> <em> <font>
<h1> <h2> <h3> <h4>
<h5> <h6> <hr /> <i>
<li> <nbsp> <ol> <p>
<small> <strike> <strong>
<sub> <sup> <table>
<td> <th> <tr> <tt>
<u> <ul>
-
Snippets of code should be wrapped in
<code> tags not
<pre> tags. In fact, <pre>
tags should generally be avoided. If they must
be used, extreme care should be
taken to ensure that their contents do not
have long lines (<70 chars), in order to prevent
horizontal scrolling (and possible janitor
intervention).
-
Want more info? How to link
or How to display code and escape characters
are good places to start.
|