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#
  4. logged in username in windows service

logged in username in windows service

Scheduled Pinned Locked Moved C#
databasecomquestionworkspace
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.
  • P Offline
    P Offline
    P S Pundeer
    wrote on last edited by
    #1

    I am creating a windows service where the employees get automatically logged into database when they start their computer. For this my service require the windows logged in username. Environment.UserName is not working. Is there any other tried solution?

    puranonnet@hotmail.com www.ibrinte.com

    S 1 Reply Last reply
    0
    • P P S Pundeer

      I am creating a windows service where the employees get automatically logged into database when they start their computer. For this my service require the windows logged in username. Environment.UserName is not working. Is there any other tried solution?

      puranonnet@hotmail.com www.ibrinte.com

      S Offline
      S Offline
      Simon P Stevens
      wrote on last edited by
      #2

      System.Security.Principal.WindowsIdentity.GetCurrent().Name will get you the user that the service is running as, but services generally run under special user accounts like "Local Service". Services also start before the user logs on so you can't just set it to run under the currently logged on user, because there might not be one. Services aren't really meant to be tied to the logged on user. What would happen if you had two users logged on at the same time (which can happen). Perhaps you should consider making your app a normal client based app (but with no GUI) and stick a short cut to it in the start up menu. You should also probably be using windows authentication instead of getting the user name.

      Simon

      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