我尝试c$
通过WNetAddConnection2
. 这是我使用的代码:
int main() {
NETRESOURCE nr;
std::string remote{"\\\\192.168.178.22\\c$"}
nr.dwType = RESOURCETYPE_ANY;
nr.lpLocalName = NULL;
nr.lpRemoteName = remote.data();
nr.lpProvider = NULL;
auto res = WNetAddConnection2(&nr, "test", "User", NULL);
if (res == NO_ERROR) {
std::cout << "Connected\n";
} else {
std::cout << res << '\n';
}
}
这只是给我86
代表的错误代码:
指定的网络密码不正确。
如果我尝试net use
像这样安装共享:
net use \\192.168.178.22\c$ /user:User
并在提示连接成功时提供相同的密码。
我的代码有问题吗?还是我错过了什么?因为对我来说,连接与函数一起工作net use
但不与WNetAddConnection2
函数一起工作很奇怪。