如何在同一个文件中使用VB.NET将我的VB.NET应用程序移动到一个文件夹?
基本上,我希望能够在执行时将VB.NET应用程序移动到Start文件夹(在同一个应用程序中)。此外,我希望能够将其移动到任何计算机上的同一文件夹,因为没有设置路径指向不同计算机上的“开始”文件夹。或者我想在开始文件夹
中为我的应用程序创建一个快捷方式谢谢,
Odinulf
答案 0 :(得分: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 :(得分:1)
您无法移动,重命名或删除当前正在使用的流程。因此,当您运行程序时,您无法移动它,而是必须创建某种bootstrapper
。