How to send values to UserName and Password Textboxes in "Log on to Windows" Dlg

hi all,
I want to send values to User Name and Password in "Windows 2000 Professional Log on Dialog" by Programmetically(Using C# or C++).
I need to avoid appearing windows Login Box.Then I don't need to enter user name and pw again and again..
Can any one help me??
[288 byte] By [pubudu] at [2007-11-19 8:42:27]
# 1 Re: How to send values to UserName and Password Textboxes in "Log on to Windows" Dlg
Unlike Win9x, in NT (Win2K, XP, etc.), you don't have to set it in the logon dialog, you set it in the registry.

These settings are in the registry under "HKLM\Software\Microsoft\Windows NT\CurrentVersion\Winlogon"

Below is a small code snippet that programmatically sets them for you.

Arjay


#define ValueAutoAdminLogon _T("AutoAdminLogon")
#define ValueDefaultPassword _T("DefaultPassword")
#define ValueLogonEnable _T("1")
#define ValueDefaultUserName _T("DefaultUserName")
#define ValueDefaultDomainName _T("DefaultDomainName")
#define ValueAltDefaultUserName _T("AltDefaultUserName")
#define ValueAltDefaultDomainName _T("AltDefaultDomainName")
#define ValueCachePrimaryDomain _T("CachePrimaryDomain")
#define SubKeyWinLogonNT
_T("Software\\Microsoft\\Windows NT\\CurrentVersion\\Winlogon")

HRESULT SetNTAutoLogon( IN const CString& sPassword )
{
HRESULT hr = S_OK;
CString sUserName;
CString sDomainName;
DWORD dwSize = UNLEN;

//Retrieve the logged on User
GetUserName( sUserName.GetBuffer( UNLEN ), &dwSize );
sUserName.ReleaseBuffer();

//Retrieve the Current domain
dwSize = UNLEN;
GetEnvironmentVariable( _T("USERDOMAIN"),
sDomainName.GetBuffer( UNLEN), dwSize );

// Make the registry settings
CRegKey rk;
if(SUCCEEDED(hr = rk.Open( HKEY_LOCAL_MACHINE,
SubKeyWinLogonNT,
KEY_ALL_ACCESS)))
{
//Set the AutoAdminValue to 1
if(FAILED(hr = rk.SetStringValue( ValueAutoAdminLogon, _T("1") )))
{
return hr;
}

//Set the Password key
if(FAILED(hr = rk.SetStringValue( ValueDefaultPassword, sPassword )))
{
return hr;
}

// Set the User Name and Domain
if(FAILED(hr = rk.SetStringValue( ValueDefaultUserName, sUserName ) ))
{
return hr;
}

if(FAILED(hr = rk.SetStringValue( ValueDefaultDomainName,
sDomainName ) ))
{
return hr;
}

// Set the Alt User Name and Alt Domain
if(FAILED(hr = rk.SetStringValue( ValueAltDefaultUserName,
sUserName ) ))
{
return hr;
}

if(FAILED(hr = rk.SetStringValue( ValueAltDefaultDomainName,
sDomainName ) ))
{
return hr;
}

// Set the CachePrimaryDomain Name
if(FAILED(hr = rk.SetStringValue( ValueCachePrimaryDomain,
sDomainName ) ))
{
return hr;
}
}
return hr;
}
Arjay at 2007-11-10 3:40:33 >
# 2 Re: How to send values to UserName and Password Textboxes in "Log on to Windows" Dlg
There is no need to write the program to do this jop.

Only three steps you want to do

what you want to do is

1.Open the control panel
2.Open the users and passwords
3.Then uncheck the Users must enter a username and password to enter this computer.

That's all over.

Logoff the computer and check the process.
sivadhas at 2007-11-10 3:41:33 >
# 3 Re: How to send values to UserName and Password Textboxes in "Log on to Windows" Dlg
I can not uncheck it.Because it is not displaying when My computer in a Domain..But the check Box is displaying when computer is in a Work Group only.
pubudu at 2007-11-10 3:42:37 >
# 4 Re: How to send values to UserName and Password Textboxes in "Log on to Windows" Dlg
I can not uncheck it.Because it is not displaying when My computer in a Domain..But the check Box is displaying when computer is in a Work Group only.When running in a domain, the code I attached earlier will work. Keep in mind that you don't need to actually run the code, you just need to make the registry changes yourself with regedit.

Arjay
Arjay at 2007-11-10 3:43:31 >