1
votes

I trying to run "net use \server_ip" and parse result. Platform - Windows

I have the following code:

QProcess *prc = new QProcess(0);
QString exec="net use";
QStringList params;
params << "\\\\" + getServerIP();
prc->start(exec,params);
qDebug() << "exec process";
prc->waitForFinished();
qDebug() << prc->readAll() << prc->exitStatus();;
delete connected;

But readAll() reurns "" and exitStatus() returns 0.

Do you guys have any suggestion?

1
"use" is actually the first parameter. The command is net.exe - Ben Voigt
Also, you should check the result of QProcess::start - Ben Voigt
QProcess::start returns void - tty6
QProcess uses signals to report failure instead of a return value. Doesn't change that you failed to check the result (result can mean return value, but it can also mean exception, output parameter, global errno, or in this case, a signal). - Ben Voigt

1 Answers

1
votes

My suggestion would be to delete all of the above, and call WNetAddConnection1 instead.

At least if I'm interpreting what you have above correctly, it seems to be a really roundabout version of something like this:

WNetAddConnection(getServerIP(), NULL, NULL);

If GetServerIP returns a QString, you may need to add a call to toAscii (or toLatin1, toLocal8Bit, etc.) to convert it to get something `WNetAddConnection knows how to deal with.


  1. Or WNetAddConnection2 or WNetAddConnection3. Microsoft officially recommends the latter, but you don't seem to need any of the extra capabilities they provide.