' 函数名 :OptionRun ' 函数功能:将传入的文件设置为自启动程序 ' 传入参数:要设置的可执行文件 ' 返回值 :True:设置成功,False:设置失败 ' 制作人 :zzz ' 制作日期:2007-04-10 ' 说 明 :此函数需要有Microsoft.Win32的引用 Public Function OptionRun() Function OptionRun(ByVal sFileName As String) As Boolean '设置自启动程序 If sFileName.Substring(sFileName.Length - 3, 3) = "exe" Or sFileName.Substring(sFileName.Length - 3, 3) = "EXE" Then MessageBox.Show("请首先浏览程序文件选择一个执行程序!", "信息提示", MessageBoxButtons.OK, MessageBoxIcon.Information) Return False End If Try Dim FileName As String = sFileName Dim ShortFileName As String = FileName.Substring(FileName.LastIndexOf("/") + 1) '打开子键节点 Dim MyReg As RegisTryKey = RegisTry.LocalMachine.OpenSubKey("SOFTWARE/Microsoft/Windows/CurrentVersion/Run", True) If MyReg Is Nothing Then '如果子键节点不存在,则创建之 MyReg = RegisTry.LocalMachine.CreateSubKey("SOFTWARE/Microsoft/Windows/CurrentVersion/Run") End If '在注册表中设置自启动程序 MyReg.SetValue(ShortFileName, FileName) Return True Catch e As Exception Throw New Exception("Error in OptionRun!" & vbCrLf & _ "Source:" & e.Source + " Message:" + e.Message) Return False End Try End Function