Qt Forum

    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Unsolved

    Solved Trouble launching windows command

    General and Desktop
    3
    11
    1470
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • D
      damre22 last edited by damre22

      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

      1 Reply Last reply Reply Quote 0
      • D
        damre22 last edited by

        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!

        1 Reply Last reply Reply Quote 3
        • Christian Ehrlicher
          Christian Ehrlicher Lifetime Qt Champion last edited by

          @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.

          Qt has to stay free or it will die.

          1 Reply Last reply Reply Quote 2
          • D
            damre22 last edited by

            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

            1 Reply Last reply Reply Quote 0
            • mrjj
              mrjj Lifetime Qt Champion last edited by

              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.

              1 Reply Last reply Reply Quote 1
              • D
                damre22 last edited by damre22

                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

                mrjj 1 Reply Last reply Reply Quote 0
                • mrjj
                  mrjj Lifetime Qt Champion @damre22 last edited by

                  @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 ?

                  1 Reply Last reply Reply Quote 0
                  • D
                    damre22 last edited by damre22

                    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?

                    mrjj 1 Reply Last reply Reply Quote 0
                    • mrjj
                      mrjj Lifetime Qt Champion @damre22 last edited by mrjj

                      @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");

                      1 Reply Last reply Reply Quote 0
                      • D
                        damre22 last edited by

                        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?

                        mrjj 1 Reply Last reply Reply Quote 0
                        • mrjj
                          mrjj Lifetime Qt Champion @damre22 last edited by mrjj

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

                          1 Reply Last reply Reply Quote 0
                          • D
                            damre22 last edited by

                            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!

                            1 Reply Last reply Reply Quote 3
                            • First post
                              Last post