Solved

Can I pass command line arguments from inside a file?

Posted on 2014-04-04
6
898 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 51

Accepted Solution

by:
Bill Prew earned 400 total points
Comment Utility
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
Comment Utility
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
Comment Utility
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
6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

 
LVL 9

Expert Comment

by:nick2253
Comment Utility
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 51

Expert Comment

by:Bill Prew
Comment Utility
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
Comment Utility
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

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Ever notice how you can't use a new drive in Windows without having Windows assigning a Disk Signature?  Ever have a signature collision problem (especially with Virtual Machines?)  This article is intended to help you understand what's going on and…
Citrix XenApp, Internet Explorer 11 set to Enterprise Mode and using central hosted sites.xml file.
With the advent of Windows 10, Microsoft is pushing a Get Windows 10 icon into the notification area (system tray) of qualifying computers. There are many reasons for wanting to remove this icon. This two-part Experts Exchange video Micro Tutorial s…
With the advent of Windows 10, Microsoft is pushing a Get Windows 10 icon into the notification area (system tray) of qualifying computers. There are many reasons for wanting to remove this icon. This two-part Experts Exchange video Micro Tutorial s…

744 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

13 Experts available now in Live!

Get 1:1 Help Now