2017-08-06 167 views
0

我遇到了一個應用程序問題,我試圖獲取它運行的系統的所有網絡配置。最終目標是找到具有最高優先級的MAC地址。程序在其他windows計算機上不能正常工作

代碼運行正常,並且在我使用QtCreator運行時工作,並且在創建包含dll文件和exe文件的文件夾時也運行正常。

但問題是,當我在其他Windows機器(7和10)上運行此程序時,它運行但不返回或顯示任何內容。我試着以管理員身份運行它,但這兩者都不起作用,並且此代碼應該能夠在所有的Windows平臺上運行。

有什麼建議嗎?

我目前在的Windows 10和使用Qt的5.8 MSVC 2015年

的exe文件在Windows 10這些DLL運行:

  • Qt5Core.dll
  • Qt5Network。 dll
  • msvcp140.dll
  • msvcr120.dll
  • vcruntime140.dll

這些DLL應該也有適用於Windows 7:

  • API-MS-雙贏的核心文件l1-2-0.dll
  • API-MS -win-core-file-l2-1-0.dll
  • api-ms-win-core-localization-l1-2-0.dll
  • api-ms-win-core-processthreads-l1-1 -1.dll
  • api-ms-win-core-string-l1-1-0.dll
  • API-MS-雙贏的核心同步,l1-2-0.dll
  • API-MS-雙贏的核心時區 - l1-1-0.dll
  • API-MS-雙贏CRT -convert-l1-1-0.dll
  • api-ms-win-crt-environment-l1-1-0.dll
  • api-ms-win-crt-filesystem-l1-1-0.dll
  • API-MS-雙贏CRT堆-l1-1-0.dll
  • API-MS-雙贏CRT-語言環境l1-1-0.dll
  • API-MS-雙贏CRT -math-l1-1-0.dll
  • api-ms-win-crt-multibyte-l1-1-0.dll
  • api-ms-win-crt-runtime-l1-1-0.dll
  • api-ms-win-crt-stdio -l1-1-0.dll
  • API-MS-雙贏CRT-串l1-1-0.dll
  • API-MS-雙贏CRT-時間l1-1-0.dll
  • api-ms-win-crt-utility-l1-1-0。下面的dll

Link是EXE和DLL文件一起:

https://ufile.io/e9htu

這裏是我的代碼,如果需要的話:

的main.cpp

#include <QCoreApplication> 
#include "macfinder.h" 

int main(int argc, char *argv[]) 
{ 
    QCoreApplication a(argc, argv); 
    MACFinder macFinder; 
    macFinder.findMAC(); 
    return a.exec(); 
} 

macfinder .h

#ifndef MACFINDER_H 
#define MACFINDER_H 

#include <QObject> 
#include <QNetworkConfiguration> 
#include <QNetworkConfigurationManager> 
#include <QNetworkInterface> 
#include <QNetworkSession> 
#include <QDebug> 

class MACFinder : public QObject 
{ 
    Q_OBJECT 
public: 
    explicit MACFinder(QObject *parent = 0); 
    void findMAC(); 
private: 
    QNetworkConfigurationManager ncm; 
    QString filterMAC(QList<QNetworkConfiguration> configs); 

signals: 
    void foundMAC(QString MAC); 
private slots: 
    void configurationsUpdateCompleted(); 
}; 

#endif // MACFINDER_H 

macfinder.cpp

#include "macfinder.h" 

MACFinder::MACFinder(QObject *parent) : QObject(parent) 
{ 
} 

