Re: ControlPanel->User Account does not show new accounts created by my program .



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;
}



.



Relevant Pages

  • Re: Windows XP Home, Missing User accounts on Log in
    ... My machine boots up to login like yours but I ... > have any other accounts. ... >> user accounts, mine being the only administrator. ...
    (microsoft.public.windowsxp.help_and_support)
  • Re: xp and outlook express
    ... Did you check for the DWORD entry & value in the user accounts, ... >> Is MS Outlook also installed? ... even if you don't use it (can happen with the install of ...
    (microsoft.public.windows.inetexplorer.ie6_outlookexpress)
  • Re: Upgrade to XP SP2, now OE wont work
    ... Try one or more of your accounts in a new Named Identity ... > After installing SP2 I also installed Microsoft Office Pro ... DWORD was not present. ...
    (microsoft.public.windows.inetexplorer.ie6_outlookexpress)
  • Re: No User Accounts Appear on the Welcome Screen
    ... This sounds an aweful lot like the accounts have been disabled through the ... Perform this check for each misbehaving login. ... exact name of one of the the user accounts that's missing. ... MS-MVP Windows XP/ Windows Smart Display ...
    (microsoft.public.windowsxp.security_admin)
  • File access on remote workstation
    ... I have a small workgroup consisting of several Win2k Pro SP4 workstations. ... Each workstation has 3 identical user accounts. ... If I login as Administrator Drive l: ...
    (microsoft.public.win2000.networking)

Loading