Startup script to register DLLs?


Author
Message
JK
JK
Master
Master (1.8K reputation)Master (1.8K reputation)Master (1.8K reputation)Master (1.8K reputation)Master (1.8K reputation)Master (1.8K reputation)Master (1.8K reputation)Master (1.8K reputation)Master (1.8K reputation)Master (1.8K reputation)
Group: Forum Members
Posts: 1.2K, Visits: 4.4K
I frequently find that the Explorer shell extensions (e.g., column headers for Backup Type and Backup Comment) randomly disappear.  Following the instructions in the KnowledgeBase article, I can fix this by executing the following in an elevated command prompt:

cd "C:\Program Files\Macrium\Reflect"
regsvr32 RContextMenu.dll
regsvr32 RShellEx.dll


Because this happens with sufficient frequency to be annoying, I would like to add the above commands to a .bat file that I already have scheduled to run on each logon.  However, I don't know if it's necessary to use the cd command, or if I can simply add the full path to each dll file name when I call regsvr32.  In addition, I would like to disable the pop-up confirmation dialog.  Thus, would the following work?

regsvr32 /s "C:\Program Files\Macrium\Reflect\RContextMenu.dll"
regsvr32 /s "C:\Program Files\Macrium\Reflect\RShellEx.dll"


Is there a better way?

Also, I believe that the above won't take effect until the next time I reboot (or sign & out sign in).  Is there a way around that?  Could I just kill and restart the explorer.exe process, and if so, what additional commands could be added to the batch file to make this happen?

                                
L. W. "Dan" Danz
L. W. "Dan" Danz
Guru
Guru (1.3K reputation)Guru (1.3K reputation)Guru (1.3K reputation)Guru (1.3K reputation)Guru (1.3K reputation)Guru (1.3K reputation)Guru (1.3K reputation)Guru (1.3K reputation)Guru (1.3K reputation)Guru (1.3K reputation)
Group: Forum Members
Posts: 582, Visits: 6.2K
SWAG -- these property sheet handlers (?? proper name??) could very well be the cause of the crashes of File Explorer for the user who tried to run v8.0 with Windows XP.  From your testing it looks like using regsvr32 /u to remove them might not work as a diagnostic step. 

I've been following your travails with Connect Standby with much interest.   I have one HP laptop that I've been able to hack and finally got 02:00 backups to stay running long enough to do the backup.  The other HP laptop wakes up at 02:00 but repeatedly dies in a short time after starting the actual writing (i.e., just past the Looking For Changes actions).  So, today I'm going to look at some of the changes you've made.   One thing I do that you haven't is:  a) use MTS, bSmile generate a powershell script with no changes, just so I can use the MTS scheduler option that prevents sleeping while the script is running.   It doesn't seem to work, though. 


 L W "Dan" Danz, Overland Park KS 
MR v8.0.6786+    Win10.21H2-19044.1889+    Win11.21H2-22000.856+




JK
JK
Master
Master (1.8K reputation)Master (1.8K reputation)Master (1.8K reputation)Master (1.8K reputation)Master (1.8K reputation)Master (1.8K reputation)Master (1.8K reputation)Master (1.8K reputation)Master (1.8K reputation)Master (1.8K reputation)
Group: Forum Members
Posts: 1.2K, Visits: 4.4K
"property sheet handlers" ... are you referring to the two DLLs mentioned in my OP?

"MTS" = Macrium Task Scheduler?  Is this not used by default when scheduling backup tasks?

