0

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

基本的に、(同じアプリケーション内で)実行されたときにVB.NETアプリケーションをStartフォルダーに移動できるようにしたいです。また、別のコンピューターでは開始フォルダーへのパスが設定されていないため、どのコンピューターでも同じフォルダーに移動できるようにしたいと思います。または、開始フォルダーにアプリケーションのショートカットを作成したいだけです

ありがとう、

オディナルフ

4

2 に答える 2

2

次のコードは、スタートメニューに実行中のアプリケーションへのショートカットを作成します(これを行うには、必要な権限が必要です)。

まず、[参照の追加]->[COM]タブ->[WindowsScriptHostオブジェクトモデル]

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
于 2011-07-08T15:23:11.023 に答える
1

現在使用中のプロセスを移動、名前変更、または削除することはできません。したがって、プログラムを実行しているときは、プログラムを移動することはできません。代わりに、ある種のを作成する必要がありますbootstrapper

于 2011-07-08T14:56:32.090 に答える