使用 Qt 在 windows 中以编程方式更改网络适配器名称
Changing the Network adapter name Programmatically in windows with Qt
我知道可以在 windows 中使用控制台中的 netsh 命令更改网络适配器。但我需要使用 C++ 在 Qt 中执行此操作。我曾尝试使用 QProcess 调用 netsh,但命令提示符需要管理员权限。我的适配器名称中也有 space,这使得 运行 也不容易。 Qt 中是否有任何库能够在不使用 QProcess 并在其中调用 windows 命令的情况下更改网络适配器名称?
更新 1:
当我 运行 具有管理员权限的程序并在我的字符串中设置 \" for having " 时,我可以使用 QProcess 和 netsh 命令更改适配器名称。
QProcess p;
QString pi_network = "original adapter name";
p.start("netsh interface set interface name = \""+pi_network+"\" newname = \"MyAdapter\"");
我会 post 它作为答案,因为它可能对某人有所帮助(正如 MrEricSir 在评论中所说)。
您可以使用 netsh 命令,但请注意您应该 运行 您的程序在 windows 中具有管理员权限。
QProcess p;
QString pi_network = "original adapter name";
p.start("netsh interface set interface name = \""+pi_network+"\" newname = \"new network adapter name\"");
p.waitForFinished();
p.close();
我知道可以在 windows 中使用控制台中的 netsh 命令更改网络适配器。但我需要使用 C++ 在 Qt 中执行此操作。我曾尝试使用 QProcess 调用 netsh,但命令提示符需要管理员权限。我的适配器名称中也有 space,这使得 运行 也不容易。 Qt 中是否有任何库能够在不使用 QProcess 并在其中调用 windows 命令的情况下更改网络适配器名称?
更新 1: 当我 运行 具有管理员权限的程序并在我的字符串中设置 \" for having " 时,我可以使用 QProcess 和 netsh 命令更改适配器名称。
QProcess p;
QString pi_network = "original adapter name";
p.start("netsh interface set interface name = \""+pi_network+"\" newname = \"MyAdapter\"");
我会 post 它作为答案,因为它可能对某人有所帮助(正如 MrEricSir 在评论中所说)。
您可以使用 netsh 命令,但请注意您应该 运行 您的程序在 windows 中具有管理员权限。
QProcess p;
QString pi_network = "original adapter name";
p.start("netsh interface set interface name = \""+pi_network+"\" newname = \"new network adapter name\"");
p.waitForFinished();
p.close();