Access a shared folder from a machine not in the domain
I am writing an application in c#, which connects to other machines using remoting, and implants an executable on each machine and then executes 开发者_运维百科it. Each machine creates a dedicated shared folder locally and then asynchronously tries to write to other machines' shared folder.
The problem is that when one machine tries to write to a shared folder of a different machine (in case they are not in the same domain), it fails. if I try to manually access from one machine to the other's shared folder, I'm being prompted for credentials, even though I can see that the shared folder gives full permissions to everyone.
Does anyone know how to solve this issue?
Thanks!
You can use the LogonUser API via P/Invoke to achieve this but you will need some mechanism for getting the users password (the user's keyboard is a good one for this ;) )
DllImport("advapi32.dll", SetLastError=true)]
static extern bool LogonUser(
string principal,
string authority,
string password,
LogonTypes logonType,
LogonProviders logonProvider,
out IntPtr token);
void login(){
bool result = LogonUser(
"Alice", "ACME", // "ACME\Alice"
pwd,
LogonTypes.Batch,
LogonProviders.Default,
out token);
if (result){
//off you go
}
}
精彩评论