Talk:UserMgr plug-in: Difference between revisions

From NSIS Wiki
Jump to navigationJump to search
(The solution to add a group to a user)
 
m (better formatting)
Line 7: Line 7:
Here is the modified code :  
Here is the modified code :  


 
<highlight-c>
int __declspec(dllexport) AddToGroup(HWND hwndParent, int string_size,  
int __declspec(dllexport) AddToGroup(HWND hwndParent, int string_size,  
char *variables, stack_t **stacktop,
                                    char *variables, stack_t **stacktop,
extra_parameters *extra)
                                    extra_parameters *extra)
{
{
NET_API_STATUS nStatus = 0;
NET_API_STATUS nStatus = 0;
Line 50: Line 50:
}
}
}//AddToGroup
}//AddToGroup
</highlight-c>

Revision as of 09:18, 10 May 2006

Thanks for this routine, i use it. However, the function to a group to a user isn't functionnal, it seems to be a windows API problem. I solved this problem using NetLocalGroupAddMembers and modified your dll and it works fine now.

BTW : Your code isn't working with VS8, the problem is swprintf, use MultiByteToWideChar instead. You can contact me at richard.france[nospam]@laposte.net Here is the modified code :

int __declspec(dllexport) AddToGroup(HWND hwndParent, int string_size, 
                                     char *variables, stack_t **stacktop,
                                     extra_parameters *extra)
{
	NET_API_STATUS nStatus = 0;
	WCHAR u_userid[256];
	WCHAR u_groupid[256];
	LPWSTR pUserID;
 
	static char userid[256];
	static char groupid[256];
 
 
	memset( u_userid, 0, sizeof( u_userid ) );
	memset( u_groupid, 0, sizeof( u_groupid ) );
 
	g_hwndParent=hwndParent;
 
	EXDLL_INIT();
 
	popstring(userid);
	popstring(groupid);
 
	MultiByteToWideChar (CP_ACP, 0, userid, -1, u_userid, strlen(userid));
	MultiByteToWideChar (CP_ACP, 0, groupid, -1, u_groupid, strlen(groupid));
 
	pUserID = u_userid;
 
	nStatus = NetLocalGroupAddMembers(NULL, u_groupid , 3,  &pUserID, 1);
 
	if (nStatus == NERR_Success)
	{
		pushstring("OK");
		return 0;
	}
	else
	{
		sprintf(userid, "ERROR %d", nStatus);
		pushstring(userid);
		return nStatus;
	}
}//AddToGroup