Solved

Can I pass command line arguments from inside a file?

Posted on 2014-04-04
6
1,045 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 53

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
Courses: Start Training Online With Pros, Today

Brush up on the basics or master the advanced techniques required to earn essential industry certifications, with Courses. Enroll in a course and start learning today. Training topics range from Android App Dev to the Xen Virtualization Platform.

 
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 53

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

Gigs: Get Your Project Delivered by an Expert

Select from freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely and get projects done right.

Question has a verified solution.

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

Today, still in the boom of Apple, PC's and products, nearly 50% of the computer users use Windows as graphical operating systems. If you are among those users who love windows, but are grappling to keep the system's hard drive optimized, then you s…
An article on effective troubleshooting
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…
Windows 8 came with a dramatically different user interface known as Metro. Notably missing from that interface was a Start button and Start Menu. Microsoft responded to negative user feedback of the Metro interface, bringing back the Start button a…

813 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

11 Experts available now in Live!

Get 1:1 Help Now