VB重启explorer的模块,执行过程:RestartExplorer

调用方式:
Private Sub Command1_Click()
RestartExplorer
End Sub

以下新建一个模块,放进去即可

 '〓〓〓〓〓〓〓〓〓〓RestartExplorer函数相关定义声明等 Start
  Const sEndProess As String = "explorer.exe" '注意必须小写
  Private Declare Function CreateToolhelp32Snapshot Lib "kernel32" (ByVal dwFlags As Long, ByVal th32ProcessID As Long) As Long
  Private Declare Function Process32First Lib "kernel32" (ByVal hSnapshot As Long, lppe As PROCESSENTRY32) As Long
  Private Declare Function Process32Next Lib "kernel32" (ByVal hSnapshot As Long, lppe As PROCESSENTRY32) As Long
  Private Declare Function CloseHandle Lib "kernel32" (ByVal hObject As Long) As Long
  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 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 * 1024
  End Type
      
  Const TH32CS_SNAPHEAPLIST = &H1
  Const TH32CS_SNAPPROCESS = &H2
  Const TH32CS_SNAPTHREAD = &H4
  Const TH32CS_SNAPMODULE = &H8
  Const TH32CS_SNAPALL = (TH32CS_SNAPHEAPLIST Or TH32CS_SNAPPROCESS Or TH32CS_SNAPTHREAD Or TH32CS_SNAPMODULE)
  Const TH32CS_INHERIT = &H80000000
  Dim pid         As Long
  Dim pname         As String
'〓〓〓〓〓〓〓〓〓〓RestartExplorer函数相关定义声明等 End
'┏〓〓〓〓〓〓〓〓〓 RestartExplorer,start 〓〓〓〓〓〓〓〓〓┓
'[简介]:
'重启Explorer进程
Sub RestartExplorer()
   '[mycode_id:2329],edittime:2013/8/4 3:55:46
   Dim my         As PROCESSENTRY32
   Dim l         As Long
   Dim l1         As Long
   Dim flag         As Boolean
   Dim mName         As String
   Dim i         As Integer
   
   l = CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0)
   If l Then
           my.dwSize = 1060
           If (Process32First(l, my)) Then                 '遍历第一个进程
                   Do
                                               i = InStr(1, my.szExeFile, Chr(0))
                                               mName = LCase(Left(my.szExeFile, i - 1))
                           If LCase(mName) = sEndProess Then
                                               pid = my.th32ProcessID
                                               pname = mName
                                               Dim mProcID         As Long
                                               mProcID = OpenProcess(1&, -1&, pid)
                                           TerminateProcess mProcID, 0&
                                               flag = True
                                               Exit Sub
                               Else
                                               flag = False
                               End If
                   Loop Until (Process32Next(l, my) < 1) '遍历所有进程知道返回值为False
           End If
           l1 = CloseHandle(l)
   End If
   
   Shell "explorer.exe"
End Sub
'┗〓〓〓〓〓〓〓〓〓  RestartExplorer,end  〓〓〓〓〓〓〓〓〓┛



评论 3
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

打赏作者

专注VB编程开发20年

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

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

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

打赏作者

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

抵扣说明:

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

余额充值