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. Visual Basic
  4. Get User Name

Get User Name

Scheduled Pinned Locked Moved Visual Basic
13 Posts 6 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.
  • Y Yuvi Panda

    Well, in VB 2005, this single line of code works :

    My.User.Name

    This returns the Name of the User under which the current process is running Yuvi Panda T Microsoft Student Partner Blogs at : http://yuvipanda.blogspot.com

    N Offline
    N Offline
    nitin_ion
    wrote on last edited by
    #4

    But I am using VS2003. do you know how to get the user name for a process in 2003

    Y 1 Reply Last reply
    0
    • A albCode

      Do you mean get current username logged in PC? If so : using System.Security.Partial; . . . . string username = System.WindowsIdentity.GetCurrent().Name.Tostring(); it gives DomainName\Username

      N Offline
      N Offline
      nitin_ion
      wrote on last edited by
      #5

      I want the user name of the process and not the user who is logged in.

      J 1 Reply Last reply
      0
      • N nitin_ion

        But I am using VS2003. do you know how to get the user name for a process in 2003

        Y Offline
        Y Offline
        Yuvi Panda
        wrote on last edited by
        #6

        Not sure, but I guess this should help:

        System.Security.Principal.WindowsIdentity.GetCurrent().Name

        Yuvi Panda T 15 Year Old Microsoft Student Partner Blogs at : http://yuvipanda.blogspot.com

        N 2 Replies Last reply
        0
        • Y Yuvi Panda

          Not sure, but I guess this should help:

          System.Security.Principal.WindowsIdentity.GetCurrent().Name

          Yuvi Panda T 15 Year Old Microsoft Student Partner Blogs at : http://yuvipanda.blogspot.com

          N Offline
          N Offline
          nitin_ion
          wrote on last edited by
          #7

          This will again get Logged on user name.

          A 1 Reply Last reply
          0
          • N nitin_ion

            This will again get Logged on user name.

            A Offline
            A Offline
            albCode
            wrote on last edited by
            #8

            check this article http://www.eggheadcafe.com/articles/20011015.asp

            1 Reply Last reply
            0
            • Y Yuvi Panda

              Not sure, but I guess this should help:

              System.Security.Principal.WindowsIdentity.GetCurrent().Name

              Yuvi Panda T 15 Year Old Microsoft Student Partner Blogs at : http://yuvipanda.blogspot.com

              N Offline
              N Offline
              nitin_ion
              wrote on last edited by
              #9

              Thanx, but This article is telling how to kill a process and not how to list the username of the process.

              1 Reply Last reply
              0
              • N nitin_ion

                Is there a way i can get the user name associated with the processes just like in task manager.

                J Offline
                J Offline
                Jim Matthews
                wrote on last edited by
                #10

                if you're working on a win 2k, xp or 2k3 machine, check into the system.management namespace. it allows you to connect to wmi which has the information you need.


                -jim

                1 Reply Last reply
                0
                • N nitin_ion

                  Is there a way i can get the user name associated with the processes just like in task manager.

                  D Offline
                  D Offline
                  Dave Kreskowiak
                  wrote on last edited by
                  #11

                  The Process class doesn't expose this functionality. The best method, like Jim said, would be to use WMI and the Win32_Process[^] class. Once you get the list of Win32_Process objects, call the GetOwner method on each one to get the information you need. Dave Kreskowiak Microsoft MVP - Visual Basic

                  N 1 Reply Last reply
                  0
                  • N nitin_ion

                    I want the user name of the process and not the user who is logged in.

                    J Offline
                    J Offline
                    Jared Parsons
                    wrote on last edited by
                    #12

                    The code snippet that was posted will give you the name of the user running the process. It is usually but not always the person who is logged in. Jared Parsons jaredp@beanseed.org http://jaredparsons.blogspot.com/[^]

                    1 Reply Last reply
                    0
                    • D Dave Kreskowiak

                      The Process class doesn't expose this functionality. The best method, like Jim said, would be to use WMI and the Win32_Process[^] class. Once you get the list of Win32_Process objects, call the GetOwner method on each one to get the information you need. Dave Kreskowiak Microsoft MVP - Visual Basic

                      N Offline
                      N Offline
                      nitin_ion
                      wrote on last edited by
                      #13

                      Thanx

                      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