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; } }

In reply to Install a perl script as a Win NT/2000/XP service. by jryan

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.