程序在其他windows计算机上不能正常工作
问题描述:
我遇到了一个应用程序问题,我试图获取它运行的系统的所有网络配置。最终目标是找到具有最高优先级的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文件一起:
这里是我的代码,如果需要的话:
的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);
}
答
我下载你的应用程序和分析它在我的电脑上。
问题是您缺少一些dll,您的应用程序运行时没有错误但无法正常工作。 (qgenericbearer.dll
,qnativewifibearer.dll
与文件夹bearer
丢失)。
您可以使用windeploy命令来部署您的项目。
去Qt中,编译器目录您的操作系统,例如:
C:\Qt\Qt5.7.0\5.7\msvc2013\bin
按Shift+right click mouse
然后click open command window here
类型windeployqt.exe C:\您的应用程序目录,例如:
windeployqt.exe C:\Users\Mofrad\Downloads\macfindertest\macFinderTest\macAddressTest.exe
现在一些dll将复制到您的应用程序目录。
现在再次尝试你的应用程序,你会看到它的工作。
你可以下载你的应用程序的部署here
也许其他窗口防火墙阻止您的应用程序。将它添加到防火墙列表,https://www.howtogeek.com/howto/uncategorized/how-to-create-exceptions-in-windows-vista-firewall/ – aghilpro
我不发送或接收任何数据包 – mostafaTmj
你可以包你的项目(EXE文件+ DLL),并上传一些地方下载它。 – aghilpro