启动文件夹中的快捷方式未加载 Visual Basic 应用程序的正确设置

发布于 2024-12-15 18:53:11 字数 911 浏览 3 评论 0原文

最近,我开始使用 Microsoft Visual Basic 2010 Express,并创建一个将 URL 加载到浏览器组件中的应用程序。

用户可以配置的设置之一是“Windows 启动时启动应用程序”。当选中此复选框并且用户保存其首选项时,我会在 microsoft 启动文件夹中创建一个快捷方式,以便在 Windows 启动时运行该应用程序。

我使用以下代码执行此操作:

My.Computer.Registry.LocalMachine.OpenSubKey("SOFTWARE\Microsoft\Windows\CurrentVersion\Run", True).SetValue(Application.ProductName, Application.ExecutablePath)
Dim startup As String = Environment.GetFolderPath(Environment.SpecialFolder.Startup)
IO.File.Copy(Application.ExecutablePath, startup & "\ApplicationName.exe")

问题是,当我使用 Visual Basic 安装时位于桌面或开始菜单程序文件夹上的快捷方式时,它会加载用户定义的设置。但是,当运行启动文件夹中的快捷方式时,它会加载一个完全“新”的应用程序,所有设置均为默认设置。

有人知道我可能做错了什么吗?我在互联网上进行了大量搜索,还查看了 StackOverflow 主题,例如 将应用程序快捷方式复制到启动文件夹 VB (这对我不起作用)

任何帮助将不胜感激。如果您需要更多信息,请询问,我会尽快查找。

Just recently I've started with Microsoft Visual Basic 2010 Express and I am creating an application which loads a URL into the browser component.

One of the settings that the user is able to configure is to 'start the app when windows launches'. When this checkbox is checked and the user saves his preferences I create a shortcut in the microsoft startup folder so the application is ran when windows starts up.

I do so using the following code:

My.Computer.Registry.LocalMachine.OpenSubKey("SOFTWARE\Microsoft\Windows\CurrentVersion\Run", True).SetValue(Application.ProductName, Application.ExecutablePath)
Dim startup As String = Environment.GetFolderPath(Environment.SpecialFolder.Startup)
IO.File.Copy(Application.ExecutablePath, startup & "\ApplicationName.exe")

The problem is, than when I use the the shortcut that Visual Basic makes on install, located on the desktop or start menu programfolder, it loads the settings defined by the user. But when the shortcut from the startup folder is ran, it loads a completely 'new' application sort of, with all the settings on default.

Anybody that knows what I might be doing wrong? I've searched the internet alot and also looked on StackOverflow topics like copying app shortcut to startup folder VB (which didn't work for me)

Any help would be highly appreciated. If you need more info, please ask and I'll look it up asap.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

北方。的韩爷 2024-12-22 18:53:11

您不是在创建快捷方式,而是将可执行文件复制到启动文件夹!
这个复制的可执行文件不会在它附近找到配置文件,因此它将创建一个新的!这就是为什么它显示默认值..
要创建快捷方式,请从项目 -> 引用 -> 添加...的“COM”选项卡导入“Windows 脚本宿主对象模型”

Dim oShell As IWshRuntimeLibrary.WshShell
Dim oShortCut As IWshRuntimeLibrary.WshShortcut

oShell = New IWshRuntimeLibrary.WshShell
oShortCut = oShell.CreateShortcut(Environment.GetFolderPath(Environment.SpecialFolder.Startup) & _
                                                    "\" & GetFileName(Application.ExecutablePath) & ".lnk")
Dim s = Environment.GetFolderPath(Environment.SpecialFolder.Startup)
With oShortCut
    .TargetPath = Application.ExecutablePath
    .Arguments = ""
    .WorkingDirectory = GetDirectoryName(Application.ExecutablePath)
End With
oShortCut.Save()
oShortCut = Nothing : oShell = Nothing

you are not creating a shortcut, you are copying the executable file to the startup folder !!
this copied executable won't find a config file near it so it will create a new one ! that's why it shows default values ..
to make a shortcut import the "Windows Script Host object model" from the "COM" tab in project->refrences->add...

Dim oShell As IWshRuntimeLibrary.WshShell
Dim oShortCut As IWshRuntimeLibrary.WshShortcut

oShell = New IWshRuntimeLibrary.WshShell
oShortCut = oShell.CreateShortcut(Environment.GetFolderPath(Environment.SpecialFolder.Startup) & _
                                                    "\" & GetFileName(Application.ExecutablePath) & ".lnk")
Dim s = Environment.GetFolderPath(Environment.SpecialFolder.Startup)
With oShortCut
    .TargetPath = Application.ExecutablePath
    .Arguments = ""
    .WorkingDirectory = GetDirectoryName(Application.ExecutablePath)
End With
oShortCut.Save()
oShortCut = Nothing : oShell = Nothing
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文