繁体   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