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. WMIC command is working on cmd but not in QProcess

WMIC command is working on cmd but not in QProcess

Scheduled Pinned Locked Moved Solved General and Desktop
7 Posts 3 Posters 1.2k 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.
  • L Offline
    L Offline
    Lemat
    wrote on 6 Jan 2020, 19:18 last edited by
    #1

    i wrote this code to get out:

    QProcess p;
        p.setReadChannel(QProcess::StandardOutput);
        p.setReadChannelMode(QProcess::MergedChannels);
        p.start("wmic diskdrive where deviceid='\\\\.\\PHYSICALDRIVE0' get serialnumber,model,size");
        p.waitForReadyRead();
        qDebug()<<QString(p.readAllStandardOutput()).simplified().split(QRegExp("[\n\r ]"),QString::SkipEmptyParts);
        p.close();
    

    when i run my qt app, i get this error :

    ("Node", "-", "Hostname", "ERROR", ":", "Description", "=", "Request", "no", "valid")
    

    instead of:

    Model        SerialNumber  Size
    ST9500***AS  ********      500105249280
    

    Time to elevate.

    K J 2 Replies Last reply 6 Jan 2020, 19:30
    0
    • L Lemat
      6 Jan 2020, 19:18

      i wrote this code to get out:

      QProcess p;
          p.setReadChannel(QProcess::StandardOutput);
          p.setReadChannelMode(QProcess::MergedChannels);
          p.start("wmic diskdrive where deviceid='\\\\.\\PHYSICALDRIVE0' get serialnumber,model,size");
          p.waitForReadyRead();
          qDebug()<<QString(p.readAllStandardOutput()).simplified().split(QRegExp("[\n\r ]"),QString::SkipEmptyParts);
          p.close();
      

      when i run my qt app, i get this error :

      ("Node", "-", "Hostname", "ERROR", ":", "Description", "=", "Request", "no", "valid")
      

      instead of:

      Model        SerialNumber  Size
      ST9500***AS  ********      500105249280
      
      J Offline
      J Offline
      JonB
      wrote on 6 Jan 2020, 19:44 last edited by JonB 1 Jun 2020, 19:55
      #3

      @Lemat said in WMIC command is working on cmd but not in QProcess:

      My hunch is that there is an issue in your command-line where you have deviceid='\\\\.\\PHYSICALDRIVE0'. For example, I see example from https://superuser.com/a/647711/479430 where using

      wmic DiskDrive where "DeviceID='\\\\.\\PHYSICALDRIVE<disk_index>'" Assoc /assocclass:Win32_DiskDriveToDiskPartition
      

      while yours will generate

      wmic diskdrive where deviceid='\\.\PHYSICALDRIVE0' get serialnumber,model,size
      

      They differ in the " marks and the number of \s. Start from the exact command you need to type into Windows shell (or from documentation) and adapt it to C++/argument for QProcess from there.

      @KroMignon's may work, but it will be passing deviceid='\\.\PHYSICALDRIVE0', is that what is intended?

      If your issue is over the backslash count, you might find you want to use C++ raw string literal here, e.g. R"(deviceid='\\\\.\\PHYSICALDRIVE0')" or whatever you decide the final command needs to look like backslash-wise.

      L 1 Reply Last reply 6 Jan 2020, 22:35
      5
      • L Lemat
        6 Jan 2020, 19:18

        i wrote this code to get out:

        QProcess p;
            p.setReadChannel(QProcess::StandardOutput);
            p.setReadChannelMode(QProcess::MergedChannels);
            p.start("wmic diskdrive where deviceid='\\\\.\\PHYSICALDRIVE0' get serialnumber,model,size");
            p.waitForReadyRead();
            qDebug()<<QString(p.readAllStandardOutput()).simplified().split(QRegExp("[\n\r ]"),QString::SkipEmptyParts);
            p.close();
        

        when i run my qt app, i get this error :

        ("Node", "-", "Hostname", "ERROR", ":", "Description", "=", "Request", "no", "valid")
        

        instead of:

        Model        SerialNumber  Size
        ST9500***AS  ********      500105249280
        
        K Offline
        K Offline
        KroMignon
        wrote on 6 Jan 2020, 19:30 last edited by
        #2

        @Lemat I think you should change the function call to use an argument list to avoid space issues:

            QProcess p;
            p.setReadChannel(QProcess::StandardOutput);
            p.setReadChannelMode(QProcess::MergedChannels);
            QStringList opt;
            opt << "diskdrive" << "where" 
                << "deviceid='\\\\.\\PHYSICALDRIVE0'"
                << "get" << "serialnumber,model,size"
            p.start("wmic", opt);
            p.waitForReadyRead();
            qDebug()<<QString(p.readAllStandardOutput()).simplified().split(QRegExp("[\n\r ]"),QString::SkipEmptyParts);
            p.close();
        

        It is an old maxim of mine that when you have excluded the impossible, whatever remains, however improbable, must be the truth. (Sherlock Holmes)

        L 1 Reply Last reply 6 Jan 2020, 22:23
        4
        • L Lemat
          6 Jan 2020, 19:18

          i wrote this code to get out:

          QProcess p;
              p.setReadChannel(QProcess::StandardOutput);
              p.setReadChannelMode(QProcess::MergedChannels);
              p.start("wmic diskdrive where deviceid='\\\\.\\PHYSICALDRIVE0' get serialnumber,model,size");
              p.waitForReadyRead();
              qDebug()<<QString(p.readAllStandardOutput()).simplified().split(QRegExp("[\n\r ]"),QString::SkipEmptyParts);
              p.close();
          

          when i run my qt app, i get this error :

          ("Node", "-", "Hostname", "ERROR", ":", "Description", "=", "Request", "no", "valid")
          

          instead of:

          Model        SerialNumber  Size
          ST9500***AS  ********      500105249280
          
          J Offline
          J Offline
          JonB
          wrote on 6 Jan 2020, 19:44 last edited by JonB 1 Jun 2020, 19:55
          #3

          @Lemat said in WMIC command is working on cmd but not in QProcess:

          My hunch is that there is an issue in your command-line where you have deviceid='\\\\.\\PHYSICALDRIVE0'. For example, I see example from https://superuser.com/a/647711/479430 where using

          wmic DiskDrive where "DeviceID='\\\\.\\PHYSICALDRIVE<disk_index>'" Assoc /assocclass:Win32_DiskDriveToDiskPartition
          

          while yours will generate

          wmic diskdrive where deviceid='\\.\PHYSICALDRIVE0' get serialnumber,model,size
          

          They differ in the " marks and the number of \s. Start from the exact command you need to type into Windows shell (or from documentation) and adapt it to C++/argument for QProcess from there.

          @KroMignon's may work, but it will be passing deviceid='\\.\PHYSICALDRIVE0', is that what is intended?

          If your issue is over the backslash count, you might find you want to use C++ raw string literal here, e.g. R"(deviceid='\\\\.\\PHYSICALDRIVE0')" or whatever you decide the final command needs to look like backslash-wise.

          L 1 Reply Last reply 6 Jan 2020, 22:35
          5
          • K KroMignon
            6 Jan 2020, 19:30

            @Lemat I think you should change the function call to use an argument list to avoid space issues:

                QProcess p;
                p.setReadChannel(QProcess::StandardOutput);
                p.setReadChannelMode(QProcess::MergedChannels);
                QStringList opt;
                opt << "diskdrive" << "where" 
                    << "deviceid='\\\\.\\PHYSICALDRIVE0'"
                    << "get" << "serialnumber,model,size"
                p.start("wmic", opt);
                p.waitForReadyRead();
                qDebug()<<QString(p.readAllStandardOutput()).simplified().split(QRegExp("[\n\r ]"),QString::SkipEmptyParts);
                p.close();
            
            L Offline
            L Offline
            Lemat
            wrote on 6 Jan 2020, 22:23 last edited by
            #4

            @KroMignon thank for your reply. but it not work.

            Time to elevate.

            K 1 Reply Last reply 6 Jan 2020, 22:26
            0
            • L Lemat
              6 Jan 2020, 22:23

              @KroMignon thank for your reply. but it not work.

              K Offline
              K Offline
              KroMignon
              wrote on 6 Jan 2020, 22:26 last edited by KroMignon 1 Jun 2020, 22:28
              #5

              @Lemat Hi, I see the problem, you need to escape the backslashes:

                  QProcess p;
                  p.setReadChannel(QProcess::StandardOutput);
                  p.setReadChannelMode(QProcess::MergedChannels);
                  QStringList opt;
                  opt << "diskdrive" << "where" 
                      << "deviceid='\\\\\\\\.\\\\PHYSICALDRIVE0'"
                      << "get" << "serialnumber,model,size"
                  p.start("wmic", opt);
                  p.waitForFinished();
                  qDebug()<<QString(p.readAllStandardOutput()).simplified().split(QRegExp("[\n\r ]"),QString::SkipEmptyParts);
                  p.close();
              

              It is an old maxim of mine that when you have excluded the impossible, whatever remains, however improbable, must be the truth. (Sherlock Holmes)

              L 1 Reply Last reply 6 Jan 2020, 22:37
              2
              • J JonB
                6 Jan 2020, 19:44

                @Lemat said in WMIC command is working on cmd but not in QProcess:

                My hunch is that there is an issue in your command-line where you have deviceid='\\\\.\\PHYSICALDRIVE0'. For example, I see example from https://superuser.com/a/647711/479430 where using

                wmic DiskDrive where "DeviceID='\\\\.\\PHYSICALDRIVE<disk_index>'" Assoc /assocclass:Win32_DiskDriveToDiskPartition
                

                while yours will generate

                wmic diskdrive where deviceid='\\.\PHYSICALDRIVE0' get serialnumber,model,size
                

                They differ in the " marks and the number of \s. Start from the exact command you need to type into Windows shell (or from documentation) and adapt it to C++/argument for QProcess from there.

                @KroMignon's may work, but it will be passing deviceid='\\.\PHYSICALDRIVE0', is that what is intended?

                If your issue is over the backslash count, you might find you want to use C++ raw string literal here, e.g. R"(deviceid='\\\\.\\PHYSICALDRIVE0')" or whatever you decide the final command needs to look like backslash-wise.

                L Offline
                L Offline
                Lemat
                wrote on 6 Jan 2020, 22:35 last edited by
                #6

                @JonB you saved my afternoon. i forgot R"()" utilization. i had used it over QFile and QByteArray for another app. thanks!! thanks!!!!!

                Time to elevate.

                1 Reply Last reply
                0
                • K KroMignon
                  6 Jan 2020, 22:26

                  @Lemat Hi, I see the problem, you need to escape the backslashes:

                      QProcess p;
                      p.setReadChannel(QProcess::StandardOutput);
                      p.setReadChannelMode(QProcess::MergedChannels);
                      QStringList opt;
                      opt << "diskdrive" << "where" 
                          << "deviceid='\\\\\\\\.\\\\PHYSICALDRIVE0'"
                          << "get" << "serialnumber,model,size"
                      p.start("wmic", opt);
                      p.waitForFinished();
                      qDebug()<<QString(p.readAllStandardOutput()).simplified().split(QRegExp("[\n\r ]"),QString::SkipEmptyParts);
                      p.close();
                  
                  L Offline
                  L Offline
                  Lemat
                  wrote on 6 Jan 2020, 22:37 last edited by
                  #7

                  @KroMignon good answer again. thanks for you time!!!. very thanks!!!.

                  Time to elevate.

                  1 Reply Last reply
                  0

                  1/7

                  6 Jan 2020, 19:18

                  • Login

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