[Last Call] Learn how to a build a cloud-first strategyRegister Now


Run Windows DOS command with PERL

Posted on 2012-09-06
Medium Priority
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

ID: 38374114
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 27

Accepted Solution

wilcoxon earned 2000 total points
ID: 38374172
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

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

See: http://www.perlhowto.com/executing_external_commands

Author Closing Comment

ID: 38374573
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.

Featured Post

How to Use the Help Bell

Need to boost the visibility of your question for solutions? Use the Experts Exchange Help Bell to confirm priority levels and contact subject-matter experts for question attention.  Check out this how-to article for more information.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

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...
OfficeMate Freezes on login or does not load after login credentials are input.
This tutorial will walk an individual through locating and launching the BEUtility application to properly change the service account username and\or password in situation where it may be necessary or where the password has been inadvertently change…
This tutorial will walk an individual through the steps necessary to install and configure the Windows Server Backup Utility. Directly connect an external storage device such as a USB drive, or CD\DVD burner: If the device is a USB drive, ensure i…

830 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