hoda9801

I have a c# console app that I published and installed successfully, but I can't figure out how I pass in my arguments to the exe file after it's been installed. Does anyone know how to do this

Thanks.




Re: Visual C# General Pass arguments into console app

timvw

Open cmd.exe, type appname.exe arg1 "arg2 is something with spaces " arg3, hit enter.. there you go (provided that appname.exe could be found....)





Re: Visual C# General Pass arguments into console app

hoda9801

Thanks for the reply, I would do that if I could find the .exe file. Anyone know where the .exe file is when you publish and install a console app It never asked me where to install the program.




Re: Visual C# General Pass arguments into console app

timvw

Overhere it's in %My Documents and Settings%\Local Settings\Apps\2.0\X\Y\Z (X, Y and Z more or less random strings)


Other options:
- Write a wrapper application (ui that accepts values)
- In the deployment options, check "allow URL parameters to be passed to program.. This way you can access the ActivationUri.

-> references to System.Web and System.Deployment are required:

Code Snippet

static void Main(string[] args)
{
Console.WriteLine("We are at: {0}", Environment.CurrentDirectory);

NameValueCollection nvc = GetQueryStringParameters();

foreach (string key in nvc.Keys)
{
Console.WriteLine("{0}: {1}", key, nvc[key]);
}

Console.WriteLine("you pass in {0} arguments.", args.Length);

Console.Write("{0}Press any key to continue...", Environment.NewLine);
Console.ReadKey();
}

private static NameValueCollection GetQueryStringParameters()
{
NameValueCollection nameValueTable = new NameValueCollection();

if (ApplicationDeployment.IsNetworkDeployed)
{
string queryString = ApplicationDeployment.CurrentDeployment.ActivationUri.Query;
nameValueTable = HttpUtility.ParseQueryString(queryString);
}

return (nameValueTable);
}



And now, instead of clicking on the run button in the publish page, you could browse to http://server/MyClickOnceConsoleApplication/MyClickOnce.application username=jeff to launch the application and you'll see the username=jeff appear...