2011-07-08 63 views
0

如何將我的VB.NET應用程序移動到同一個文件中使用VB.NET的文件夾?將程序移動到某個位置

實質上,我希望能夠將VB.NET應用程序在執行時(在同一應用程序中)移動到Start文件夾中。另外,我希望能夠將它移動到任何計算機上的相同文件夾,因爲在不同計算機上沒有設置Start文件夾的路徑。或者,我想只需要創建一個快捷方式,我的啓動文件夾中的應用

感謝,

Odinulf

+0

聽起來像你已經有了答案。爲應用程序創建一個快捷方式。完成。 – JohnFx

回答

2

下面的代碼將創建一個快捷方式在開始菜單中運行的應用程序(需要必要的權限,要做到這一點):

首先添加引用 - > COM標籤 - > Windows腳本宿主對象模型

Imports IWshRuntimeLibrary 

Public Function CreateShortcut(ByVal fileName As String, ByVal description As String) As Boolean 
     Try 
      Dim shell As New WshShell 
      'the following is the root of the Start Menu so if you want it in a folder you need to create it 
      Dim ShortcutDir As String = Environment.GetFolderPath(Environment.SpecialFolder.CommonStartMenu) 
      Dim shortCut As IWshRuntimeLibrary.IWshShortcut 

      ' short cut files have a .lnk extension 
      shortCut = CType(shell.CreateShortcut(ShortcutDir & "\" & fileName & ".lnk"), IWshRuntimeLibrary.IWshShortcut) 

      ' set the shortcut properties 
      With shortCut 
       .TargetPath = System.Reflection.Assembly.GetExecutingAssembly.Location() 
       .WindowStyle = 1 
       .Description = description 
       .WorkingDirectory = ShortcutDir 
       ' the next line gets the first Icon from the executing program 
       .IconLocation = System.Reflection.Assembly.GetExecutingAssembly.Location() & ", 0" 

       '.Arguments = "" 
       .Save() 
      End With 
      Return True 
     Catch ex As System.Exception 
      ' add your error handling here 
      Return False 
     End Try 
    End Function 
1

不能移動,重命名或刪除一個過程,是當前正在使用。所以當你運行你的程序時,你不能移動它,相反你必須創建一些bootstrapper

相關問題