Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. getting username from windows service in VC++.Net2005

getting username from windows service in VC++.Net2005

Scheduled Pinned Locked Moved C / C++ / MFC
csharpc++help
1 Posts 1 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • A Offline
    A Offline
    anumadhu
    wrote on last edited by
    #1

    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

    1 Reply Last reply
    0
    Reply
    • Reply as topic
    Log in to reply
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes


    • Login

    • Don't have an account? Register

    • Login or register to search.
    • First post
      Last post
    0
    • Categories
    • Recent
    • Tags
    • Popular
    • World
    • Users
    • Groups