HKEY_CURRENT_USER\Software\\Microsoft\\Windows\\CurrentVersion\\Explorer\ logon User Name cannot access from system process
-
hai all HKEY_CURRENT_USER\Software\\Microsoft\\Windows\\CurrentVersion\\Explorer\ logon User Name cannot access from system process I use the following code LPCSTR szKey = _T("Software\\Microsoft\\Windows\\CurrentVersion\\Explorer"); LPCSTR szValueName = _T("Logon User Name"); //open the registry key lRet = RegOpenKeyEx( HKEY_CURRENT_USER, szKey, 0, KEY_QUERY_VALUE, &hSubKey ); if( lRet == ERROR_SUCCESS) { dwBufLen = 256; lRet = RegQueryValueEx( hSubKey, szValueName, NULL, NULL, (LPBYTE) szValue, &dwBufLen); } pls help me Advance thanks
-
hai all HKEY_CURRENT_USER\Software\\Microsoft\\Windows\\CurrentVersion\\Explorer\ logon User Name cannot access from system process I use the following code LPCSTR szKey = _T("Software\\Microsoft\\Windows\\CurrentVersion\\Explorer"); LPCSTR szValueName = _T("Logon User Name"); //open the registry key lRet = RegOpenKeyEx( HKEY_CURRENT_USER, szKey, 0, KEY_QUERY_VALUE, &hSubKey ); if( lRet == ERROR_SUCCESS) { dwBufLen = 256; lRet = RegQueryValueEx( hSubKey, szValueName, NULL, NULL, (LPBYTE) szValue, &dwBufLen); } pls help me Advance thanks
vicky00000 wrote:
LPCSTR szKey = _T("Software\\Microsoft\\Windows\\CurrentVersion\\Explorer"); LPCSTR szValueName = _T("Logon User Name");
The above should be
LPCTSTR szKey = _T("Software\\Microsoft\\Windows\\CurrentVersion\\Explorer");
LPCTSTR szValueName = _T("Logon User Name");And the code shown lacks some definitions like the one of the buffer (probably they are already present in your program, I don't know), anyway, the following code (practically identical to yours) is working fine on my system (XP):
TCHAR szValue[256];
LPCTSTR szKey = _T("Software\\Microsoft\\Windows\\CurrentVersion\\Explorer");
LPCTSTR szValueName = _T("Logon User Name");
HKEY hSubKey;
//open the registry key
LRESULT lRet = RegOpenKeyEx( HKEY_CURRENT_USER, szKey, 0, KEY_QUERY_VALUE, &hSubKey );
if( lRet == ERROR_SUCCESS)
{
DWORD dwBufLen = 256;
Ret = RegQueryValueEx( hSubKey, szValueName, NULL, NULL,(LPBYTE) szValue, &dwBufLen);
}BTW whenever RegQueryValueEx fails is worthy to give a look at reported error. :)
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler. -- Alfonso the Wise, 13th Century King of Castile.
[my articles] -
vicky00000 wrote:
LPCSTR szKey = _T("Software\\Microsoft\\Windows\\CurrentVersion\\Explorer"); LPCSTR szValueName = _T("Logon User Name");
The above should be
LPCTSTR szKey = _T("Software\\Microsoft\\Windows\\CurrentVersion\\Explorer");
LPCTSTR szValueName = _T("Logon User Name");And the code shown lacks some definitions like the one of the buffer (probably they are already present in your program, I don't know), anyway, the following code (practically identical to yours) is working fine on my system (XP):
TCHAR szValue[256];
LPCTSTR szKey = _T("Software\\Microsoft\\Windows\\CurrentVersion\\Explorer");
LPCTSTR szValueName = _T("Logon User Name");
HKEY hSubKey;
//open the registry key
LRESULT lRet = RegOpenKeyEx( HKEY_CURRENT_USER, szKey, 0, KEY_QUERY_VALUE, &hSubKey );
if( lRet == ERROR_SUCCESS)
{
DWORD dwBufLen = 256;
Ret = RegQueryValueEx( hSubKey, szValueName, NULL, NULL,(LPBYTE) szValue, &dwBufLen);
}BTW whenever RegQueryValueEx fails is worthy to give a look at reported error. :)
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler. -- Alfonso the Wise, 13th Century King of Castile.
[my articles]Thanks ur reply, My code is exactly like u mentioned. This code will work correctly while it run by a normal process . It shows error while it run as system process. The error it shows is ERROR_FILE_NOT_FOUND
-
Thanks ur reply, My code is exactly like u mentioned. This code will work correctly while it run by a normal process . It shows error while it run as system process. The error it shows is ERROR_FILE_NOT_FOUND
vicky00000 wrote:
t shows error while it run as system process
Do you mean a service?
vicky00000 wrote:
The error it shows is ERROR_FILE_NOT_FOUND
MSDN http://msdn2.microsoft.com/en-us/library/ms724911(VS.85).aspx[^] states: If lpValueName specifies a key that is not in the registry, the function returns ERROR_FILE_NOT_FOUND. Hence the service is not able to se this entry (or the entry there isn't when the service runs). But those are only poor hypothesis: I'm not an expert about, maybe you can also ask the OS/SysAdimn forum. :)
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler. -- Alfonso the Wise, 13th Century King of Castile.
[my articles] -
hai all HKEY_CURRENT_USER\Software\\Microsoft\\Windows\\CurrentVersion\\Explorer\ logon User Name cannot access from system process I use the following code LPCSTR szKey = _T("Software\\Microsoft\\Windows\\CurrentVersion\\Explorer"); LPCSTR szValueName = _T("Logon User Name"); //open the registry key lRet = RegOpenKeyEx( HKEY_CURRENT_USER, szKey, 0, KEY_QUERY_VALUE, &hSubKey ); if( lRet == ERROR_SUCCESS) { dwBufLen = 256; lRet = RegQueryValueEx( hSubKey, szValueName, NULL, NULL, (LPBYTE) szValue, &dwBufLen); } pls help me Advance thanks
So what's failing?
"Normal is getting dressed in clothes that you buy for work and driving through traffic in a car that you are still paying for, in order to get to the job you need to pay for the clothes and the car and the house you leave vacant all day so you can afford to live in it." - Ellen Goodman
"To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne
-
hai all HKEY_CURRENT_USER\Software\\Microsoft\\Windows\\CurrentVersion\\Explorer\ logon User Name cannot access from system process I use the following code LPCSTR szKey = _T("Software\\Microsoft\\Windows\\CurrentVersion\\Explorer"); LPCSTR szValueName = _T("Logon User Name"); //open the registry key lRet = RegOpenKeyEx( HKEY_CURRENT_USER, szKey, 0, KEY_QUERY_VALUE, &hSubKey ); if( lRet == ERROR_SUCCESS) { dwBufLen = 256; lRet = RegQueryValueEx( hSubKey, szValueName, NULL, NULL, (LPBYTE) szValue, &dwBufLen); } pls help me Advance thanks
Did you get any error or null result?
-
hai all HKEY_CURRENT_USER\Software\\Microsoft\\Windows\\CurrentVersion\\Explorer\ logon User Name cannot access from system process I use the following code LPCSTR szKey = _T("Software\\Microsoft\\Windows\\CurrentVersion\\Explorer"); LPCSTR szValueName = _T("Logon User Name"); //open the registry key lRet = RegOpenKeyEx( HKEY_CURRENT_USER, szKey, 0, KEY_QUERY_VALUE, &hSubKey ); if( lRet == ERROR_SUCCESS) { dwBufLen = 256; lRet = RegQueryValueEx( hSubKey, szValueName, NULL, NULL, (LPBYTE) szValue, &dwBufLen); } pls help me Advance thanks
In the registry, the current user would be the account you're running from - the system account. See LocalSystem Account[^] Are you trying to get the name of the current logged-on user from a service running in a system account? Mark
Mark Salsbery Microsoft MVP - Visual C++ :java:
-
In the registry, the current user would be the account you're running from - the system account. See LocalSystem Account[^] Are you trying to get the name of the current logged-on user from a service running in a system account? Mark
Mark Salsbery Microsoft MVP - Visual C++ :java:
yes .................
-
yes .................