Go Premium for a chance to win a PS4. Enter to Win

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

How do you pass arguments to a published application?

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
borgb002
Asked:
borgb002
  • 6
  • 4
  • 4
  • +1
2 Solutions
 
Jaime OlivaresCommented:
is this data to pass fixed? maybe you can put in a "setting variable" instead.
0
 
borgb002Author Commented:
no sorry. I could pass different parameter values
0
 
Jaime OlivaresCommented:
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
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
borgb002Author Commented:
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
 
borgb002Author Commented:
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
 
Jaime OlivaresCommented:
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
 
borgb002Author Commented:
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
 
Jaime OlivaresCommented:
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
 
borgb002Author Commented:
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
 
PaulHewsCommented:
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
 
CodeCruiserCommented:
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
 
PaulHewsCommented:
>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
 
CodeCruiserCommented:
The suggestion you gave is my point 3; to activate the application from the URL with passing parameters to the URL.
0
 
PaulHewsCommented:
>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
 
borgb002Author Commented:
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
 
PaulHewsCommented:
>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

Veeam Task Manager for Hyper-V

Task Manager for Hyper-V provides critical information that allows you to monitor Hyper-V performance by displaying real-time views of CPU and memory at the individual VM-level, so you can quickly identify which VMs are using host resources.

  • 6
  • 4
  • 4
  • +1
Tackle projects and never again get stuck behind a technical roadblock.
Join Now