| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 834 人关注过本帖
标题:修改注册表设置不重新启动电脑直接生效
只看楼主 加入收藏
weiyi75
Rank: 1
等 级:新手上路
威 望:1
帖 子:43
专家分:0
注 册:2006-9-7
收藏
 问题点数:0 回复次数:2 
修改注册表设置不重新启动电脑直接生效

Winxp总管经常这样问,是否关闭explorer直接生效设置。

一个例子

窗体加入3个按钮,名字看代码就知道

'窗体代码部分

Option Explicit

'打开注册表中的项

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 RegDeleteValue Lib "advapi32.dll" Alias "RegDeleteValueA" (ByVal hKey As Long, ByVal lpValueName As String) As Long

Private Const HKEY_CURRENT_USER = &H80000001
Private Const REG_BINARY As Long = 3
Private Const REG_SZ = 1
Private Const REG_DWORD = 4

Private Sub cmdHideDesktop_Click() '隐藏桌面

Dim hKey As Long

RegOpenKeyEx HKEY_CURRENT_USER, "Software\Microsoft\Windows\CurrentVersion\Policies", 0, 0, hKey
RegCreateKey HKEY_CURRENT_USER, "Software\Microsoft\Windows\CurrentVersion\Policies\Explorer", hKey
RegSetValueEx hKey, "nodesktop", 0, REG_BINARY, &H1, 4

Updatenow

End Sub

Private Sub cmdShowDesktop_Click() '显示桌面

Dim hKey As Long
Dim bArr(0 To 4) As Byte

RegCreateKey HKEY_CURRENT_USER, "Software\Microsoft\Windows\CurrentVersion\Policies\Explorer", hKey
RegDeleteValue hKey, "nodesktop"

Updatenow

End Sub

Private Sub cmdExit_Click()

End

End Sub

模块代码部分

Option Explicit

'获得进程的句柄

Private Declare Function OpenProcess Lib "kernel32" (ByVal dwDesiredAccess As Long, ByVal blnheritHandle As Long, ByVal dwAppProcessId As Long) As Long

'终止进程

Private Declare Function TerminateProcess Lib "kernel32" (ByVal ApphProcess As Long, ByVal uExitCode As Long) As Long

'创建一个系统快照

Private Declare Function CreateToolhelp32Snapshot Lib "kernel32" (ByVal lFlags As Long, lProcessID As Long) As Long

'获得系统快照中的第一个进程的信息

Private Declare Function ProcessFirst Lib "kernel32" Alias "Process32First" (ByVal mSnapShot As Long, uProcess As PROCESSENTRY32) As Long

'获得系统快照中的下一个进程的信息

Private Declare Function ProcessNext Lib "kernel32" Alias "Process32Next" (ByVal mSnapShot As Long, uProcess As PROCESSENTRY32) As Long

Private Declare Sub CloseHandle Lib "kernel32" (ByVal hPass As Long) '关闭句柄

Private Type PROCESSENTRY32 '进程结构信息

dwSize As Long
cntUsage As Long
th32ProcessID As Long
th32DefaultHeapID As Long
th32ModuleID As Long
cntThreads As Long
th32ParentProcessID As Long
pcPriClassBase As Long
dwFlags As Long
szExeFile As String * 260

End Type

Private Const TH32CS_SNAPPROCESS As Long = 2& '快照常量
Private Const PROCESS_ALL_ACCESS = &H1F0FFF 'OpenProcess使用的常量

Dim list3 As Long '要关闭进程的ID
Dim ParentHandle As Long '要关闭进程的句柄

Public Sub Updatenow()

Dim mSnapShot As Long
Dim uProcess As PROCESSENTRY32
Dim ProcessName As String
Dim R As Long
Dim I As Integer

mSnapShot = CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0&)

If mSnapShot = 0 Then Exit Sub

uProcess.dwSize = Len(uProcess)

R = ProcessFirst(mSnapShot, uProcess)

Do While R '开始遍历所有进程

I = InStr(1, uProcess.szExeFile, Chr$(0))

ProcessName = Mid$(LCase$(Left$(uProcess.szExeFile, I - 1)), 1, 50)

If ProcessName = "explorer.exe" Then

list3 = uProcess.th32ProcessID

End If

R = ProcessNext(mSnapShot, uProcess)

Loop

Call CloseHandle(mSnapShot)

ParentHandle = OpenProcess(PROCESS_ALL_ACCESS, True, list3)

Call TerminateProcess(ParentHandle, 0) '杀死explorer.exe重新加载

End Sub

[此贴子已经被作者于2006-9-25 22:11:48编辑过]

搜索更多相关主题的帖子: 注册表 设置 
2006-09-25 22:11
没翅膀的天使猪
Rank: 1
等 级:新手上路
帖 子:16
专家分:0
注 册:2006-9-25
收藏
得分:0 

不错!喜欢!

编过类似的软件吗???

[此贴子已经被作者于2006-9-25 22:41:39编辑过]


【认真过好每一天】
2006-09-25 22:41
weiyi75
Rank: 1
等 级:新手上路
威 望:1
帖 子:43
专家分:0
注 册:2006-9-7
收藏
得分:0 
以下是引用没翅膀的天使猪在2006-9-25 22:41:01的发言:

不错!喜欢!

编过类似的软件吗???



应该不难,会删加注册表的方法,搜集一下或提取这些软件写注册表的值,模仿是不难的。

2006-09-25 22:45
快速回复:修改注册表设置不重新启动电脑直接生效
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.036346 second(s), 7 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved