Run Windows DOS command with PERL

Posted on 2012-09-06
Last Modified: 2012-09-06
Windows 2008 server.  At Winodws Command Prompt.  
I would like to run a PERL script to set user login times.

This is the windows command:  net user UserName /times:M-Su,06:00-22:00

I don't know how to tell perl to run it as a DOS command.

At present I'm only trying to send a single command as shown.
After I can do that then I will figure out how to run a list through the command.

The goal is to run a perl  script on several servers and update multiple user accounts with out spending a huge amount of time doing so.

thanks -- stan
Question by:gstanl
    LVL 13

    Expert Comment

    Could you have Perl execute a batch file? Inside the batch file, you could have "net user UserName /times:M-Su,06:00-22:00"
    LVL 26

    Accepted Solution

    If you don't want any output from the command...
    system("net user UserName /times:M-Su,06:00-22:00");
    if ($@) {
        #error checking here

    Open in new window

    If you do want to capture the output...
    my $out = `net user UserName /times:M-Su,06:00-22:00`;

    Open in new window

    LVL 20

    Expert Comment

    Use the Perl "system" function to access the OS:


    Author Closing Comment

    Excellent, wilcoxon. <br />This is what I was hoping to get and the error output  info is a plus.<br /><br />Yes, I could run a bat file.  But, I wanted to know how to send the DOS command in PERL and the selected solution does that for me.<br /><br />Thanks for the suggestions folks.

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    What Should I Do With This Threat Intelligence?

    Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

    A year or so back I was asked to have a play with MongoDB; within half an hour I had downloaded (,  installed and started the daemon, and had a console window open. After an hour or two of playing at the command …
    Sometimes drives fill up and we don't know why.  If you don't understand the best way to use the tools available, you may end up being stumped as to why your drive says it's not full when you have no space left!  Here's how you can find out...
    This tutorial will walk an individual through the steps necessary to enable the VMware\Hyper-V licensed feature of Backup Exec 2012. In addition, how to add a VMware server and configure a backup job. The first step is to acquire the necessary licen…
    This tutorial will show how to inventory, catalog, and restore media from legacy versions of Backup Exec into both 2012 and 2014 versions of the software. Select Storage from the tabs along the ribbon bar as the top: Ensure the proper storage devi…

    737 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    18 Experts available now in Live!

    Get 1:1 Help Now