怎么用vb代码重新建立桌面??
就是要达到下面过程的效果:启动任务管理器==》结束explorer.exe==》应用程序==》新任务==》explorer.exe(这个过程有点繁琐!)想过一下几种途径:
1、建一个bat文件,然后用shell调用==》失败!!
@echo off
taskkill /f /im explorer.exe
start explorer.exe2、直接使用Shell "Explorer.exe", vbNormalFocus  只是打开了一个资源管理器,这是不需要的!!3、Shell "ntsd -c q -pn explorer.exe"在win7系统无法执行。
... ...

解决方案 »

  1.   

    好像需要用CreateProcess API来创建Explorer.exe,
    正确设置STARTUPINFO结构.
      

  2.   

    TerminateProcess API就可以,只要权限足够。
      

  3.   

    我喜欢自动隐藏任务栏,可是有时候卸载U盘时,任务栏无法隐藏了,需要进行如下操作:启动任务管理器==》结束explorer.exe==》应用程序==》新任务==》explorer.exe   才能让任务栏自动隐藏。网上炒了个例子,不成功!!Option Explicit
    Private Type PROCESS_INFORMATION
            hProcess As Long
            hThread As Long
            dwProcessId As Long
            dwThreadId As Long
    End Type
    Private Type STARTUPINFO
            cb As Long
            lpReserved As String
            lpDesktop As String
            lpTitle As String
            dwX As Long
            dwY As Long
            dwXSize As Long
            dwYSize As Long
            dwXCountChars As Long
            dwYCountChars As Long
            dwFillAttribute As Long
            dwFlags As Long
            wShowWindow As Integer
            cbReserved2 As Integer
            lpReserved2 As Long
            hStdInput As Long
            hStdOutput As Long
            hStdError As Long
    End Type
    Private Type SECURITY_ATTRIBUTES
            nLength As Long
            lpSecurityDescriptor As Long
            bInheritHandle As Long
    End Type
    Private Declare Function CreateProcess Lib "kernel32" Alias "CreateProcessA" ( _
      ByVal lpApplicationName As String, _
      ByVal lpCommandLine As String, _
      lpProcessAttributes As SECURITY_ATTRIBUTES, _
      lpThreadAttributes As SECURITY_ATTRIBUTES, _
      ByVal bInheritHandles As Long, _
      ByVal dwCreationFlags As Long, _
      lpEnvironment As Any, _
      ByVal lpCurrentDriectory As String, _
      lpStartupInfo As STARTUPINFO, _
      lpProcessInformation As PROCESS_INFORMATION) As Long
    Private Declare Function WaitForSingleObject Lib "kernel32" (ByVal hHandle As Long, ByVal dwMilliseconds As Long) As Long
    Private Declare Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As Long)
    Private Sub Command1_Click()
      Dim sInfo As STARTUPINFO
      Dim psInfo As PROCESS_INFORMATION
      Dim pAttr As SECURITY_ATTRIBUTES
      Dim tAttr As SECURITY_ATTRIBUTES
      Dim nRet As Long
      Dim nElapse As Integer
      nRet = CreateProcess("C:\Windows\explorer.exe", "", pAttr, tAttr, 0, 0, 0, "c:\", sInfo, psInfo)
      If nRet = 0 Then Exit Sub
      nElapse = 0
      While 1 > 0
        nRet = WaitForSingleObject(psInfo.hProcess, 1000)
        If nRet = 0 Then
          MsgBox "Done!"
          Exit Sub
        End If
        Label1.Caption = CStr(nElapse)
        nElapse = nElapse + 1
        Sleep (1000)
        DoEvents
      Wend
    End Sub
      

  4.   

    你的这个DONE提示一下,又提示一下没有注册类,进程中会多一个EXPLORER.EXE,然后一会又没了
      

  5.   

    用批处理的话看我博客
    http://blog.csdn.net/xiaoyao961/article/details/9740643
      

  6.   

    VB重启explorer的模块,执行过程:RestartExplorer 
    http://blog.csdn.net/xiaoyao961/article/details/9740781
      

  7.   

    不好意思,您的代码 依然只是启动了一个“资源管理器”,桌面并没有恢复!我的系统是win7,账户是管理员级。
      

  8.   

    不可能嘛,我这边都是自动结束当前EXPLORER然后新开一个EXPLORER进程,也没有资源管理器出来的
      

  9.   

    估计是你电脑有问题了,哪里被锁定了,看看这个
    Option Explicit '〓〓〓〓〓〓〓〓〓〓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
      
      
       
    Private Type PROCESS_INFORMATION
            hProcess As Long
            hThread As Long
            dwProcessId As Long
            dwThreadId As Long
    End Type
    Private Type STARTUPINFO
            cb As Long
            lpReserved As String
            lpDesktop As String
            lpTitle As String
            dwX As Long
            dwY As Long
            dwXSize As Long
            dwYSize As Long
            dwXCountChars As Long
            dwYCountChars As Long
            dwFillAttribute As Long
            dwFlags As Long
            wShowWindow As Integer
            cbReserved2 As Integer
            lpReserved2 As Long
            hStdInput As Long
            hStdOutput As Long
            hStdError As Long
    End Type
    Private Type SECURITY_ATTRIBUTES
            nLength As Long
            lpSecurityDescriptor As Long
            bInheritHandle As Long
    End Type
    Private Declare Function CreateProcess Lib "kernel32" Alias "CreateProcessA" ( _
      ByVal lpApplicationName As String, _
      ByVal lpCommandLine As String, _
      lpProcessAttributes As SECURITY_ATTRIBUTES, _
      lpThreadAttributes As SECURITY_ATTRIBUTES, _
      ByVal bInheritHandles As Long, _
      ByVal dwCreationFlags As Long, _
      lpEnvironment As Any, _
      ByVal lpCurrentDriectory As String, _
      lpStartupInfo As STARTUPINFO, _
      lpProcessInformation As PROCESS_INFORMATION) As Long
    Private Declare Function WaitForSingleObject Lib "kernel32" (ByVal hHandle As Long, ByVal dwMilliseconds As Long) As Long
    Private Declare Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As Long)
      Sub OpenExplorer()
      Dim sInfo As STARTUPINFO
      Dim psInfo As PROCESS_INFORMATION
      Dim pAttr As SECURITY_ATTRIBUTES
      Dim tAttr As SECURITY_ATTRIBUTES
      Dim nRet As Long
      Dim nElapse As Integer
      nRet = CreateProcess("C:\Windows\explorer.exe", "", pAttr, tAttr, 0, 0, 0, "c:\", sInfo, psInfo)
      If nRet = 0 Then Exit Sub
      nElapse = 0
      While 1 > 0
        nRet = WaitForSingleObject(psInfo.hProcess, 1000)
        If nRet = 0 Then
          MsgBox "Done!"
          Exit Sub
        End If
     
        nElapse = nElapse + 1
        Sleep (1000)
        DoEvents
      Wend
    End Sub'〓〓〓〓〓〓〓〓〓〓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
       
    OpenExplorer
    End Sub
    '┗〓〓〓〓〓〓〓〓〓  RestartExplorer,end  〓〓〓〓〓〓〓〓〓┛
      

  10.   


    首先对xiaoyao961 说声不好意思。把你的代码编译成exe后再执行,一切ok!!!
    非常感谢!!