Solved

How do you pass arguments to a published application?

Posted on 2008-10-08
19
1,043 Views
Last Modified: 2013-11-26
Very easy yet can't figure a way out of it! With VS2003 I used to make a project for my deployment package. But with VS2008 I am now using the excellent feature of publishing my application. Which everything works fine!

The question is, how can I pass a command line argument to my published application? The problem is that every time I publish my application and is installed on the user's computer the installation path changes since the installation is in his documents and settings folder etc.. Previously the installation path was fixed such as
c:\progra~1\MyApp\Test.exe myProc1
In the above case myProc1 would be the argument/parameter being passed in the application

Any ideas people??
0
Comment
Question by:borgb002
  • 6
  • 4
  • 4
  • +1
19 Comments
 
LVL 55

Expert Comment

by:Jaime Olivares
ID: 22671238
is this data to pass fixed? maybe you can put in a "setting variable" instead.
0
 

Author Comment

by:borgb002
ID: 22671273
no sorry. I could pass different parameter values
0
 
LVL 55

Expert Comment

by:Jaime Olivares
ID: 22671316
I feel maybe changing parameters constantly is not the best solution for you.
if you will pass differente parameters values, how and when do you will change them?
0
 

Author Comment

by:borgb002
ID: 22671384
I want to make automation in my program. a very simple scenario. I use windows scheduler to call my application at 8 AM to send an email and at 9 AM to print a document. (theorical example).
Hence I create two batch files that call my application with their respective parameter
0
 

Author Comment

by:borgb002
ID: 22677064
Come on people, no heroes? With over 50,000 experts having 2.3 million proven solutions and no solution yet :))

Let's put it another way. The real idea is to be able to communicate with another programmer that is using Framework 1.1 and is not able to upgrade to the latest framework (for various reasons beyond the scope of this question). I want him to be able to call my application and send particular commands to be able to call particular functions or routines asynchronously i.e. he does not need to receive any feedback, however if there is a way, it would be nice :)

over to you gurus!
0
 
LVL 55

Expert Comment

by:Jaime Olivares
ID: 22677088
Well, you can know the path of the application at runtime, with:
    System.Windows.Forms.Application.ExecutablePath
So, if you configure your scheduled settings at runtime, you can create the batch files with easy.
0
 

Author Comment

by:borgb002
ID: 22681202
Not possible because the other programmer/developer would not be able to determine the path. As regards the schedules created at runtime it looks a bit messy.. no offense.
0
 
LVL 55

Accepted Solution

by:
Jaime Olivares earned 250 total points
ID: 22681622
Indeed you have a poor control of this because your are using the Publish Wizard, if you need a better control you should create your own Installer application project. But if you want to keep working with the Publish Wizard you will have to use some create trick.

A common used technique also is:
When you start your application for first time, save the application path into a registry entry.
From your scheduling tool, you can read this path.

0
Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

 

Author Comment

by:borgb002
ID: 22826043
Isn't there some other easier way to communicate with my fellow programmer? Rather than using the registry as a common note ........

To recap:
- He is using framework 1.1.  I'm using Framework 3.5 using VS2008
- I'm using the Publish / Click-once technology. Hence the installation path is dynamic
- There must be a way that he could
1) find the path of my application (since it is not in a standardised folder
2) call my application
3) pass parameter(s)
0
 
LVL 38

Expert Comment

by:PaulHews
ID: 22830987
borgb002,

Because of the way ClickOnce applications are deployed and launched, you have limited choices for programmatically starting your application.  Probably the best way would be to use the manifest URL and pass your parameters that way.  This is described here:

http://briannoyes.net/2004/08/10/HarvestingClickOnceCommandLineArguments.aspx
0
 
LVL 83

Expert Comment

by:CodeCruiser
ID: 22830985
Hi,
1) I dont see any reason he could not search for your application in the file system as the name of the exe does not change.
2) Is there any reason you could not publish a DLL for the other programmer to reference in his application?
3) Is it feasible to make your application run online only and allow URL parameters?
0
 
LVL 38

Expert Comment

by:PaulHews
ID: 22831034
>I dont see any reason he could not search for your application in the file system as the name of the exe does not change.

Because multiple versions will be installed as updates are published.

>Is there any reason you could not publish a DLL for the other programmer to reference in his application?

The same problems exist.  You cannot install to GAC using ClickOnce
0
 
LVL 83

Expert Comment

by:CodeCruiser
ID: 22831243
The suggestion you gave is my point 3; to activate the application from the URL with passing parameters to the URL.
0
 
LVL 38

Expert Comment

by:PaulHews
ID: 22831363
>The suggestion you gave is my point 3;

Yes, which is why I didn't comment on your 3rd point, although the link I gave describes it in a lot more detail.
0
 

Author Comment

by:borgb002
ID: 22834767
PaulHews ->  I'll have a look at your link and study it into detail

CodeCruiser:
          1) I dont see any reason he could not search for your application in the file system as the name of the exe does not change.
Right, the exe doesn't change but the running path changes for every publish :(  [this is my biggest prob!]

2) Is there any reason you could not publish a DLL for the other programmer to reference in his application?
Nope the DLL in framework 3.5 didnt work well with 1.1 Have tried it and VS2003 didnt recognise it as a "valid DLL".

3) Is it feasible to make your application run online only and allow URL parameters

I think this is similar to what PaulHews said.... But didn't know that the application can be made "online" ?   What would happen to those offline users working on a laptop? can they then use my application without a network.?
0
 
LVL 38

Assisted Solution

by:PaulHews
PaulHews earned 250 total points
ID: 22835205
>What would happen to those offline users working on a laptop? can they then use my application without a network.?

If you look at your clickonce settings you should see something like this picture.  If you have "Offline as well" selected, then your users will be able to launch your program from the start menu using the installed shortcut.  But while offline, your command line parameters will not be able to be passed via the URL, so your scheduled tasks may fail (if that's how you set them up.)  Even if you figured out the path and created scheduled tasks for your app, when there's an update, all those tasks would be invalid anyway.

ClickOnce has it's uses, but it's also very limited, as Jaime pointed out before.  Given the complications you face, you may want to create a proper setup package or use one of the variations Jaime suggested above.  




Image2.jpg
0

Featured Post

Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

Join & Write a Comment

Suggested Solutions

Microsoft Office Picture Manager was included in Office 2003, 2007, and 2010, but not in Office 2013. Users had hopes that it would be in Office 2016/Office 365, but it is not. Fortunately, the same zero-cost technique that works to install it with …
PaperPort has a feature called the "Send To Bar". It provides a convenient, drag-and-drop interface for using other installed software, such as Microsoft Office. However, this article shows that the latest Office 2016 apps (installed with an Office …
This video shows where to find templates, what they are used for, and how to create and save a custom template using Microsoft Word.
The viewer will learn how to use a discrete random variable to simulate the return on an investment over a period of years, create a Monte Carlo simulation using the discrete random variable, and create a graph to represent the possible returns over…

760 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

18 Experts available now in Live!

Get 1:1 Help Now