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. [SOLVED] Windows: netsh and QProcess
Forum Updated to NodeBB v4.3 + New Features

[SOLVED] Windows: netsh and QProcess

Scheduled Pinned Locked Moved General and Desktop
13 Posts 4 Posters 6.0k 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.
  • H Offline
    H Offline
    helthans
    wrote on last edited by
    #3

    Thanks a lot for the reply, SGaist.
    I have tried to use exitCode() as shown below, but this just gives me zero regardless if I have an IP conflict or not.

    @
    QProcess process;
    QString cmd;
    cmd = QString("netsh interface ip set address name="%1" static %2 %3 %4 1").arg(m_adapter).arg(m_ip).arg(m_netmask).arg(m_gateway);

    process.start(cmd);
    process.waitForFinished();
    qDebug() << process.exitCode();
    @

    I have tried to run the netsh command manually in a command prompt. And it does not give any output either if I trigger an IP conflict (other than the pop-up window). Any ideas how to extract this information from netsh?

    1 Reply Last reply
    0
    • T Offline
      T Offline
      TioRoy
      wrote on last edited by
      #4

      netsh is returning 0 because it changed the IP successfully.

      The conflict notification occurs later.

      1 Reply Last reply
      0
      • H Offline
        H Offline
        helthans
        wrote on last edited by
        #5

        Ahh.. Good to know :) Do you know if it is possible to get the notification of the conflict other than a pop-up window?

        1 Reply Last reply
        0
        • SGaistS Offline
          SGaistS Offline
          SGaist
          Lifetime Qt Champion
          wrote on last edited by
          #6

          Isn't that popup coming from your OS ?

          Interested in AI ? www.idiap.ch
          Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

          1 Reply Last reply
          0
          • H Offline
            H Offline
            helthans
            wrote on last edited by
            #7

            Yes that is coming from the OS

            1 Reply Last reply
            0
            • T Offline
              T Offline
              TioRoy
              wrote on last edited by
              #8

              I don't know if it's possible.

              The popup is displayed when a network packet arrives at the NIC. This can happen immediately or take minutes, depending on network traffic.

              1 Reply Last reply
              0
              • J Offline
                J Offline
                jafarabadi.qt
                wrote on last edited by
                #9

                Hi, helthans
                i think that below code can be useful for you... change for yourself and try it:
                @
                QProcess pingProcess;
                QString exec = "ping";
                QStringList params;
                params << "-c" << "1" << IP;
                pingProcess.start(exec,params,QIODevice::ReadOnly);
                pingProcess.waitForFinished(-1);
                QString p_stdout = pingProcess.readAllStandardOutput();
                QString p_stderr = pingProcess.readAllStandardError();
                @

                1 Reply Last reply
                0
                • SGaistS Offline
                  SGaistS Offline
                  SGaist
                  Lifetime Qt Champion
                  wrote on last edited by
                  #10

                  @ a.jafarabadi QProcess is not the problem here, the impact of the call to netsh is completely outside of QProcess.

                  Interested in AI ? www.idiap.ch
                  Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

                  1 Reply Last reply
                  0
                  • T Offline
                    T Offline
                    TioRoy
                    wrote on last edited by
                    #11

                    The code from a.jafarabadi can be usefull: Test the IP (with ping) before invoke the netsh. Maybe you need to decode the results.

                    If your code will run on Windows only, you can call IcmpSendEcho:http://msdn.microsoft.com/en-us/library/windows/desktop/aa366050(v=vs.85).aspx instead invoke PING.EXE, .

                    1 Reply Last reply
                    0
                    • H Offline
                      H Offline
                      helthans
                      wrote on last edited by
                      #12

                      @ a.jafarabadi and TiRoy: Yes I agree, testing the IP before netsh is the way to go.
                      Thanks a lot for the solutions suggested. For the network issue my code is split up in a Windows and Linux part (no way around this :)). For Windows I will look into lcmpSendEcho, but for Linux I need to use the ping command - I was hoping I could use another metric, instead of having to do some pattern matching of the output of the ping command, but I guess there is no way around this either.

                      1 Reply Last reply
                      0
                      • J Offline
                        J Offline
                        jafarabadi.qt
                        wrote on last edited by
                        #13

                        Thanks from every one who help to solve it :)

                        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