Solved

Can I pass command line arguments from inside a file?

Posted on 2014-04-04
6
1,055 Views
Last Modified: 2014-04-08
Is it possible to pass command line arguments to the command prompt from inside a text file?  

I have several scheduled tasks in Windows Task Scheduler that myprogram.exe with the arguments "pswd=mypassword mypgmparm=thisvalue".  Is it possible to place the argments inside a text file so I don't have to modify every task whenever I want to change the command line parameter the program uses?
0
Comment
Question by:LesterJebson
6 Comments
 
LVL 54

Accepted Solution

by:
Bill Prew earned 400 total points
ID: 39978524
Inside of a BAT script you can use FOR /F to read a text file and process data from it in the BAT script, so you could read a password from a text file, assign it to a variable in the BAT script, and then pass that variable to an EXE on a command line.  Of course, storing account info in a TXT file is a bit risky, but I'll leave that to you to weigh.

If you can give a bit more info on what you schedule today, if you are using a BAT file, what has to execute, etc, we can give specific examples.

~bp
0
 
LVL 9

Expert Comment

by:nick2253
ID: 39978557
That's very doable.

However, I would strongly recommend switching to Windows Powershell for scripting, instead of Batch.  Batch is really out-dated, as opposed to Powershell, which was designed for sysadmins, and contains numerous incredibly powerful features that make scripting a breeze.
0
 
LVL 43

Expert Comment

by:Steve Knight
ID: 39978597
nick2253,

totally agreed about powershell, stuff that is hard in batch or neededing VBScript bits or other utils etc. natively BUT if just talking about running a few exe's with command line options probably good idea to do this.

If you want the password semi-hidden too you could place them in an alternative data stream within the text file so opened it notepad it just looks like "This is a text file", e.g. see this technique:

http://scripts.dragon-it.co.uk/links/batch-password1
http://scripts.dragon-it.co.uk/links/batch-password2

That doesn't have to be in the batch file itself (which is why we used %0) but any other file.  Still available to find it for anyone who knows how but a bit better than a plain text file.

Steve
0
How Do You Stack Up Against Your Peers?

With today’s modern enterprise so dependent on digital infrastructures, the impact of major incidents has increased dramatically. Grab the report now to gain insight into how your organization ranks against your peers and learn best-in-class strategies to resolve incidents.

 
LVL 9

Expert Comment

by:nick2253
ID: 39978636
Hiding passwords in other data streams is highly insecure.  Worse, it gives the impression of security where none is to be had.

If you really need your password to be secure, you need to encrypt it, and use an appropriate program to process on it.

Lastly, there's no reason to use batch anymore.  For the use cases that you provide, a Powershell Script is at worst no more work than a batch file.  I can't think of a single case where a batch file would be less work than a powershell script.
0
 
LVL 54

Expert Comment

by:Bill Prew
ID: 39978779
You might want to look at this prior question as well, it had some interesting discussion about this topic.

http://www.experts-exchange.com/OS/Microsoft_Operating_Systems/MS_DOS/Q_25000620.html

~bp
0
 

Author Closing Comment

by:LesterJebson
ID: 39987644
This works!  Thank you.  

I wish I could've done this in Powershell instead of a .bat file.  The thing that prevented that was we do not have rights to run Powershell scripts in batch mode on that computer.
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

In this article, I will show you HOW TO: Install VMware Tools for Windows on a VMware Windows virtual machine on a VMware vSphere Hypervisor 6.5 (ESXi 6.5) Host Server, using the VMware Host Client. The virtual machine has Windows Server 2016 instal…
This article summaries thoughts and ideas from two years of sustained use. It provides good reasoning to make the jump to Windows 10.
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
This video Micro Tutorial explains how to clone a hard drive using a commercial software product for Windows systems called Casper from Future Systems Solutions (FSS). Cloning makes an exact, complete copy of one hard disk drive (HDD) onto another d…

696 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