问题描述
我的程序在Windows启动时无法正常工作.代码如下:
I have problem with making my program works on windows startup. Here''s the code:
Sub RunAtStartup(ByVal PutAtStartup As Boolean, ByVal Name As String, ByVal Path As String)
Dim StartupPath As String = "Software\Microsoft\Windows\CurrentVersion\Run"
Dim myKey As Microsoft.Win32.RegistryKey
myKey = Microsoft.Win32.Registry.LocalMachine.OpenSubKey(StartupPath, True)
If PutAtStartup = True Then
Try
myKey.SetValue(Name, Path)
Catch ex As Exception
ErrLog &= ex.ToString & vbNewLine
End Try
Else
Try
myKey.DeleteValue(Name, False)
Catch ex As Exception
ErrLog &= ex.ToString & vbNewLine
End Try
End If
End Sub
正如您在程序上方看到的那样,在路径"Software \ Microsoft \ Windows \ CurrentVersion \ Run"上编辑注册表,并将其成功插入路径中.但是问题是我的程序在Windows启动时无法正常工作. s错了吗???
注意:我的操作系统是Windows 7 32位.
As you see above my program edit the registry on path "Software\Microsoft\Windows\CurrentVersion\Run"" and the value it succefully inserted in the path. But the problem is my program dosen''t works on windows startup what''s the wrong?????
Note: my OS is windows 7 32bit.
推荐答案
Imports IWshRuntimeLibrary
3.实现一个功能,该功能在启动目录中创建一个重定向到您的应用程序的快捷方式:
3. Implement a function that creates a shortcut in the startup directory redirecting to your application:
Dim WshShell As WshShellClass = New WshShellClass
Dim MyShortcut As IWshRuntimeLibrary.IWshShortcut
' Shortcut will be created in the startup directory
Dim StartupFolder As String = Environment.GetFolderPath(Environment.SpecialFolder.Startup)
MyShortcut = CType(WshShell.CreateShortcut(StartupFolder & "MyShortcut.lnk"), IWshRuntimeLibrary.IWshShortcut)
' Specify target file full path
MyShortcut.TargetPath = "PATH_TO_YOUR_APP"
MyShortcut.Save()
希望这可以帮助!但是代码未经测试;)
Hope this helps! But code is untested ;)
这篇关于使我的程序在Windows启动时启动的问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!