getting username from windows service in VC++.Net2005
-
I have a windows service application. Created in windows XP and vc++.Net2005. I want this to make it work on windows 95,98,2K,XP and Vista. I want to get the username of the current logged-in user or users(if the user is switching between more than once loggin on the same machine) I have implemented it in this format: Added the refrences to my project that is using project properties from the toolbar. Now, wrote in this way: CString Get_Username() { CString Username=_T(""); System::Management::ManagementObjectSearcher q = gcnew System::Management::ManagementObjectSearcher("Select * from Win32_Process"); System::Management::ManagementObjectCollection mc = q.Get(); System::Management::ManagementObject mo = mc.GetEnumerator(); while(!mo) { Username = mo("username"); mo.Get(mc); } return Username; } i am getting the following compilation errors: .\DataSentinelService.cpp(80) : error C2664: 'System::Management::ManagementObjectSearcher::ManagementObjectSearcher(System::String ^)' : cannot convert parameter 1 from 'System::Management::ManagementObjectSearcher ^' to 'System::String ^' No user-defined-conversion operator available, or Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast .\myservice.cpp(81) : error C3673: 'System::Management::ManagementObjectCollection' : class does not have a copy-constructor .\myservice.cpp(82) : error C2664: 'System::Management::ManagementObject::ManagementObject(System::Management::ManagementPath ^)' : cannot convert parameter 1 from 'System::Management::ManagementObjectCollection::ManagementObjectEnumerator ^' to 'System::Management::ManagementPath ^' No user-defined-conversion operator available, or Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast .\myservice.cpp(84) : error C2088: '!' : illegal for class .\myservice.cpp(84) : fatal error C1903: unable to recover from previous error(s); stopping compilation I have also tested by placing the following lines in the starting of my myservice.cpp file: using namespace System; using namespace System::Management; But still the same kind of errors persists. I have even searched on net to get the exact cause of error/problem. In the msdn also, the code samples are given for VB.Net/C# but not for vc++/C++. Any idea please... Thanks in advance Anee