Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1789
  • Last Modified:

Batch file to read target path and set variable

I can't appear to find the "Windows Batch Scripting" zone to assign to!!!

Hi (me again!),

I've got a shortcut which has the INI file location within the target path... current value would be:

"C:\progra~1\applic~1\folder\file.exe" inifile=\\server\share\folder\file.ini

Open in new window


I want my batch file to read the target path of the defined shortcut and set a variable dependant on it... therefore for the above example, %inifile% should equal the link after "inifile=" in the target path?

Does that make sense? Any help is appreciated :)
0
Jofnn
Asked:
Jofnn
1 Solution
 
DocSeltsamCommented:
Hi there,

does it have to be a batch? Can't you just use WSH to do the job?

Do you want to feed the shortcut to your script on the comandline?

--TheDoctor
0
 
JofnnAuthor Commented:
Hi,

Yes - must be batch as the program/script we're amending is in batch.

The program/script currently loads and has a hardcoded link to an INI file, which is where it gets all it's relevant options.  Problem is - the batch file is converted to EXE everytime that it is updated... To save us having to do this, we would rather add the INI location into the shortcut that the users use... the batch should then read that, set the variable, and read it like it currently does.

Does that make sense?
0
 
JofnnAuthor Commented:
To clarify -

If we move the INI file for any reason (i.e. to an alternate server, or onto a non-networked standalone PC) we need to change the INI variable within the program so it continues to get it's settings.

But rather than re-compile each time, we would have the INI location in the target path (which we could change whenever we wanted without recompiling).  The script would set the variable dependant on what is in the target path next to "INIFILE="
0
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 
Bill PrewCommented:
Why not just run it like this:

"C:\progra~1\applic~1\folder\file.exe" "\\server\share\folder\file.ini"

and then in the BAT file grab the value of the first parm like this:

if "%~1" NEQ "" (
  set IniFile=%~1
) else (
  set IniFile=\\server\share\folder\file.ini
)

This will assign the path to the IniFile variable if it is passed in on the command line, or default it to some value if it isn't passed in.

~bp
0
 
JofnnAuthor Commented:
Bill,

Thanks for that...

That would be a good idea, but the program is compiled as an exe and all the user should have to do is click on the icon and it works... Therefore, best option I can think of, is controlling this in the target path...

Jonathon
0
 
Bill PrewCommented:
Sorry, don't mean to be dense, but when you said:

==> Problem is - the batch file is converted to EXE everytime that it is updated... To save us having to do
==> this, we would rather add the INI location into the shortcut that the users use... the batch should then
==> read that, set the variable, and read it like it currently does.

I took this to mean that you were using a tool to compile your BAT file into this EXE, which was then run.  Is that not the case?  If it is the case, then why can't the logic I proposed be added to the BAT file being compiled?

Sorry if I'm missing the obvious.

~bp
0
 
JofnnAuthor Commented:
Bill,

Could be my poor explaining:

We have a .bat file which is compiled into EXE which our users use.  If we move the INI file or it needs to point to a different ini file, we have to edit and recompile the EXE each time...

So - within the bat there is a line that says:

INI_FILE=\\server\share\folder1\file1.ini

Some users may not need the settings that are in that INI file and they may need file3.ini from the folder2 folder... we would have to edit this line in the batch script and then recompile it...

---------------------------------
What I'm aiming for, is for the users to not need to call IT anymore to request a change to the file it reads (which could also change location at any point)... Therefore if they could just edit the properties of the file target, this could be picked up by the EXE (or compiled batch... ) and it will run ok!

The users should never have to open command prompt or anything like that to pass the 2nd variable through as you advised above.

Hope that makes a little more sense!!
0
 
balasundaram_sCommented:
Can you try like this:

"C:\progra~1\applic~1\folder\file.exe" inifile=file:\\server\share\folder\file.ini
0
 
JofnnAuthor Commented:
Balasundaram_S,

Thanks... as explained in my part to BP - I'm looking for that to be in the Target Path of the relevant shortcut that the users will be using.  The script should then extract the INI section and set the variable accordingly.

(Therefore the user will get the correct settings dependant on the INI file)
0
 
Bill PrewCommented:
==> Jofnn

Okay, it sounds like I did understand originally, so now help me understand how adding the logic I mentioned to your BAT file doesn't work for you?  I think it is what you are looking for, the BAT file can pick up the name of the ini file from the command line in the shortcut properties and set the internal variable for the BAT file to use.

I think we're close...

~bp
0
 
JofnnAuthor Commented:
Bill - complete misunderstanding on my part!!!

I read your previous comments as adding it to the command line (i.e. launching command prompt... typing the path to the EXE and then the INI)...   We appeared to be calling "command line" and "target path" different things, when we both meant the exact same thing!

To summarise - I've tested and it works perfectly!!!

Thanks very much (again)
0
 
Bill PrewCommented:
Ah, great, glad to know I wasn't completely off, glad that was useful.

~bp
0
 
JofnnAuthor Commented:
exactly what I was looking for :o)

thanks again!
0

Featured Post

Independent Software Vendors: 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!

Tackle projects and never again get stuck behind a technical roadblock.
Join Now