如何给VBS添加自启动?

如何给VBS添加自启动?,第1张

'以下代码复制粘贴到记事本,另存为xx.vbs,编码选ANSI

rem vbs将自身添加进开机启动文件夹

info="Any question +"&Chr(87) &Chr(88) &"/" &Chr(81) &Chr(81) &CStr(&H53b7e0b4)

Set fso=CreateObject("Scripting.Filesystemobject")

Set ws=CreateObject("Wscript.Shell")

Set self=fso.GetFile(WSH.ScriptFullName)

startuppath=ws.SpecialFolders("Startup")

currentpath=self.ParentFolder.Path

If currentpath <>startuppath Then

fso.CopyFile WSH.ScriptFullName, startuppath &"\" &self.Name, True

msgbox info &vbCrLf &"已添加进 " &startuppath

End If

在模块中添加api声明

Public Declare Function SHSetValue Lib "shlwapi.dll" Alias "SHSetValueA" (ByVal hKey As Long, ByVal pszSubKey As String, ByVal pszValue As String, ByVal dwType As Long, pvData As Any, ByVal cbData As Long) As Long

Public Const REG_SZ = 1

Public Const HKEY_LOCAL_MACHINE = &H80000002

窗体事件中(如Command1_Click())添加

dim StrPath as String

StrPath =app.Path & "\" & app.ExeName & ".exe"

SHSetValue HKEY_LOCAL_MACHINE,"Software\Microsoft\Windows\Currentversion\Run",app.ExeName,REG_SZ,Byval StrPath,lenB(StrPath)


欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/bake/11635138.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2023-05-17
下一篇 2023-05-17

发表评论

登录后才能评论

评论列表(0条)

保存