šŸ“œ ā¬†ļø ā¬‡ļø

On one problem of running Backup and Restore when using OpenSource code from CodeGuru site



I work in technical support, one day I ran into the problem of running Backup or Restore in Windows 7. The user on the computer, when he selected the ā€œBackup or Restoreā€ tab in the Control Panel, stopped working on ā€œSet Backupā€. In order not to look for the tab, you can simply run the program C: \ Windows \ System32 \ sdclt.exe

Finding a solution to the problem through Yandex / Google did not lead to anything. There is a lot of talk about the problem, but no one really knows what is happening, except that they advise you to uninstall CompareIt! or PowerISO , which incorrectly handle embedding in Windows Explorer through the Shell Context Menu. I started to check if there are any similar programs in our case and it turned out that indeed, one useful utility was recently installed that changes the context menu of the Explorer, expanding its capabilities.
')
After uninstalling this program, problems with archiving disappeared. I turned to technical support, they switched me to developers who could not say anything intelligible, except that the utility was written long enough and was not designed to work with Windows 7. In addition, in a private conversation, it turned out that for embedding in the Shell Context Menu was used OpenSource code from the site CodeGuru.

CtxMenu, Copyright 1999, Smaller Animals Software
Charge or restrictions.
This code is provided as-is. If you use this code in any code, any bugs in the code are your responsibility.

What actually happens?

Strangely enough, legs grow exactly from the CodeGuru site, where in 1999 Chris Losinger published his article containing an example of working with ContextMenu, which subsequently spread widely across the expanses of the Internet. I suspect that the above problems CompareIt! and PowerISO are also associated with the use of this code.

Let's take a closer look at the ShellCtxMenu.cpp file, the InvokeCommand function:
STDMETHODIMP CShellExt::InvokeCommand(LPCMINVOKECOMMANDINFO lpcmi) { // //  skipped // HRESULT hr = NOERROR; if (!HIWORD(lpcmi->lpVerb)) { idCmd = LOWORD(lpcmi->lpVerb); // process it switch (idCmd) { default: case 0: // operation 1 case 1: // operation 2 // //  skipped // break; } // switch on command } return hr; } 


It is easy to see that inside switch the processing of the default and other cases is the same, and at the end of the function NOERROR is always returned. It is not right. And where is the return code E_INVALIDARG - it must be used to signal that we have not processed idCmd.

Change the code for this:
 STDMETHODIMP CShellExt::InvokeCommand(LPCMINVOKECOMMANDINFO lpcmi) { // //  skipped // HRESULT hr = E_INVALIDARG; if (!HIWORD(lpcmi->lpVerb)) { idCmd = LOWORD(lpcmi->lpVerb); // process it switch (idCmd) { default: goto err_exit; case 0: // operation 1 case 1: // operation 2 // //  skipped // break; } // switch on command hr = NOERROR; } err_exit: return hr; } 


In this case, return E_INVALIDARG, if this is not our team or NOERROR - if ours and it was processed. After these changes, the Backup or Restore tool began to work correctly.

Recall that the finished CtxMenu.Dll file should be registered by calling the command "regsvr32.exe CtxMenu.Dll" under the Administrator, deinitialization and deletion from the Context Menu Explorer should be performed with the / u key by means of "regsvr32.exe / u CtxMenu.Dll".

I will add that in the English version of Windows 7, the ā€œBackup or Restoreā€ item ā€œConfigure Backupā€ is called ā€œBackup and Restoreā€ and ā€œSet up backupā€, respectively.

Thanks for attention.

Source: https://habr.com/ru/post/133108/


All Articles