2017-04-04 3 views
0

はここに私のコードです:プロジェクトのショートカットを作成する方法.exeは同じフォルダにありますか?

 private void button_Click_1(object sender, RoutedEventArgs e) 
    { 
     string link = Environment.GetFolderPath(Environment.SpecialFolder.Desktop) 
      + System.IO.Path.DirectorySeparatorChar + System.Windows.Forms.Application.ProductName + ".lnk"; 
     var shell = new WshShell(); 
     var shortcut = shell.CreateShortcut(link) as IWshShortcut; 
     shortcut.TargetPath = System.Windows.Forms.Application.ExecutablePath; 
     shortcut.WorkingDirectory = System.Windows.Forms.Application.StartupPath; 
     //shortcut... 
     shortcut.Save(); 
    } 

このコードは、デスクトップにショートカットが作成されます...私はショートカットが私のexeファイルが同じフォルダ内に作成することにしたいです。私は他の人がそれを解凍して実行する場所を知らないので、フォルダパスを指定することはできません:(

答えて

0

もちろん、それはあなたがEnvironment.SpecialFolder.Desktopを使用したときに作成すると言いました。あなたはあなたがあなたの代わりにshortcut.WorkingDirectoryに代入している同じ場所を使用する必要がありますか?

どこか別の場所に現れることを期待しています。

private void button_Click_1(object sender, RoutedEventArgs e) 
{ 
    string link = System.Windows.Forms.Application.StartupPath + 
     System.IO.Path.DirectorySeparatorChar + 
     System.Windows.Forms.Application.ProductName + ".lnk"; 
    var shell = new WshShell(); 
    var shortcut = shell.CreateShortcut(link) as IWshShortcut; 
    shortcut.TargetPath = System.Windows.Forms.Application.ExecutablePath; 
    shortcut.WorkingDirectory = System.Windows.Forms.Application.StartupPath; 
    //shortcut... 
    shortcut.Save(); 
} 
関連する問題