中国DOS联盟论坛

China DOS Union

-- Unite DOS · Advance DOS · Grow DOS --
Union site: www.cn-dos.net Forum site: www.cn-dos.net/forum
Guest | Log in | Register | Members | Search | China DOS Union
中国DOS联盟论坛
The time now is 2026-08-09 07:03
47,811 topics / 349,895 posts / today 0 new / 48,253 members
DOS批处理 & 脚本技术(批处理室) » Restart "Windows Explorer" → VBS Version
Printable Version  1,445 / 10
Floor1 baomaboy Posted 2007-03-17 12:42
银牌会员 Posts 554 Credits 1,513
Issued at the request of chengbiner, actually there are just two sentences:
To determine whether it is an Nt or 9x system, use respectively:
ntsd -c q -pn Explorer.exe
RUNDLL32 SHELL32.DLL,SHExitWindowsEx -1

It is mostly used to take effect immediately after modifying the registry,
and for easy operation at any time, it is placed in the right-click menu of files and folders.

Attachments
Restare_Explorer.rar (5.12 KiB)
1.GIF (5.38 KiB)
Floor2 lxmxn Posted 2007-03-17 13:23
版主 Posts 4,938 Credits 11,386

The second command, I encountered an error in the command line support, saying that the entry "SHExitWindowsEx" is missing. What's going on?
Floor3 baomaboy Posted 2007-03-17 13:27
银牌会员 Posts 554 Credits 1,513
Originally posted by lxmxn at 2007-3-17 13:23:

  The second command, I got an error in the command line support, saying that the entry "SHExitWindowsEx" is missing. What's going on?


The second command is for WinMe, and the same kernel is estimated to be usable for 98 as well. It has been canceled in XP.
The reason for writing this command is that the Win9x series does not support the first command ntsd (not tested, should be like that)

[ Last edited by baomaboy on 2007-3-17 at 01:28 PM ]
Floor4 lxmxn Posted 2007-03-17 13:32
版主 Posts 4,938 Credits 11,386
Oh, so that's how it is. Is there a similar command under XP?
Floor5 baomaboy Posted 2007-03-17 13:35
银牌会员 Posts 554 Credits 1,513
I couldn't find relevant similar commands. The following can also be used under XP
For Each Process in GetObject("winmgmts:"). _
ExecQuery ("select * from Win32_Process where name='explorer.exe'")
Process.terminate(0)
Next
Floor6 lxmxn Posted 2007-03-17 13:46
版主 Posts 4,938 Credits 11,386

  Well, this VBS for ending processes is good. The following commands can all achieve the effect of ending the explorer.exe process:

1、Wmic process where "name='explorer.exe'" call terminate

2、Taskkill /f /im explorer.exe

3、Ntsk -c q -pn explorer.exe

4、Stop-Process -name explorer (used under Windows PowerShell)
Floor7 baomaboy Posted 2007-03-17 14:04
银牌会员 Posts 554 Credits 1,513
Originally posted by lxmxn at 2007-3-17 13:46:

  Well, this VBS script to end processes is quite good. The following commands can all achieve the effect of ending the explorer.exe process:

1、Wmic process where "name='explorer.exe'" call ...


There are many, bookmarked for later use.
Brother, have you ever encountered a situation where after ending it, explorer.exe cannot be recreated? Only an empty desktop remains, and you have to manually run it in the Task Manager. I don't know if it's because my system is unstable or something else?

Since I don't know the reason, there's no proper solution. I can only add in the code to end the explorer.exe process, wait for 3 seconds, then check if explorer.exe process exists; if it does, exit; if not, recreate it.

The original code didn't add a delay before recreating explorer.exe. Later, I don't know if the system became stable or something else, but every time an extra explorer.exe window would open up ^_^

