Expiring Today—Celebrate National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Can I pass command line arguments from inside a file?

Posted on 2014-04-04
6
Medium Priority
?
1,073 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
6 Comments
 
LVL 57

Accepted Solution

by:
Bill Prew earned 1600 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
Optimum High-Definition Video Viewing and Control

The ATEN VM0404HA 4x4 4K HDMI Matrix Switch supports 4K resolutions of UHD (3840 x 2160) and DCI (4096 x 2160) with refresh rates of 30 Hz (4:4:4) and 60 Hz (4:2:0). It is ideal for applications where the routing of 4K digital signals is required.

 
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 57

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

Connect further...control easier

With the ATEN CE624, you can now enjoy a high-quality visual experience powered by HDBaseT technology and the convenience of a single Cat6 cable to transmit uncompressed video with zero latency and multi-streaming for dual-view applications where remote access is required.

Question has a verified solution.

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

Windows 10 Creator Update has just been released and I have it working very well on my laptop. Read below for issues, fixes and ideas.
By default Outlook 2016 displays only one time zone in the Calendar. The following article explains how to display two time zones in one calendar view.
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…
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.

730 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