QString MACFinder::filterMAC(QList<QNetworkConfiguration> configs) 
{ 
    qDebug() << "MAC and Index: "; 
    QString MAC; 
    int index; 
    QNetworkConfiguration nc; 
    foreach(nc,configs) 
    { 
     QNetworkSession networkSession(nc); 
     QNetworkInterface netInterface = networkSession.interface(); 
     QString debugStr = QString::number(netInterface.index()) 
       + " | " + netInterface.humanReadableName() + " | " 
       + nc.name() + " | " + netInterface.hardwareAddress(); 
     if(netInterface.hardwareAddress().isEmpty()) 
     { 
      qDebug() << "--> No MAC: " << debugStr; 
      continue; 
     } 
     if(netInterface.name().isEmpty()) 
     { 
      qDebug() << "--> NO NAME: " << debugStr; 
      continue; 
     } 
     if(netInterface.index() == 0) 
     { 
      qDebug() << "--> NO INDEX: " << debugStr; 
      continue; 
     } 
     if(netInterface.flags() & QNetworkInterface::IsLoopBack) 
     { 
      qDebug() << "--> loopBack: " << debugStr; 
      continue; 
     } 
     if(netInterface.flags() & (QNetworkInterface::IsRunning | QNetworkInterface::IsUp)) 
     { 
      qDebug() << "*** Accepted: " << debugStr; 
      if(MAC.isEmpty()) 
      { 
       qDebug() << "setting MAC:" << debugStr; 
       MAC = netInterface.hardwareAddress(); 
       index = netInterface.index(); 
      } 
      else 
      { 
       if(netInterface.index() < index) 
       { 
        qDebug() << "setting MAC:" << debugStr; 
        MAC = netInterface.hardwareAddress(); 
        index = netInterface.index(); 
       } 
       else 
        qDebug() << "index is not lower: " << debugStr; 
      } 
     } 
    } 
    return MAC; 
} 

void MACFinder::findMAC() 
{ 
    qDebug() << "MACFinder::findMAC | updating all configurations"; 
    connect(&ncm,SIGNAL(updateCompleted()),this,SLOT(configurationsUpdateCompleted())); 
    ncm.updateConfigurations(); 
} 

void MACFinder::configurationsUpdateCompleted() 
{ 
    qDebug() << "MACFinder::configurationsUpdateCompleted"; 
    disconnect(&ncm,SIGNAL(updateCompleted()),this,SLOT(configurationsUpdateCompleted())); 
    QNetworkConfiguration nc; 
    QList<QNetworkConfiguration> configs = ncm.allConfigurations(QNetworkConfiguration::Active); 
    qDebug() << "\nAllConfigs: "; 
    foreach (nc,configs) 
    { 
     qDebug() << nc.identifier() << nc.name() << nc.state(); 
    } 
    QString MAC = filterMAC(configs); 
    qDebug() << "\nMAC:" << MAC; 
    if(MAC.isEmpty()) 
    { 
     qDebug("no MAC address found"); 
    } 
    emit foundMAC(MAC); 
} 
+0

也許其他窗口防火牆阻止您的應用程序。將它添加到防火牆列表,https://www.howtogeek.com/howto/uncategorized/how-to-create-exceptions-in-windows-vista-firewall/ – aghilpro

+0

我不發送或接收任何數據包 – mostafaTmj

+0

你可以包你的項目(EXE文件+ DLL),並上傳一些地方下載它。 – aghilpro

回答

3

我下載你的應用程序和分析它在我的電腦上。

問題是您缺少一些dll,您的應用程序運行時沒有錯誤但無法正常工作。 (qgenericbearer.dll,qnativewifibearer.dll與文件夾bearer丟失)。

您可以使用windeploy命令來部署您的項目。

去Qt中,編譯器目錄您的操作系統,例如:

C:\Qt\Qt5.7.0\5.7\msvc2013\bin 

Screenshot1

Shift+right click mouse然後click open command window here

類型windeployqt.exe C:\您的應用程序目錄,例如:

windeployqt.exe C:\Users\Mofrad\Downloads\macfindertest\macFinderTest\macAddressTest.exe 

Screenshot2

現在一些dll將複製到您的應用程序目錄。

現在再次嘗試你的應用程序,你會看到它的工作。

你可以下載你的應用程序的部署here

相關問題