簡體   English   中英

將程序移動到某個位置

[英]Moving Program to A Location

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

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

謝謝,

奧迪努爾夫

以下代碼將在“開始”菜單中創建正在運行的應用程序的快捷方式(您將需要必要的權限才能執行此操作):

首先,添加參考 -> COM 選項卡 -> Windows 腳本宿主 Object ZA559B87068921EEC05ZE086CE578

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

您不能移動、重命名或刪除當前正在使用的進程。 因此,當您運行程序時,您不能移動它,而是必須創建某種bootstrapper

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM