Re: ControlPanel->User Account does not show new accounts created by my program .
- From: "Mark Yudkin" <DoNotContactMe@xxxxxxxxxxxxxx>
- Date: Sun, 14 Jan 2007 10:05:22 +0100
This is a VB6 forum. Your code looks like C++.
"Purusothaman A" <Purusothaman.A@xxxxxxxxx> wrote in message
news:1168677357.286301.267690@xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
Hi all,
I am trying to creating user accounts in Windows XP thru VC++
programming.
Below I have pasted 2 function implementation which of one gives
available login names and another creates new login account.
My problem is, the CreateUserAccount() function creates new account
successfully, but ControlPanel->User Account does not show my program
created new accounts. And also in windows login screen does not show my
new accounts.
But GetLoginNames() gives new account name also.
Whats going on wrong?
/*
My GetLoginNames() function includes service accounts. i.e., (daemon
service accounts like postgres).
I just want this function to give only login user accounts not
service and other kind of login names.
*/
Thanks in advance.
:)
Purusothaman A
#include <lm.h>
#pragma comment(lib, "Netapi32.lib")
void GetLoginNames(CArray<CString, CString&> &arrLoginNames)
{
LPUSER_INFO_1 pBuf = NULL;
LPUSER_INFO_1 pTmpBuf;
DWORD dwLevel = 1;
DWORD dwPrefMaxLen = MAX_PREFERRED_LENGTH;
DWORD dwEntriesRead = 0;
DWORD dwTotalEntries = 0;
DWORD dwResumeHandle = 0;
DWORD i;
DWORD dwTotalCount = 0;
NET_API_STATUS nStatus;
LPWSTR pszServerName = NULL;
INT_PTR iCnt = 0;
//
// Call the NetUserEnum function, specifying level 0;
// enumerate global user account types only.
//
do // begin do
{
nStatus = NetUserEnum(pszServerName,
dwLevel,
FILTER_NORMAL_ACCOUNT, // global users
(LPBYTE*)&pBuf,
dwPrefMaxLen,
&dwEntriesRead,
&dwTotalEntries,
&dwResumeHandle);
//
// If the call succeeds,
//
if ((nStatus == NERR_Success) || (nStatus == ERROR_MORE_DATA))
{
if ((pTmpBuf = pBuf) != NULL)
{
//
// Loop through the entries.
//
for (i = 0; (i < dwEntriesRead); i++)
{
if (pTmpBuf == NULL)
{
return;
}
//
// copying the name of the user account.
//
if((pTmpBuf->usri1_flags & UF_ACCOUNTDISABLE) !=
UF_ACCOUNTDISABLE)
{
CString sLoginName;
sLoginName = pTmpBuf->usri1_name;
arrLoginNames.Add(sLoginName);
}
pTmpBuf++;
dwTotalCount++;
}
}
}
//
// Free the allocated buffer.
//
if (pBuf != NULL)
{
NetApiBufferFree(pBuf);
pBuf = NULL;
}
}
// Continue to call NetUserEnum while
// there are more entries.
//
while (nStatus == ERROR_MORE_DATA); // end do
//
// Check again for allocated memory.
//
if (pBuf != NULL)
NetApiBufferFree(pBuf);
}
NET_API_STATUS CreateUserAccount(LPWSTR sUserName, LPWSTR sPassword,
DWORD &dwError)
{
USER_INFO_1 ui;
DWORD dwLevel = 1;
NET_API_STATUS nStatus;
dwError = 0;
//
// Set up the USER_INFO_1 structure.
// USER_PRIV_USER: name identifies a user,
// rather than an administrator or a guest.
// UF_SCRIPT: required for LAN Manager 2.0 and
// Windows NT and later.
//
ui.usri1_name = sUserName;
ui.usri1_password = sPassword;
ui.usri1_priv = USER_PRIV_USER;
ui.usri1_home_dir = NULL;
ui.usri1_comment = NULL;
ui.usri1_flags = UF_SCRIPT;
ui.usri1_script_path = NULL;
//
// Call the NetUserAdd function, specifying level 1.
//
nStatus = NetUserAdd(NULL/*Local Machine*/,
dwLevel,
(LPBYTE)&ui,
&dwError);
return nStatus;
}
.
- Prev by Date: Alpha Blended Windows in Vista
- Next by Date: MapVirtualKeyEx
- Previous by thread: Alpha Blended Windows in Vista
- Next by thread: MapVirtualKeyEx
- Index(es):
Relevant Pages
|
Loading