I had preferred to do some testing (by temporarily removing the DLLs -- but I'm still awaiting assistance with how to best do that) before floating the following theory, but something in my system has caused a serious instability in explorer.exe.  The symptom is that when terminating the explorer process and restarting it in Task manager, the system enters a crash loop in which explorer.exe repeatedly crashes and respawns itself until I Ctrl-Alt-Delete. I only have two "non-standard" apps that are allowed explorer integrations (Reflect and TortoiseCVS), so it's not out of the question that Reflect is to blame (and if so, that the culprit is one or both of the above named DLLs).

I did find some suitable commands that would allow the explorer process to be killed and restarted in a batch file (which was one of my OP requests in this thread), but I don't want to attempt it until I am able to resolve the instability that is triggered when I restart explorer manually.

                                
L. W. "Dan" Danz
L. W. "Dan" Danz
Guru
Guru (1.3K reputation)Guru (1.3K reputation)Guru (1.3K reputation)Guru (1.3K reputation)Guru (1.3K reputation)Guru (1.3K reputation)Guru (1.3K reputation)Guru (1.3K reputation)Guru (1.3K reputation)Guru (1.3K reputation)
Group: Forum Members
Posts: 582, Visits: 6.2K
JK - 18 January 2022 8:32 PM
"property sheet handlers" ... are you referring to the two DLLs mentioned in my OP?

"MTS" = Macrium Task Scheduler?  Is this not used by default when scheduling backup tasks?

I had preferred to do some testing (by temporarily removing the DLLs -- but I'm still awaiting assistance with how to best do that) before floating the following theory, but something in my system has caused a serious instability in explorer.exe.  The symptom is that when terminating the explorer process and restarting it in Task manager, the system enters a crash loop in which explorer.exe repeatedly crashes and respawns itself until I Ctrl-Alt-Delete. I only have two "non-standard" apps that are allowed explorer integrations (Reflect and TortoiseCVS), so it's not out of the question that Reflect is to blame (and if so, that the culprit is one or both of the above named DLLs).

I did find some suitable commands that would allow the explorer process to be killed and restarted in a batch file (which was one of my OP requests in this thread), but I don't want to attempt it until I am able to resolve the instability that is triggered when I restart explorer manually.

Yes, the two shell extensions. 
MTS might be default or not. I don't care.    It can be switched to WTS and vice versa.  MTS has an extra option that WTS does not have.

 L W "Dan" Danz, Overland Park KS 
MR v8.0.6786+    Win10.21H2-19044.1889+    Win11.21H2-22000.856+




Cy “kkm” K'Nelson
Cy “kkm” K'Nelson
New Member
New Member (28 reputation)New Member (28 reputation)New Member (28 reputation)New Member (28 reputation)New Member (28 reputation)New Member (28 reputation)New Member (28 reputation)New Member (28 reputation)New Member (28 reputation)New Member (28 reputation)
Group: Forum Members
Posts: 22, Visits: 109
JK - 17 January 2022 8:27 PM


Also, I believe that the above won't take effect until the next time I reboot (or sign & out sign in). Is there a way around that? Could I just kill and restart the explorer.exe process, and if so, what additional commands could be added to the batch file to make this happen?


Correct, rudely killing and restarting explorer.exe is enough. The commands are

taskkill /f /im explorer.exe
explorer

if you find that explorer takes to long to die so that the second 'explorer' command doesn't start a new one, a delay is needed between the two. The old Windows hack for a delay of 1s is

ping localhost -n 2 >NUL

(in general, the integer argument to -n should be K+1 for K seconds).

In PowerShell, sleep is an alias to I do not remember what sleep applet, and can be called as 'sleep N' for N seconds or 'sleep -milli N' for N milliseconds.

Windows 10 can restart a process more gracefully, but I do not know how to do that from command line. It loses all open windows in Explorer in either case, so the end result is still the same.

P.S. I probably misunderstood your problem when I recommended Autoruns in the other response (it's for hiding menu entries, not adding them). Still a useful tool. :-)





JK
JK
Master
Master (1.8K reputation)Master (1.8K reputation)Master (1.8K reputation)Master (1.8K reputation)Master (1.8K reputation)Master (1.8K reputation)Master (1.8K reputation)Master (1.8K reputation)Master (1.8K reputation)Master (1.8K reputation)
Group: Forum Members
Posts: 1.2K, Visits: 4.4K
@kkm
Through the magic of Google, I had found the following commands previously:
taskkill /f /IM explorer.exe
start explorer.exe

Not sure if there is a benefit to using start vs just calling explorer directly, as you had proposed, and I appreciate the tip about the delay.

However, I never proceeded with testing this script, because when I did a dry run by manually killing and restarting explorer.exe, it triggered a nasty infinite loop of explorer crashes.  No point in automating this instability!

That was the impetus for my other thread -- I wanted to temporarily uninstall or disable RContextMenu.dll and RShellEx.dll, to see if that would fix the instability.

Another question related to this script (assuming I can fix the explorer instability) is how to terminate it.  Based on imitating other unrelated batch scripts, I thought I might add something like the following to the end of the .bat:
if ERRORLEVEL 1 pause > nul
exit

However, I don't really know what I'm doing here, so if these extra lines of code are not advisable (or if there is a better alternative), any pointers or suggestions would be appreciated.

                                
Cy “kkm” K'Nelson
Cy “kkm” K'Nelson
New Member
New Member (28 reputation)New Member (28 reputation)New Member (28 reputation)New Member (28 reputation)New Member (28 reputation)New Member (28 reputation)New Member (28 reputation)New Member (28 reputation)New Member (28 reputation)New Member (28 reputation)
Group: Forum Members
Posts: 22, Visits: 109
Immediately after regsvr32?

The script fragment is not stellar. The first line checks if a command above it failed (the construct is ancient, comes from DOS, and implicitly means error code 1 or greater; any non-zero exit code indicates a failure), and if it did, runs the pause command. Normally this command prints "Press any key to continue . . ." and waits for a key press, but the redirect to NUL eats the message, so the command waits for any keypress silently, without any indication that it is waiting for input. This looks like a surprising behavior to me. In a cmd prompt, try both 'pause' and 'pause > nul' to see the difference. Perhaps, someone wrote the redirect to nul relying on the previous command having printed an error message to console, but, IIRC, regsvr32 never prints anything. It displays a message box instead, or, with the '/s' switch, nothing.

'exit' will close cmd.exe (after a message-less pause has been responded to by the user in case previous command failed, or without invoking 'pause' if it succeeded). It might be a very bad idea in scripting, as if the script was invoked by another .BAT script, the rest of that calling script won't be executed. It may be used intentionally to abort the whole stack of scripts this way, in case they are never called by the user from cmd.exe windows (it will close the window, which is a nasty user experience), but usually in the form 'exit 1', to return a failure exit code to the program that invoked the script. Terminating your calling scripts and returning 0 indicating success is a weird behavior.

Despite the language of .BAT being rather esoteric, I would not imagine circumstances that would prompt me to write such a fragment.

Besides, there is nothing much to check for success. taskkill will fail if explorer.exe was not running, but that could hardly be a case; even if it isn't, you probably want to start it anyway. If explorer start fails, you'll probably notice that, too, without an additional message from the script...

The start command is not required for explorer. It allows more precise behavior control in scripts when used with switches (see 'start /?'), but for a windows program (as opposed to a console program) just 'explorer' and 'start explorer' are equivalent.

JK
JK
Master
Master (1.8K reputation)Master (1.8K reputation)Master (1.8K reputation)Master (1.8K reputation)Master (1.8K reputation)Master (1.8K reputation)Master (1.8K reputation)Master (1.8K reputation)Master (1.8K reputation)Master (1.8K reputation)
Group: Forum Members
Posts: 1.2K, Visits: 4.4K
I had placed the if ERRORLEVEL etc. after the following code block:
@ECHO OFF
ECHO Running reflect_dll_fix.bat ...
regsvr32 /s "C:\Program Files\Macrium\Reflect\RContextMenu.dll"
regsvr32 /s "C:\Program Files\Macrium\Reflect\RShellEx.dll"
taskkill /f /IM explorer.exe
start explorer.exe

Do you suggest simply letting the .bat file end after the last line shown above?  The behavior I would want is to automatically close the cmd window if everything completed without errors or warnings, but to otherwise allow me to see that an error has occurred.

I probably will not call the above script from another script, but I may merge the code into another .bat that is scheduled to run at each logon to perform various tasks.  So I would like to know if any of the commands in the script resulted in an error.


                                
Cy “kkm” K'Nelson
Cy “kkm” K'Nelson
New Member
New Member (28 reputation)New Member (28 reputation)New Member (28 reputation)New Member (28 reputation)New Member (28 reputation)New Member (28 reputation)New Member (28 reputation)New Member (28 reputation)New Member (28 reputation)New Member (28 reputation)
Group: Forum Members
Posts: 22, Visits: 109
Each program returns a status code, but cmd keeps only the last one. So by putting the check after the 'start explorer' line, you check whether explorer has started or not. You will very much notice if it would not start without additional error messages :-) Besides, explorer is a "windows subsystem" program, so the return code is not meaningful: it may start and immediately die for any reason, but windows programs are detached from cmd immediately. Good news is that it usually starts.

I think you wanted to check if regsvr32 was successful or not. I just checked, and regsvr32 in fact returns a meaningful error code, apparently the Windows API error code: 3 when I run 'regsvr32 /s foo', 5 if I run 'regsvr32 /s "C:\Program Files\Macrium\Reflect\RContextMenu.dll" without elevation, and 0 if from an elevated command prompt. 3 stands for ERROR_PATH_NOT_FOUND, 5 for ERROR_ACCESS_DENIED, which kinda makes sense.

No point checking the success/failure of taskkill: if explorer.exe was not running, you probably still want to start it.

I think you want something like this, in the end:

@echo off
setlocal
setlocal enableextensions

set err1=
regsvr32 /s "C:\Program Files\Macrium\Reflect\RContextMenu.dll"
if ERRORLEVEL 1 set err1=regsvr32 failed on RContextMenu.dll with error %ERRORLEVEL%

set err2=
regsvr32 /s "C:\Program Files\Macrium\Reflect\RShellEx.dll"
if ERRORLEVEL 1 set err2=regsvr32 failed on RShellEx.dll with error %ERRORLEVEL%

if NOT DEFINED err1 if NOT DEFINED err2 (
taskkill /f /im explorer.exe >NUL
explorer
exit /b 0
)

: At least one of err1, err2 is defined.
if DEFINED err1 echo %err1%
if DEFINED err2 echo %err2%
pause
exit /b 1

I'm a bit short of time to give a detailed explanation, but you can run 'if /?', 'set /?', 'exit /?' etc for help on cmd internal commands. A variable set to nothing is undefined—I think this is not explicitly spelled in 'set /?' message. '>NUL' redirect after taskkill is because it's quite chatty.

The crappy language does not even have logical operators, so each 'if' can test only one condition. And quoting arguments is a sheer disaster. PowerShell is better, but not without its own quirks.

Try running the whole thing unelevated (one of the DLLs fails to register with error 5) and elevated (both succeed, explorer restarts).

JK
JK
Master
Master (1.8K reputation)Master (1.8K reputation)Master (1.8K reputation)Master (1.8K reputation)Master (1.8K reputation)Master (1.8K reputation)Master (1.8K reputation)Master (1.8K reputation)Master (1.8K reputation)Master (1.8K reputation)
Group: Forum Members
Posts: 1.2K, Visits: 4.4K
Thank you @kkm !  I will give this a try after I have figured out why restarting explorer causes an infinite crash loop on my system (which I will hopefully be able to do with the help of Autoruns, as you had suggested on my other thread).

I think I understand your whole script except for the two setlocal commands, but I should be able to Google those if you don't have time to explain.

                                
GO

Merge Selected

Merge into selected topic...



Merge into merge target...



Merge into a specific topic ID...




Reading This Topic

Login

Explore
Messages
Mentions
Search