Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

Trouble launching windows command



  • Hello, I'm trying to automate this command on windows using a Qt application:

      uwfmgr volume protect c:
    

    the command is supposed to activate the disk filter overlay on partition C:, and if I run the command manually on a terminal it works fine. Uwfmgr is installed and working correctly, the application is running on windows 10 enterprise edition.
    I tried a lot of options:
    I tried directly running the command:

    QStringList par;
    par << "/c";
    par << "uwfmgr volume protect C:";
    //process.setWorkingDirectory( R"(C:\WINDOWS\System32\)" );
     process.start("cmd",par);
    process.waitForFinished(10000);
    

    I tried launching an external script that only contains that command:

    QProcess process;
    process.setProgram( "cmd.exe" );
    process.setArguments( { "/C", R"(D:\test\protectPartition.bat )" } );
    process.start();
    process.waitForFinished(10000);
    

    I tried using windows 10 API (shellapi.h):

    QString path = QDir().absoluteFilePath("protectPartition.bat");
    int result = (int)::ShellExecuteA(0, "open", path.toUtf8().constData(), 0, 0, SW_MINIMIZE);
    if (SE_ERR_ACCESSDENIED == result)
    {
        result = (int)::ShellExecuteA(0, "runas", path.toUtf8().constData(), 0, 0, SW_MINIMIZE);
    }
    

    Keep in mind that my application is running as administrator so the problem is not connected to the application privileges.
    Every solution I tried returns an error like this one:

    'uwfmgr' is not recognized as an internal or external command, operable program or batch file.
    

    I also tried using the absolute path for uwfmgr: "C:/WINDOWS/System32/uwfmgr.exe"
    Execution policy on file "uwfmgr.exe" is to read&execute for every user.
    I checked the environment variables of the shell launched by every one of the solutions above but it is the same as the shell I launch to manually execute the command.
    Does anyone have experience with automating the uwfmgr protection on windows? I'm also asking support on microsoft forums in case there is something I'm missing on that part.
    Thanks to anyone that might have info on this topic.
    Edit: The application is compiled 32-bit



  • Found it! I read this article: https://www.samlogic.net/articles/sysnative-folder-64-bit-windows.htm
    And just for summarizing it: I discovered that when you're running a 32bit application on a 64bit version of windows all the 64bit executables are accessible from %windir%/sysnative instead of %windir%/System32
    Questionable design choice but everyone has their reason.
    This is the snippet of the working code:

    QProcess process;
    //process.setWorkingDirectory("C:/Windows/Sysnative");
    process.start("C:/Windows/Sysnative/uwfmgr.exe", QStringList{"volume", "protect", "C:"});
    process.waitForFinished(10000);
    logInfo("std:"+process.readAllStandardOutput());
    logInfo(QFile::exists(R"(C:\Windows\Sysnative\uwfmgr.exe)")?"uwfExists":"uwfNotExists");
    

    Thank for the support and patience!


  • Lifetime Qt Champion

    @damre22 said in Trouble launching windows command:

    I also tried using the absolute path for uwfmgr: "C:/WINDOWS/System32/uwfmgr.exe"

    Where is the code snipped for this try?
    Don't know why you would need cmd.exe or simliar when you want to run an executable.



  • I tried without the cmd but the result is the same:

    QProcess process;
    process.setWorkingDirectory("C:\\Windows\\System32");
    process.start("uwfmgr.exe", QStringList{ "volume", "protect", "C:" });
    process.waitForFinished(10000);
    

    process.errorString() contains: "Process failed to start: The system cannot find the file specified"
    same as the other tries. I checked again the executable and is in: C:/Windows/System32/uwfmgr.exe


  • Lifetime Qt Champion

    Hi
    I think its a rights issue.
    if you look here
    https://docs.microsoft.com/en-us/windows-hardware/customize/enterprise/uwfmgrexe

    it says it needs an administrator account to change anything.

    so unless you app has the rights, already, i dont think its allowed.



  • Yes i'm using an administrator account and the application is launched with administrator privileges, all the tests above have been executed with this configuration


  • Lifetime Qt Champion

    @damre22
    Ah sorry, you did say "is running as administrator"

    so if you just open a cmd prompt and fire the same "line" its does in fact work ?



  • Yes it works with an administrator command prompt, exactly. I just edited the post because I found this
    https://stackoverflow.com/questions/25457225/qprocess-always-returns-2-when-running-a-valid-command
    My application is compiled with 32-bit QtFramework, could this be the issue?


  • Lifetime Qt Champion

    @damre22
    Hi
    Im not aware of any issues calling other .exe with QProcess and 32/64 issues.
    Should not matter.
    However, if the location does in fact differ between 32/64, then yes.
    The 32 bit app simply dont see the .exe in that location.

    I would try test it
    qDebug() << "file there" << QFile::exists(""C:/WINDOWS/System32/uwfmgr.exe");



  • QFile::exists(""C:/WINDOWS/System32/uwfmgr.exe") returns false. So I need to create a 64bit executable or find the real location of the 32bit one?


  • Lifetime Qt Champion

    @damre22
    Ok. good test.
    I would first try to find real location.
    Try looking in
    C:\WINDOWS\SysWOW64



  • Found it! I read this article: https://www.samlogic.net/articles/sysnative-folder-64-bit-windows.htm
    And just for summarizing it: I discovered that when you're running a 32bit application on a 64bit version of windows all the 64bit executables are accessible from %windir%/sysnative instead of %windir%/System32
    Questionable design choice but everyone has their reason.
    This is the snippet of the working code:

    QProcess process;
    //process.setWorkingDirectory("C:/Windows/Sysnative");
    process.start("C:/Windows/Sysnative/uwfmgr.exe", QStringList{"volume", "protect", "C:"});
    process.waitForFinished(10000);
    logInfo("std:"+process.readAllStandardOutput());
    logInfo(QFile::exists(R"(C:\Windows\Sysnative\uwfmgr.exe)")?"uwfExists":"uwfNotExists");
    

    Thank for the support and patience!


Log in to reply