#

WPF: Application Link in Start-up Folder kopieren unter Windows 10

Aufgabe: ich möchte meine Anwendung automatisch mit Windows 10 Startup starten lassen.
Da ich nicht über die Win32 Registry gehen möchte, möchte ich einen Link der App in den Startup Folder Kopieren.

Lösung: man kann über die InteropServices die Shell ausführen und den Link erstellen.
//--< link erstellen >--
var lnk = shell.CreateShortcut(sShortcut_inStartup);
//</ link erstellen >
try
{
//< link daten einstellen >
lnk.TargetPath = sApp_with_path;
lnk.IconLocation = sApp_with_path + ", 0";
lnk.Description = "ScreenShot To Clipboard";
lnk.Save();
//</ link daten einstellen >
}




Der Link ist dann direkt in dem Startup-Folder. Dieser ist normalerweise ausgeblendet, wenn man den Pfad im Explorer eingibt, wird er sichtbar.


Man muss einen Verweis auf die InteropServices machen:
using System.Runtime.InteropServices; //marshal


hier der Code zum Erstellen. Läuft ganz gut auch unter Windows 10.. wie man oben sieht.


//----< Link in Startup erstellen >----
//--< ermittle App Pfad und Startup >--
string sApp_Name = Application.ResourceAssembly.GetName().Name;
string sStartup_Folder = Environment.GetFolderPath(Environment.SpecialFolder.Startup);
string sShortcut_inStartup = sStartup_Folder + "\\" + sApp_Name + ".lnk";// appref-ms";
string sApp_with_path = Application.ResourceAssembly.Location;
//--</ ermittle App Pfad und Startup >--

//-< Shell starten >--
Type t = Type.GetTypeFromCLSID(new Guid("72C24DD5-D70A-438B-8A42-98424B88AFB8")); //Windows script Host Shell Object
dynamic shell = Activator.CreateInstance(t);
//-</ Shell starten >--

try
{
//--< link erstellen >--
var lnk = shell.CreateShortcut(sShortcut_inStartup);
//</ link erstellen >
try
{
//< link daten einstellen >
lnk.TargetPath = sApp_with_path;
lnk.IconLocation = sApp_with_path + ", 0";
lnk.Description = "ScreenShot To Clipboard";
lnk.Save();
//</ link daten einstellen >
}
finally
{
//< close >
Marshal.FinalReleaseComObject(lnk);
//</ close >
}
//-</ Link erstellen >--
}
finally
{
//< close >
Marshal.FinalReleaseComObject(shell);
//</ close >
}
//----</ Link in Startup erstellen >----

Mobile

.

123movies