[源码]VB6.0操作注册表

VB6.0操作注册表

本文将介绍用CreateObject(“wscript.shell”)对象操作注册表

本文操作的注册表目录是HKEY_CLASSES_ROOT\Directory\Background\shell
也就是桌面菜单右键

下面看一下效果图:
在这里插入图片描述

其中python 注册表 重载文件资源管理器都是我自己添加的,在桌面右键菜单就可以直接打开,十分方便

下面我们来看一下自己动手怎么实现:

在这里插入图片描述
在注册表里面是这个样子,这里显示的是名字。

在这里插入图片描述
这里看到是ico文件的设置,也就是图标

在这里插入图片描述
这里看到的就是点击的时候执行的命令,可以是一个路径,也可以是一条指令。

接下来我们用Vb6.0实现添加注册表的功能

Dim WSH
Set WSH = CreateObject("WSCRIPT.SHELL")
WSH.RegWrite "HKEY_CLASSES_ROOT\Directory\Background\shell\test\test", "test"        '写入注册表

运行完后是这样的:

在这里插入图片描述
下面这个代码可以加入python到右键菜单中

Dim WSH
Set WSH = CreateObject("WSCRIPT.SHELL")
WSH.RegWrite "D:\python\python.exe","D:\python\python.exe" 

测试效果:

在这里插入图片描述
在这里插入图片描述
其实挺方便的。
其实还可以做一个界面让用户自己输入自己想要运行的程序,代码如下:

Private Sub Command_openfile1_Click()
CommonDialog_exe.FileName = ""
CommonDialog_exe.Filter = "可执行应用程序(*.exe)|*.exe"
CommonDialog_exe.FilterIndex = 2
CommonDialog_exe.DialogTitle = "选择可执行应用程序(*.exe)"
CommonDialog_exe.ShowOpen
If CommonDialog_exe.FileName = "" Then
    a = "Nnothing"
Else
    Text_command.Text = CommonDialog_exe.FileName
End If
End Sub


Private Sub Command_openfile2_Click()
CommonDialog_exe.FileName = ""
CommonDialog_exe.Filter = "应用程序或图标文件(*.exe;*.ico)|*.exe;*.ico)"
CommonDialog_exe.FilterIndex = 2
CommonDialog_exe.DialogTitle = "选择图标(*.ico,*.exe)"
CommonDialog_exe.ShowOpen
If CommonDialog_exe.FileName = "" Then
    a = "Nnothing"
Else
    Text_ico.Text = CommonDialog_exe.FileName
End If
End Sub

Private Sub Command_run_Click()
Set WSH = CreateObject("wscript.shell")
reg_name_ico = "HKEY_CLASSES_ROOT\Directory\Background\shell\" + Text_name.Text + "\icon"
If Text_ico.Text = "" Then
    
WSH.RegWrite reg_name_ico, Text_ico.Text

reg_name = "HKEY_CLASSES_ROOT\Directory\Background\shell\" + Text_name.Text + "\command\"
reg_command = Text_command.Text
WSH.RegWrite reg_name, reg_command
MsgBox "添加成功"
End Sub

Private Sub Text_name_Change()
Text1.Text = "HKEY_CLASSES_ROOT\Directory\Background\shell\" + Text_name.Text + "\command\"
End Sub

下面是程序里各个控件名称:
在这里插入图片描述
测试:

在这里插入图片描述
十分的方便和快捷,点个赞吧,程序和源码如下:

本程序在Windows7系统下测试,Windows10系统注册表好像有变化,但修改的代码不会有变,可自行设计。

https://download.csdn.net/download/qq_28406527/20234916?spm=1001.2014.3001.5503

  • 6
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

某新手

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值