Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Trouble launching windows command

Trouble launching windows command

Scheduled Pinned Locked Moved Solved General and Desktop
11 Posts 3 Posters 2.5k Views
  • 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 Offline
    D Offline
    damre22
    wrote on last edited by damre22
    #1

    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
    0
    • D Offline
      D Offline
      damre22
      wrote on last edited by
      #11

      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
      3
      • Christian EhrlicherC Offline
        Christian EhrlicherC Offline
        Christian Ehrlicher
        Lifetime Qt Champion
        wrote on last edited by
        #2

        @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 Online Installer direct download: https://download.qt.io/official_releases/online_installers/
        Visit the Qt Academy at https://academy.qt.io/catalog

        1 Reply Last reply
        2
        • D Offline
          D Offline
          damre22
          wrote on last edited by
          #3

          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
          0
          • mrjjM Offline
            mrjjM Offline
            mrjj
            Lifetime Qt Champion
            wrote on last edited by
            #4

            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
            1
            • D Offline
              D Offline
              damre22
              wrote on last edited by damre22
              #5

              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

              mrjjM 1 Reply Last reply
              0
              • D 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

                mrjjM Offline
                mrjjM Offline
                mrjj
                Lifetime Qt Champion
                wrote on last edited by
                #6

                @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
                0
                • D Offline
                  D Offline
                  damre22
                  wrote on last edited by damre22
                  #7

                  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?

                  mrjjM 1 Reply Last reply
                  0
                  • D 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?

                    mrjjM Offline
                    mrjjM Offline
                    mrjj
                    Lifetime Qt Champion
                    wrote on last edited by mrjj
                    #8

                    @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
                    0
                    • D Offline
                      D Offline
                      damre22
                      wrote on last edited by
                      #9

                      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?

                      mrjjM 1 Reply Last reply
                      0
                      • D damre22

                        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?

                        mrjjM Offline
                        mrjjM Offline
                        mrjj
                        Lifetime Qt Champion
                        wrote on last edited by mrjj
                        #10

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

                        1 Reply Last reply
                        0
                        • D Offline
                          D Offline
                          damre22
                          wrote on last edited by
                          #11

                          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
                          3

                          • Login

                          • Login or register to search.
                          • First post
                            Last post
                          0
                          • Categories
                          • Recent
                          • Tags
                          • Popular
                          • Users
                          • Groups
                          • Search
                          • Get Qt Extensions
                          • Unsolved