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

Is perl the correct language to learn if I want to create an application that i can use on my web site to start and stop Windows Services? Sorry for my ignorance but I am just now trying to break into learning code and am looking for a little direction.

Thanks To all that can Help :0)

janitored by ybiC: Retitle from "Web Based" for searchability

  • Comment on Start/stop win32 services with CGI - is Perl a good choice?

Replies are listed 'Best First'.
Re: Start/stop win32 services with CGI - is Perl a good choice?
by b10m (Vicar) on Jan 08, 2004 at 14:17 UTC

    Yup, you could do that with Perl (and what a wise choice of you! :) Take a peek at Win32::Service after you've learned some basics. That Perl module looks like what you need (and you probably want CGI too).

    --
    b10m
Re: Start/stop win32 services with CGI - is Perl a good choice?
by crabbdean (Pilgrim) on Jan 08, 2004 at 14:21 UTC
    You can do this sort of thing in perl using the Win32::Service module. I've never used this module but its fairly simple and probably a good start if you've never used perl.

    You can also simply start and stop services on the command line in Windows using "net start" and "net stop" commands. These you can add into a batch file and run from that. Eg to start the printer spooler you type "net start spooler". You only limited access though as to which services you can stop and start this way.

    Dean
Re: Start/stop win32 services with CGI - is Perl a good choice?
by Art_XIV (Hermit) on Jan 08, 2004 at 15:22 UTC

    That's a little like asking if a Hummer is the correct vehicle for getting in and out of a driveway.

    Perl is a wonderful general-purpose language that can do alot - It's very good for web-based applications, and it can start and stop Windows services, but it can also do a whole lot more.

    Perl's not a bad pick for learning about programming - one of the really nice things about it is that Perl works on most operating systems while being more accessible than Java. It doesn't try to force you into using object-oriented methodologies, either, but the OO features are there if you want them.

    If you know very little or nothing about coding then I would recommend Learning Perl or Elements of Programming with Perl. Both of these books are fairly gentle introductions to Perl and neither assume that you have a background in coding. You could even check out some of the tutorials here on Perl Monks or on other sites if you don't wish to purchase a book.

    Hanlon's Razor - "Never attribute to malice that which can be adequately explained by stupidity"
Re: Start/stop win32 services with CGI - is Perl a good choice?
by NetWallah (Canon) on Jan 08, 2004 at 18:26 UTC
    Before your write code for this function, please look at simpler alternatives:
    • NET STOP W3SVC and NET START W3SVC
      You can run these commands if you have the right privileges, and have access to running system commands.
    • IISRESET.EXE
      This command is designed for the specific purpose of restarting IIS - I think it comes with IIS 5 and above.
      Usage: iisreset [computername] /RESTART Stop and then restart all Internet services. /START Start all Internet services. /STOP Stop all Internet services. /REBOOT Reboot the computer. /REBOOTONERROR Reboot the computer if an error occurs when st +arting, stopping, or restarting Internet services. /NOFORCE Do not forcefully terminate Internet services +if attempting to stop them gracefully fails. /TIMEOUT:val Specify the timeout value ( in seconds ) to wa +it for a successful stop of Internet services. On exp +iration of this timeout the computer can be rebooted i +f the /REBOOTONERROR parameter is specified. The default value is 20s for restart, 60s for +stop, and 0s for reboot. /STATUS Display the status of all Internet services. /ENABLE Enable restarting of Internet Services on the local system. /DISABLE Disable restarting of Internet Services on the local system.
    Update: Corrected spelling of 'IISRESET'

    "When you are faced with a dilemma, might as well make dilemmanade. "
Re: Start/stop win32 services with CGI - is Perl a good choice?
by maa (Pilgrim) on Jan 09, 2004 at 08:47 UTC

    Hi,

    Win32::Service has already been suggested but you need to remember one thing... you're going to have to authenticate the user with the O/S to control the services.

    That's easy if you're doing this on an intranet (enable NTLM on the virtual folder)then just go for it... if they have sufficient rights it'll work. It's a lot more complicated if you don't have NTLM or you're talking about doing it over an internet connection...

    If you can be more specific (intranet/www, proposed authentication method etc) you might get some even better pointers.

    HTH - Mark

      Assuming that you are using IIS as the web server - maa has pointed out one of the ways to make sure that you are using the correct user account to stop and restart services (an action that requires user permissions). The other ways include:

      1. Enabling basic authentication and setting the domain that IIS checks against to be the local machine. Login as a user with the correct permissions to run your CGI script.
      2. Change the user account that IIS uses for anonymous access to one with appropriate access.

      Neither method is particularly desirable. The first method passes unecrypted user credentials over the network and the second method requires no Windows NT credentials to be passed.

      The second method is however a useful technique if the CGI script is participating in another logon scheme such as a cookie based system or if it is protected by a secure single signon system.