LogonUser

  • Thread starter Thread starter ZhangZQ
  • Start date Start date
Z

ZhangZQ

If I want to access the shared folder in other Windows PC, a popup dialog
will popup to input the username and password.

Is it possible to access the files in shared folder in coding without the
popup dialog if I have the user name and password in that host pc?

For examples, I want to open the file in a host, \\host\files\file.cpp,
fopen(\\\host\\files\file.cpp, 'r'); Is it possible? Should I use the
LogonUser() first?

Thanks.
 
yes, can you show me the example code to do that?
I want to know which functions should be used?

Thank you very much!
 
ZhangZQ said:
If I want to access the shared folder in other Windows PC, a popup dialog
will popup to input the username and password.

Is it possible to access the files in shared folder in coding without the
popup dialog if I have the user name and password in that host pc?

For examples, I want to open the file in a host, \\host\files\file.cpp,
fopen(\\\host\\files\file.cpp, 'r'); Is it possible? Should I use the
LogonUser() first?

You don't have to do a LogonUser() unless the creditials are going to
conflict with what the process is running as.

You need to do WNetAddConnection2()

WNetAddConnection2(
"\\\\host\\files",
"password",
"username",
dwFlags
);

If you want it to prompt the user if the user/pass you give it fails set the
flags to CONNECT_INTERACTIVE.
 
Thank you, let me try.

Chris P. said:
You don't have to do a LogonUser() unless the creditials are going to
conflict with what the process is running as.

You need to do WNetAddConnection2()

WNetAddConnection2(
"\\\\host\\files",
"password",
"username",
dwFlags
);

If you want it to prompt the user if the user/pass you give it fails set the
flags to CONNECT_INTERACTIVE.
 
Wait! I made a mixtake. The first parameter is the NETRESOURCE structure,
not just a path.
 
NETRESOURCE nr;
ZeroMemory(&nr,sizeof(NETRESOURCE));
nr.dwScope = RESOURCE_GLOBALNET;
nr.dwType = RESOURCETYPE_ANY;
nr.lpLocalName = "";
nr.lpRemoteName = (LPTSTR)"\\\\host\\files";
nr.lpProvider = NULL;
WNetAddConnection2(&nr,pszPass,pszUserName,NULL);
FILE* fp;
fp = fopen("\\\\host\\files\file.cpp", 'r');
 
If you need programmatically make share directory "files" use
NetShareAdd() for that
Arkady
 
Back
Top