[ Last edited by baomaboy on 2007-3-17 at 02:15 PM ]
Floor8 baomaboy Posted 2007-04-13 14:05
银牌会员 Posts 554 Credits 1,513
Dim WshSHell,FSO
On Error Resume Next
Set WshSHell = WScript.CreateObject("WScript.Shell")
Set FSO = CreateObject("Scripting.FileSystemObject")
Set WinVer = WshSHell.Environment("Process")
Set Args = WScript.Arguments
CloseTime = 5
FileName = WScript.ScriptName
FileFullName = WScript.ScriptFullName
FilePath = FSO.GetParentFolderName(FileFullName)
InsPath = FSO.GetSpecialFolder(1)
InsFullName = FSO.BuildPath(InsPath ,FileName)
LnkPathNT = WshSHell.SpecialFolders(2)
LnkPath9X = WshSHell.SpecialFolders(14)
LnkPathAll = WshSHell.SpecialFolders("StartMenu")
OtherFileName="PathCopyEx.dll"
OtherFilePath=FSO.GetSpecialFolder(1)
TemFileName = "PathCopyEx.reg"
TemFilePath = FSO.GetSpecialFolder(1)
Copyright="Linglong Technology"
QQ="QQ:25926183"
Email="Email:fty1995@163.com"
InsTitle="Restart Explorer"
InsAnswer="Restart Explorer"
RegPath1="HKEY_CLASSES_ROOT\*\shell\Restare_Explorer\"
RegValue1="Restart Explorer"
RegForm1="REG_SZ"
RegPath2="HKEY_CLASSES_ROOT\*\shell\Restare_Explorer\command\"
RegValue2="wscript.exe "&InsFullName
RegForm2="REG_SZ"
RegPath3="HKEY_CLASSES_ROOT\Directory\shell\Restare_Explorer\"
RegValue3="Restart Explorer"
RegForm3="REG_SZ"
RegPath4="HKEY_CLASSES_ROOT\Directory\shell\Restare_Explorer\command\"
RegValue4="wscript.exe "&InsFullName
RegForm4="REG_SZ"
RegPath9="HKEY_CLASSES_ROOT\Drive\shell\"
RegPath10="HKEY_CLASSES_ROOT\Directory\shell\"
RegValue13="open"
WshSHell.RegWrite RegPath9,RegValue13,RegForm1
WshSHell.RegWrite RegPath10,RegValue13,RegForm1
IF FileFullName <> InsFullName then
intAnswer = MsgBox("【Yes】Add "+ InsAnswer +" to the right-click menu, "&Chr(10)&Chr(10)&"【No】Remove "+ InsAnswer +" from the right-click menu. ", vbQuestion + vbYesNoCancel, "Installation - "+ InsTitle +" - "+ Copyright)
If intAnswer = vbYes Then
WshSHell.RegWrite RegPath1,RegValue1,RegForm1
WshSHell.RegWrite RegPath2,RegValue2,RegForm1
WshSHell.RegWrite RegPath3,RegValue3,RegForm3
WshSHell.RegWrite RegPath4,RegValue4,RegForm4
FSO.GetFile(FileFullName).Copy(InsFullName)
WshSHell.popup _
"Add script file: "+chr(10)+InsFullName+chr(10)+chr(10)+ _
"Add registry entries: "+chr(10)+chr(34)+ RegPath1 +chr(34)+chr(10)+chr(34)+ RegPath3 +chr(34)+chr(10)+ _
chr(10) & CloseTime & " seconds later this window will close automatically!" +chr(10)+chr(10)+ _
chr(10) & "Copyright(C) " + Copyright +" " & QQ &" " + Email _
, CloseTime, "Installation Successful - "+ InsTitle +" - "+ Copyright, 0 + 64
end if
If intAnswer = vbNo Then
WshSHell.RegDelete RegPath4
WshSHell.RegDelete RegPath3
WshSHell.RegDelete RegPath2
WshSHell.RegDelete RegPath1
FSO.DeleteFile InsFullName
WshSHell.popup _
"Delete script file: "+chr(10)+InsFullName+chr(10)+chr(10)+ _
"Delete registry entries: "+chr(10)+chr(34)+ RegPath3 +chr(34)+chr(10)+chr(34)+ RegPath1 +chr(34)+chr(10)+ _
chr(10) & CloseTime & " seconds later this window will close automatically!" +chr(10)+chr(10)+ _
chr(10) & "Copyright(C) " + Copyright +" " & QQ &" " + Email _
, CloseTime, "Uninstallation Successful - "+ InsTitle +" - "+ Copyright, 0 + 64
End If
If intAnswer = vbCancel Then
end if
ELSE
If WinVer("OS") <> "Windows_NT" Then
WshSHell.Run ("RUNDLL32 SHELL32.DLL,SHExitWindowsEx -1"), vbHide
else
For Each Process in GetObject("winmgmts:"). _
ExecQuery ("select * from Win32_Process where name='explorer.exe'")
Process.terminate(0)
Next
WScript.Sleep 3000
for each ps in getobject _
("winmgmts:\\.\root\cimv2:win32_process").instances_
if LCase(ps.name)="explorer.exe" then
Set WshSHell = Nothing
Set FSO = Nothing
Set Args = Nothing
WScript.Quit(0)
exit for
end if
next
WshSHell.Run ("explorer.exe")
end if
End IF
Set WshSHell = Nothing
Set FSO = Nothing
Set Args = Nothing
WScript.Quit(0)
 

[ Last edited by baomaboy on 2008-3-25 at 01:02 AM ]
Floor9 eech Posted 2008-07-21 17:57
高级用户 Posts 346 Credits 906
If you can return to the original directory and call it by right-clicking on the desktop blank, it will be perfect
Floor10 kidzgy Posted 2008-07-23 22:04
中级用户 Posts 129 Credits 262
Originally posted by baomaboy at 2007-3-17 02:04 PM:


There are so many, collected for future use.
Brother, have you ever encountered a situation where explorer.exe cannot be recreated after ending? Only an empty desktop remains, and I have to run it manually through the task manager. I wonder if it's because my system is unstable...


I have also encountered it, but it was under BAT. After I got the VBS from the moderator to start explorer, I didn't have that problem anymore.

If start explorer.exe in the bat does have unstable factors, it should be an issue with CMD itself.

Even if I added many start explorer.exe below, sometimes it wouldn't run.

I think VBS is more stable. So far, I haven't had that unstable problem.

The code to restart explorer.exe is: only two lines in the bat
@taskkill /im explorer.exe /f >nul
@mshta VBScript:CreateObject("WScript.Shell").Run("explorer.exe")(window.close)
Floor11 chengbiner Posted 2008-07-24 03:40
初级用户 Posts 44 Credits 105
Thanks to brother baomaboy. It's been a long time since I came here. I didn't expect to see my name again. Thanks to brother baomaboy once more.
[ Contact the Union admin team - 中国DOS联盟 - Standard version ]
Sponsored by ifanr Inc | © 2001–2023