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. Managed C++/CLI
  4. using the System::Collections::IEnumerator()

using the System::Collections::IEnumerator()

Scheduled Pinned Locked Moved Managed C++/CLI
csharpc++help
2 Posts 2 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

    Hello, I am trying to get current login user name using my own windows service program using VC++.Net 2005, windows XP. The code used to develop windows service contains only unmanaged one. But in order to retrieve the current login name.. i am using the help of System::Management class, for which i included necessary namespaces in its .cpp file. actually i am trying interpret the following statement of c# into c++: System::Management::Collections mc; foreach(System::Management::Object mo in mc){..do this..} my approach was somewhat like this in the following way: CString CUSBActivity::Get_User_Name() { CString Username=_T(""); System::Management::ManagementObjectSearcher^ q = nullptr; System::Management::ManagementObjectCollection^ mc = nullptr; System::Management::ManagementObject^ mo = nullptr; System::Collections::IEnumerator^ enu = nullptr; q = gcnew System::Management::ManagementObjectSearcher("Select * from Win32_Process"); mc = q->Get(); enu = mc->GetEnumerator(); mo = (System::Management::ManagementObject^)enu->Current; while(enu->MoveNext()) { DebugBreak(); mo = (System::Management::ManagementObject ^)enu->GetType(); Username = mo["username"]->ToString(); mc->GetEnumerator()->MoveNext(); } return Username; } But when i run this, i am getting the run time exception and the Username is null. Could anybody... assist me in fixing this thank u. Anee

    M 1 Reply Last reply
    0
    • A anumadhu

      Hello, I am trying to get current login user name using my own windows service program using VC++.Net 2005, windows XP. The code used to develop windows service contains only unmanaged one. But in order to retrieve the current login name.. i am using the help of System::Management class, for which i included necessary namespaces in its .cpp file. actually i am trying interpret the following statement of c# into c++: System::Management::Collections mc; foreach(System::Management::Object mo in mc){..do this..} my approach was somewhat like this in the following way: CString CUSBActivity::Get_User_Name() { CString Username=_T(""); System::Management::ManagementObjectSearcher^ q = nullptr; System::Management::ManagementObjectCollection^ mc = nullptr; System::Management::ManagementObject^ mo = nullptr; System::Collections::IEnumerator^ enu = nullptr; q = gcnew System::Management::ManagementObjectSearcher("Select * from Win32_Process"); mc = q->Get(); enu = mc->GetEnumerator(); mo = (System::Management::ManagementObject^)enu->Current; while(enu->MoveNext()) { DebugBreak(); mo = (System::Management::ManagementObject ^)enu->GetType(); Username = mo["username"]->ToString(); mc->GetEnumerator()->MoveNext(); } return Username; } But when i run this, i am getting the run time exception and the Username is null. Could anybody... assist me in fixing this thank u. Anee

      M Offline
      M Offline
      Mark Salsbery
      wrote on last edited by
      #2

      In your while loop you do this: mo = (System::Management::ManagementObject ^)enu->GetType(); That doesn't look like a valid cast to me. Did you mean mo = (System::Management::ManagementObject ^)enu->Current; ?? What line is the exception occurring on? Mark

      "Posting a VB.NET question in the C++ forum will end in tears." Chris Maunder

      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