The shortcut points at the appref-ms file. If you point it at the exe, it
will not be running as a ClickOnce application.
This is how you create a shortcut on your desktop. Look through this and see
how it creates the .appref-ms shortcut; that's what you want to call.
/// <summary>
/// This will create a Application Reference file on the users desktop
/// if they do not already have one when the program is loaded.
/// Check for them running the deployed version before doing this,
/// so it doesn't kick it when you're running it from Visual Studio.
/// </summary
static void CheckForShortcu t()
{
if
(System.Deploym ent.Application .ApplicationDep loyment.IsNetwo rkDeployed)
{
ApplicationDepl oyment ad = ApplicationDepl oyment.CurrentD eployment;
if (ad.IsFirstRun) //first time user has run the app
{
Assembly code = Assembly.GetExe cutingAssembly( );
string company = string.Empty;
string description = string.Empty;
if (Attribute.IsDe fined(code,
typeof(Assembly CompanyAttribut e)))
{
AssemblyCompany Attribute ascompany =
(AssemblyCompan yAttribute)Attr ibute.GetCustom Attribute(code,
typeof(Assembly CompanyAttribut e));
company = ascompany.Compa ny;
}
if (Attribute.IsDe fined(code,
typeof(Assembly DescriptionAttr ibute)))
{
AssemblyDescrip tionAttribute asdescription =
(AssemblyDescri ptionAttribute) Attribute.GetCu stomAttribute(c ode,
typeof(Assembly DescriptionAttr ibute));
description = asdescription.D escription;
}
if (company != string.Empty && description != string.Empty)
{
string desktopPath = string.Empty;
desktopPath =
string.Concat(E nvironment.GetF olderPath(Envir onment.SpecialF older.Desktop),
"\\", description, ".appref-ms");
string shortcutName = string.Empty;
shortcutName =
string.Concat(E nvironment.GetF olderPath(Envir onment.SpecialF older.Programs) ,
"\\", company, "\\", description, ".appref-ms");
System.IO.File. Copy(shortcutNa me, desktopPath,tru e);
}
}
}
}
Hope this helps.
RobinS.
GoldMail.com
-------------------------------------
"Tim Kelley" <tk*****@compan y.comwrote in message
news:e7******** *****@TK2MSFTNG P02.phx.gbl...
>I have an application that I have distributed using one click install. I
selected the option to allow the program to be run if the server is
offline. From another program I want to be able to check if the first
program is running (easy enough) and start it (not so easy) if it is not
running. The shortcut that is created in the start menu is an application
reference. My question is, how do I replicate the function of the
application reference shortcut in my C# program to start the first program?
Thanks,
Tim