2011-07-08 11 views
0

同じファイルでVB.NETを使用しているフォルダにVB.NETアプリケーションを移動するにはどうすればよいですか?場所を移動するプログラム

基本的には、(同じアプリケーション内で)実行されたときに、自分のVB.NETアプリケーションを開始フォルダに移動できるようにします。また、別のコンピュータの「スタート」フォルダへのパスも設定されていないため、どのコンピュータ上の同じフォルダにも移動できるようにしたい。または私はちょうどあなたが、移動、名前変更または現在使用中のプロセスを削除することはできません開始フォルダに

おかげで、

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を作成する必要があります。

関連する問題