Question

I want to achieve Path SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\SharedDLLs and key name : C:\Program Files\Common Files\Intel\WirelessCommon\TraceAPI.dll Now I want to remove this key. Below is my attempt. Thanks for reading.

I have tried with Qt and with native API also. Qt remove is not working because of slash in keyname. In native API I am able to open key but when I'm trying to delete the key there is ERROR_FILE_NOT_FOUND . I have tried all possible combination of key with slashes.

void  sharedDlls(QSettings::Format format)
{
  QSettings settings("HKLM\\SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\SharedDLLs", format);

  HKEY hkey;
  LONG n = ::RegOpenKeyEx(HKEY_LOCAL_MACHINE,
                          TEXT("SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\SharedDLLs"),
                          0, KEY_ALL_ACCESS | KEY_WOW64_64KEY, &hkey);

  foreach (QString subkey, settings.allKeys() )
  {
    //converting to double quoted slashes
    subkey = subkey.replace("/","\\\\");

    if(clean)
    {  
      // because of a slash it's impossible for qsettings to delete
      settings.remove(subkey);

      LONG n = RegDeleteKeyEx(hkey, (LPCWSTR)subkey.utf16(), KEY_WOW64_32KEY, 0);
      if(n != ERROR_SUCCESS)
      {
        qDebug() << GetLastError();
        qDebug() << "deleting error" << n;
        //here is error
        //ERROR_FILE_NOT_FOUND
      }
    }
  }

  //now close opened
  ::RegCloseKey(hkey);
}
Was it helpful?

Solution

I found no answer of my Qs so I'm adding solution..you can give bounty if like it ;)

It's workaround and not exact solution but I think it's good and stable.

There are two parts of answer 1. Handle 32 redirection 2. REG DELETE - to remove key containing backslashes

Part 1

Run 32
%windir%\SysWOW64\reg.exe

Run64 %windir%\sysnative\reg.exe

if you use system32 it will redirect to 32 bit reg when used from 32 bit app so avoid using it. Use sysnative. or disable redirection for temporary

SysNative is valid vista above only

Part 2 : This is complete solution (Qt)

QString reg32 = qgetenv("windir")+"\\SysWOW64\\reg.exe";
QString reg64 = qgetenv("windir")+ "\\sysnative\\reg.exe";


QString command = tr("%1 DELETE \"HKLM\\SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\SharedDLLs\" /v \"%2\" /f")
        .arg(  is32Bit == true ? reg32 : reg64  )
        .arg(key);



QProcess *process = new QProcess(this);
process->start(command);


if (process->waitForStarted())
{
    process->waitForFinished();
    QString l = process->readAllStandardOutput().simplified();

    Logger::Log_Info("RegistryCleaner", command);

    if(l.isEmpty())
        Logger::Log_Error("RegistryCleaner", "Try again." );
    else
        Logger::Log_Info("RegistryCleaner", "Successfully done" );
}
else
    qDebug() << process->readAllStandardError().simplified();

delete process;
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top