China DOS Union

-- Unite DOS · Advance DOS · Grow DOS --

Union site: www.cn-dos.net Forum site: www.cn-dos.net/forum
DOS stands for freedom, openness and progress. Let us work hard, learn from the openness and GNU spirit of FreeDOS and Linux, and together build and grow a free GNU GPL world!

中国DOS联盟论坛
The time now is 2026-08-09 05:53
中国DOS联盟论坛 » DOS批处理 & 脚本技术(批处理室) » Restart "Windows Explorer" → VBS Version View 1,443 Replies 10
Original Poster Posted 2007-03-17 12:42 ·  中国 河北 保定 联通
银牌会员
★★★
Credits 1,513
Posts 554
Joined 2005-12-30 00:50
20-year member
UID 48180
Gender Male
Status Offline
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.
Recent Ratings for This Post ( 1 in total) Click for details
RaterScoreTime
chengbiner +2 2008-07-24 03:53
Attachments
Restare_Explorer.rar (5.12 KiB, Downloads: 69)
1.GIF
Floor 2 Posted 2007-03-17 13:23 ·  中国 湖北 武汉 电信
版主
★★★★★
Credits 11,386
Posts 4,938
Joined 2006-07-23 17:10
20-year member
UID 59080
Status Offline

The second command, I encountered an error in the command line support, saying that the entry "SHExitWindowsEx" is missing. What's going on?
Floor 3 Posted 2007-03-17 13:27 ·  中国 河北 保定 联通
银牌会员
★★★
Credits 1,513
Posts 554
Joined 2005-12-30 00:50
20-year member
UID 48180
Gender Male
Status Offline
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 ]
Floor 4 Posted 2007-03-17 13:32 ·  中国 湖北 武汉 电信
版主
★★★★★
Credits 11,386
Posts 4,938
Joined 2006-07-23 17:10
20-year member
UID 59080
Status Offline
Oh, so that's how it is. Is there a similar command under XP?
Floor 5 Posted 2007-03-17 13:35 ·  中国 河北 保定 联通
银牌会员
★★★
Credits 1,513
Posts 554
Joined 2005-12-30 00:50
20-year member
UID 48180
Gender Male
Status Offline
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
Floor 6 Posted 2007-03-17 13:46 ·  中国 湖北 武汉 电信
版主
★★★★★
Credits 11,386
Posts 4,938
Joined 2006-07-23 17:10
20-year member
UID 59080
Status Offline

  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)
Floor 7 Posted 2007-03-17 14:04 ·  中国 河北 保定 联通
银牌会员
★★★
Credits 1,513
Posts 554
Joined 2005-12-30 00:50
20-year member
UID 48180
Gender Male
Status Offline
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 ]
Floor 8 Posted 2007-04-13 14:05 ·  中国 河北 保定 联通
银牌会员
★★★
Credits 1,513
Posts 554
Joined 2005-12-30 00:50
20-year member
UID 48180
Gender Male
Status Offline
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 ]
Floor 9 Posted 2008-07-21 17:57 ·  中国 安徽 芜湖 电信
高级用户
★★★
Credits 906
Posts 346
Joined 2006-07-10 09:58
20-year member
UID 58334
Gender Male
Status Offline
If you can return to the original directory and call it by right-clicking on the desktop blank, it will be perfect
Floor 10 Posted 2008-07-23 22:04 ·  中国 广东 梅州 电信
中级用户
★★
Credits 262
Posts 129
Joined 2007-07-11 06:50
19-year member
UID 93679
Gender Male
Status Offline
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)
Floor 11 Posted 2008-07-24 03:40 ·  中国 上海 静安区 电信
初级用户
Credits 105
Posts 44
Joined 2006-10-05 13:57
19-year member
UID 64618
Status Offline
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.
Forum Jump: