none
Shell32 related code working in Windows 7 but not in Windows 10 RRS feed

  • Question

  • I have the below code. This basically launches the 'system properties' window and tries to remove all tabs from the window apart from the Computer Name tab. This code works seamlessly in windows 7. However, when the same application is launched on windows 10, the code does not seem to work. All the IntPtr have their values returned as 0. And all the tabs are visible.

     using (var exeProcess = new Process())
                    {
                        exeProcess.StartInfo.FileName = "control.exe";
                        exeProcess.StartInfo.Arguments = "sysdm.cpl,,1";
                        exeProcess.Start();
                        exeProcess.WaitForInputIdle();
                        string sLocalizedSystemPropertiesString = null;
                        IntPtr hShellDll = LoadLibrary("Shell32.dll");
                        if (hShellDll != IntPtr.Zero)
                        {
                            StringBuilder sb;
                            int nLength, nSize = 32;
                            do
                            {
                                sb = new StringBuilder(nSize);
                                nLength = LoadString(hShellDll, 0x7A3e, sb, nSize);
                                if (nLength > 0 && nLength < nSize)
                                {
                                    sLocalizedSystemPropertiesString = sb.ToString();
                                    break;
                                }

                                nSize *= 2;
                            }
                            while (nLength > 0);
                            FreeLibrary(hShellDll);

                            IntPtr hWndTarget = FindWindow(null, sLocalizedSystemPropertiesString);
                            IntPtr hWndSysTab = FindWindowEx(hWndTarget, IntPtr.Zero, "SysTabControl32", string.Empty);
                            int nTabCount = SendMessage(hWndSysTab, TCM_GETITEMCOUNT, 0, 0);
                            int nReturn = 1;
                            while (nTabCount >= 2 && nReturn != 0)
                            {
                                nReturn = SendMessage(hWndSysTab, TCM_DELETEITEM, 1, 0);
                                nTabCount = SendMessage(hWndSysTab, TCM_GETITEMCOUNT, 0, 0);
                            }
                        }
                    }


    Wednesday, September 25, 2019 9:13 AM

All replies

  • You must be Admin to send messages (Manifest)

    and be sure that the Dialog Box is displayed (with Sleep for example)

    (Tested on Windows 10 with VS 2015)

    Wednesday, September 25, 2019 10:10 AM
  • Hi IshamRajgariah, 

    Thank you for posting here.

    According to your question, I try to make a test on my side, but I get an exception in FindWindow() method.

    Could you provide your FindWindow() method?

    If possible, please provide all the PInvoke methods you add. It will help us to analyze your problem and make a test.

    We are waiting for your update.

    Best Regards,

    Xingyu Zhao


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Thursday, September 26, 2019 8:41 AM
    Moderator