How to get Logged in user name using my own windows service application
-
Hello, I am developing a windows service in VC++.Net2005 on windows XP. I want the end product should be portable to all the windows OS(atleast to win98,Me,2K,XP and Vista). In my windows service (which runs on Local System means as System's service), there is a requirement to access the current login user name. To get that i am using the GetUserName() of win32 API, but with this, i am only getting the Login-name as "SYSTEM" ( probably because of the reason that, my windows service is running in System's area(local system)). Is it feasible to get the current login name instead of getting the user in which the my windows service is running. If possible.. any clues.. Thank you
Anee
-
Hello, I am developing a windows service in VC++.Net2005 on windows XP. I want the end product should be portable to all the windows OS(atleast to win98,Me,2K,XP and Vista). In my windows service (which runs on Local System means as System's service), there is a requirement to access the current login user name. To get that i am using the GetUserName() of win32 API, but with this, i am only getting the Login-name as "SYSTEM" ( probably because of the reason that, my windows service is running in System's area(local system)). Is it feasible to get the current login name instead of getting the user in which the my windows service is running. If possible.. any clues.. Thank you
Anee
-
Hello, I am developing a windows service in VC++.Net2005 on windows XP. I want the end product should be portable to all the windows OS(atleast to win98,Me,2K,XP and Vista). In my windows service (which runs on Local System means as System's service), there is a requirement to access the current login user name. To get that i am using the GetUserName() of win32 API, but with this, i am only getting the Login-name as "SYSTEM" ( probably because of the reason that, my windows service is running in System's area(local system)). Is it feasible to get the current login name instead of getting the user in which the my windows service is running. If possible.. any clues.. Thank you
Anee
Be very careful doing this. There are a number of issues that you must address. What if the user hasn't signed on yet? What if you have two users logged on at the same time and they are going back and forth using Fast User Switching? What if the user logs off? Judy
-
Hello, I am developing a windows service in VC++.Net2005 on windows XP. I want the end product should be portable to all the windows OS(atleast to win98,Me,2K,XP and Vista). In my windows service (which runs on Local System means as System's service), there is a requirement to access the current login user name. To get that i am using the GetUserName() of win32 API, but with this, i am only getting the Login-name as "SYSTEM" ( probably because of the reason that, my windows service is running in System's area(local system)). Is it feasible to get the current login name instead of getting the user in which the my windows service is running. If possible.. any clues.. Thank you
Anee
the hkey_local_machine is available from registry.. you canĀ HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Winlogon for current logged on user + plus you need to write Winlogon Notification Package for same!
"Opinions are neither right nor wrong. I cannot change your opinion. I can, however, change what influences your opinion." - David Crow
cheers, Alok Gupta Global Interface Table: An Easy Way to Marshal an Interface Pointer[new] VC Forum Q&A :- I/ IV Support CRY- Child Relief and You
-
Be very careful doing this. There are a number of issues that you must address. What if the user hasn't signed on yet? What if you have two users logged on at the same time and they are going back and forth using Fast User Switching? What if the user logs off? Judy
Hello friends... Thanks for your comments. I am taking help from the following article provided with Codeproject: http://www.codeproject.com/vb/net/Windows\_Service.asp What i understand from this is, we can have access to the WMI. This WMI shows all the information regarding the various processes running in machine. As i want to get the username in which i am currently logged-in, So, i am using the Win32_Process (which gives the name of process explorer... and the substring of, name of process explorer contains the currently logged-in username(eg.. user_nameprocess.exe) . Using string operations... i am trying to extract that particular username part of the process explorer name. Now,Taking help of this, i have added System.Management reference to my project (VC++.NET/windows XP) and then i got two files namely ROOT.CIMV2.Win32_Process.h/cpp with my project name. And in the ROOT.CIMV2.Win32_Process.cpp contains following lines of code: #include Stdafx.h #include ROOT.CIMV2.Win32_Process.h After this i added System refrence through the project properties. But while building this project, i am getting some errors in these new files ROOT.CIMV2.Win32_Process.h/cpp. and command line options are: C/C++ Command line options: /Od /D "WIN32" /D "_DEBUG" /D "_CONSOLE" /D "_UNICODE" /D "UNICODE" /FD /EHa /MDd /Yu"stdafx.h" /Fp"Debug\myservice.pch" /Fo"Debug\\" /Fd"Debug\vc80.pdb" /W0 /nologo /c /Zi /clr:pure /TP /errorReport:prompt /FU "c:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\System.Management.dll" /FU "c:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\System.dll" Linker Command Line Options: /OUT:"D:\Apr\2\myservice\Debug\myservice.exe" /INCREMENTAL /NOLOGO /MANIFEST /MANIFESTFILE:"Debug\myservice.exe.intermediate.manifest" /DEBUG /ASSEMBLYDEBUG /PDB:"d:\Apr\2\myservice\debug\myservice.pdb" /SUBSYSTEM:CONSOLE /MACHINE:X86 /FIXED:No /ERRORREPORT:PROMPT setupapi.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib And stdafx.h file looks like this: #pragma once #define WIN32_LEAN_AND_MEAN // Exclude rarely-used stuff from Windows headers // TODO: reference additional headers your program requires here #define _AFXDLL /*I included this, bcoz if i don't, then i m getting an build error: D:\Microsoft Visual Studio 8\VC\atlmfc\include\afx.h(24) : fatal error C1189: #error : Building MFC application with /MD[d] (CRT dll version) requires MFC shared dll version.