Shell32 related code working in Windows 7 but not in Windows 10

  • Thread starter Thread starter IshamRajgariah
  • Start date Start date
I

IshamRajgariah

Guest
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);
}
}
}

Continue reading...
 
Back
Top