Beefy Boxes and Bandwidth Generously Provided by pair Networks
Pathologically Eclectic Rubbish Lister
 
PerlMonks  

Perl as a background process on Windows NT/2000

by akm2 (Scribe)
on Aug 17, 2001 at 19:00 UTC ( [id://105691]=perlquestion: print w/replies, xml ) Need Help??

akm2 has asked for the wisdom of the Perl Monks concerning the following question:

Here is a question for all you Windows NT/2000 ActivePerl (from ActiveState) users out there. I'm running version 5.6.1 built for MSWin32-x86-multi-thread (Binary build 628) on Windows 2000 Server Edition with Service Pack 2.

I have a Perl script that runs each time a certain user logs on. Right-now the script is being executed by a shortcut in the user's Startup Folder on the Start Menu, but soon I will be executing the script using the Run section of the user's Registry.

Every time a Perl script is executed on a Windows NT/2000 system, a Command Prompt is loaded to the taskbar. In my application this is a security risk. I don't want this user to have access to any form of a Command Prompt. Do any of you guys out there know of a way I can run my script at startup in the background or as a service, so the user won't have access to a Command Prompt?

Thanks in advance for any advise!

Andrew Kenton Mitchell
Andrew@AndrewKMitchell.com

  • Comment on Perl as a background process on Windows NT/2000

Replies are listed 'Best First'.
Re: Perl as a background process on Windows NT/2000
by Eustaquio (Novice) on Aug 17, 2001 at 19:20 UTC
    There is "wperl.exe" that runs a script without show a command prompt. You can find it at perl\bin. I hope this help. Eustaquio.
Re: Perl as a background process on Windows NT/2000
by joefission (Monk) on Aug 17, 2001 at 19:25 UTC
    Your script can run without a command prompt in user's window by using Win32::Process.
    WARNING:I know it works for NT4, but I haven't tested it on W2K.

    If you go the services route, you may be interested in Dave Roth's Win32::Daemon module which doesn't need srvany.exe. Looks short on documentation, though.

Re: Perl as a background process on Windows NT/2000
by Graham (Deacon) on Aug 17, 2001 at 19:10 UTC
    The WindowsNT resource kit comes with a program called srvany.exe.
    This will allow you to run an application as an NT service and should do what you require.
Re: Perl as a background process on Windows NT/2000
by Starky (Chaplain) on Aug 17, 2001 at 22:36 UTC
    I've used srvany.exe from the NT Resource Kit, and can confirm that it works well for running Perl scripts as a service, although last time I used it (a couple years ago) the documentation sucked.

    ActiveState also has PerlSvc, part of their Dev Kit, which allows you to compile Perl scripts to be run as services. I haven't used PerlSvc, but I used their compiler (PerlApp) a couple years ago, and if it's as bomber as their compiler, it should work well. (If their compiler was bomber then, I can only imagine it's really spanking nice now!)

    However, I don't think your question is exactly "how do I run a Perl script as a service?" but more "how do I run a Perl script once upon a certain event (login) by a user and exit without giving the user any indication that the script is running?" In this case, there is a flag that you can feed to PerlApp (I can't remember what it is, as I haven't used Windows in a couple years, but I remember that it's there) which will keep your executable from popping up a DOS window.

    Aside from addressing your concern, compiling your script will give you a couple other advantages: (i) Perl doesn't have to be installed on the machine the compiled script is running on and (ii) you never have to worry about differences in Perl or Perl module versions hosing your script. If you're distributing this to many users and can't count on them keeping their Perl distributions properly administered, (ii) can make a big difference.

    Hope this helps!

Re: Perl as a background process on Windows NT/2000
by RayRay459 (Pilgrim) on Aug 17, 2001 at 19:17 UTC
    Question...Does the script need to continue to run after it is executed at logon? If not, why not have the script exit after it is run. Maybe thats an obvious thought, but thought i might throw that out there anyways. :) Happy Hunting. Ray

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://105691]
Approved by root
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others having an uproarious good time at the Monastery: (7)
As of 2024-04-23 18:42 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found