Вопрос

I have a WinForms application that accepts a command line argument by calling Environment.GetCommandLineArgs() and does something with it.

It works fine in Debug mode - I enter the argument in the Debug tab of Project Properties, then run it (F5) and the application gets the argument correctly.

But after I publish the application and try to call it from another Winform application with this code line:

Process.Start("\\path\to\myApp\MyApp.application", "4")

it doesn't work. Apparently the argument is not passed to the application for some reason, and I don't know why. I also tried to create a new process and set its ProcessStartInfo.Arguments before starting it, but it still doesn't work.

Can anyone help me?

UPDATE

It seems to me that when Process.Start("\\path\to\etc", "4") is called, what is actually run is the local copy of the program on my machine, located at C:\users\myUserName\AppData\Local\App\2.0\long-string-of-digits-and-letters\MyA‌​pp.exe. If I run Process.Start("C:\users\etc", "4") instead - it works.

Now my question is - why wasn't the argument passed to the local copy of the program when running Process.Start("\\path\to\etc", "4")? What should I do so that the argument is passed to the local copy?

Это было полезно?

Решение

OK, as I wrote in the update of the question, the problem was in the link. Presumably the .application file ran the local .exe file on my machine, but for some reason didn't pass in the argument to it. I had to open directly the local .exe file.

To solve this problem, I added code along these lines (validation/exception handling logic omitted for brevity):

Dim path As String = Environment.GetEnvironmentVariable("LOCALAPPDATA") & "\apps\2.0"
Dim files() As String = Directory.GetFiles(path, "MyApp.exe", IO.SearchOption.AllDirectories)
Process.Start(files(0), "4")

Not an optimal solution (since it assumes that the local .exe file is located in some subfolder of %LOCALAPPDATA%\apps\2.0), but at least it solved my problem...

Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top