I have a workgroup with two machines (Two Windows Server 2012). I wanted to write a program that let me to create files/directories and ... on the remote machine. My workgroup setup:
Machine 1:
- Username: W1
- Name: WONE
- password: lalalala
- Workgroup: WLAB
Machine 2:
- Username: W2
- Name: WTWO
- password: lalalala
- Workgroup: WLAB
I have written the following program that works correctly on the local file system but when I wanted to create a file on the remote machine (i.e \WONE\Users\W1\Desktop\Sample.txt) from WTWO machine, it doesn't work. I run my program with administrator privilege too but nothing changed. My program:
#include <windows.h>
#include <iostream>
bool MakeFileOnSystemAbsloute(const wchar_t* arg_path)
{
SECURITY_ATTRIBUTES sa_FileSecurityAttribute;
wchar_t c_FilePath[MAX_PATH];
sa_FileSecurityAttribute.nLength = sizeof(sa_FileSecurityAttribute);
sa_FileSecurityAttribute.lpSecurityDescriptor = NULL;
sa_FileSecurityAttribute.bInheritHandle = FALSE;
wcscpy_s(c_FilePath, MAX_PATH, arg_path);
HANDLE h_CreatedFile = CreateFileW(c_FilePath, 0, 0, &sa_FileSecurityAttribute, CREATE_NEW, FILE_ATTRIBUTE_NORMAL, NULL);
if (h_CreatedFile)
{
CloseHandle(h_CreatedFile);
return true;
}
else
{
return false;
}
return false;
}
int main()
{
MakeFileOnSystemAbsloute(L"\\WONE\\Users\\W1\\Desktop\\Milad.txt");
return 0;
}
Where is the problem? How should I fix this issue? Also, I read the following text from the internet, it seems I can't get access to the remote machine with my current account in local machine.
Quote:
The fact that the machine with the shared drive is not on a domain is where your main problem is. In order to get this to work you will have to configure the Windows Service to run as a specific user, and then you'll have to create an identical user on the remote system with the same password. It might work then.
The problem stems from the fact that in order to log in to a machine not in a domain, you have to log into that machine using an account that exists on that machine. The machine account for something else definitely won't exist on that local machine. By creating an identical user with an identical password, you might be able get the login to work."
-sysadmin1138