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.6k Views 1 Watching
  • 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.
  • LematL Offline
    LematL Offline
    Lemat
    wrote on 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.

    KroMignonK JonBJ 2 Replies Last reply
    0
    • LematL Lemat

      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
      
      JonBJ Offline
      JonBJ Offline
      JonB
      wrote on last edited by JonB
      #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.

      LematL 1 Reply Last reply
      5
      • LematL Lemat

        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
        
        KroMignonK Offline
        KroMignonK Offline
        KroMignon
        wrote on 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)

        LematL 1 Reply Last reply
        4
        • LematL Lemat

          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
          
          JonBJ Offline
          JonBJ Offline
          JonB
          wrote on last edited by JonB
          #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.

          LematL 1 Reply Last reply
          5
          • KroMignonK KroMignon

            @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();
            
            LematL Offline
            LematL Offline
            Lemat
            wrote on last edited by
            #4

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

            Time to elevate.

            KroMignonK 1 Reply Last reply
            0
            • LematL Lemat

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

              KroMignonK Offline
              KroMignonK Offline
              KroMignon
              wrote on last edited by KroMignon
              #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)

              LematL 1 Reply Last reply
              2
              • JonBJ JonB

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

                LematL Offline
                LematL Offline
                Lemat
                wrote on 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
                • KroMignonK KroMignon

                  @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();
                  
                  LematL Offline
                  LematL Offline
                  Lemat
                  wrote on last edited by
                  #7

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

                  Time to elevate.

                  1 Reply Last reply
                  0

                  • Login

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