Service:Determine current windows login user?

  • Know its a SQL forum.

    Got a service running and the service needs to determine if a user is login. Service is running under local sys admin account (Windows 2000). If not logged in, user gets notified through a messagebox of an action being performed by the service. If logged in then normal service window gets displayed.

    Any suggestions?

  • There is quite possibly a better idea, but what about the USERNAME environment variable?

    Hope this helps

    Phill Carter

    --------------------

    Colt 45 - the original point and click interface

    --------------------
    Colt 45 - the original point and click interface

  • Hi 5409045121009

    quote:


    Got a service running and the service needs to determine if a user is login. Service is running under local sys admin account (Windows 2000). If not logged in, user gets notified through a messagebox of an action being performed by the service. If logged in then normal service window gets displayed.

    Any suggestions?


    if you want to determine if someone is logged onto a computer, you can use 'net session'. Will give you a list of resources. You can capture the output into a file and search this file for your criteria. AFAIK, this will only work on local computers, so I guess directly on the server.

    For remote stuff take a look at

    http://www.sysinternals.com/ntw2k/freeware/psloggedon.shtml

    HTH

    Frank

    http://www.insidesql.de

    --
    Frank Kalis
    Microsoft SQL Server MVP
    Webmaster: http://www.insidesql.org/blogs
    My blog: http://www.insidesql.org/blogs/frankkalis/[/url]

  • Thanks for the replies.

    Phillcart I suspects if the service 'looks' at the environment variable for its thread/shell it will see SYSTEM. I will defnitely give it a try.

    Frank thanks for 'NetSessionEnum' will investigate the idea further.

  • Hi 5409045121009,

    well, consider this a WAG, but AFAIK Windows loads the profile of the currently logged on user into registry. So you should be able to query the registry for this information. As I don't know the actual key you need to google on this.

    I'm pretty sure that I have seen source code on planetsourcecode.com or codeproject.com or codeguru.com.

    HTH

    Frank

    http://www.insidesql.de

    --
    Frank Kalis
    Microsoft SQL Server MVP
    Webmaster: http://www.insidesql.org/blogs
    My blog: http://www.insidesql.org/blogs/frankkalis/[/url]

  • Found another reference at

    http://www.experts-exchange.com/Programming/Programming_Languages/Visual_Basic/Q_20413027.html

    Talk about jumping through hoops to achieve something.

    I only needs the bit upto

    Public Function loggedusername() As String
    
    Dim tok As Long
    Dim ret As Long
    Dim hprocess As Long
    Dim rr As Long
    Dim explpid As Long
    explpid = explorerpid ' get ProcessID of explorer.exe
    If explpid = -1 Then loggedusern = "NO USER": Exit Function ' if explorer is not found, nobody is logged on

    I am running out of time and will try all till at least one provide the solution.

    Thanks

  • After searching BOL for a solution I came up with this after correcting the example code and testing it in the query analyzer:

    DECLARE @usr char(30)

    SET @usr = user

    SELECT 'The current user''s database username is: ' + @usr

    GO

  • Don't think it's suitable since it is run from SQL Server but you might be interested in

    CREATE VIEW USERINFO

    AS

    SELECT hostname, program_name, nt_username, net_address,

    net_library, loginame, nt_domain

    FROM master.dbo.sysprocesses

    WHERE (hostname IS NOT NULL)

    Please do not poke the DBA


    The systems fine with no users loggged in. Can we keep it that way ?br>

Viewing 8 posts - 1 through 7 (of 7 total)

You must be logged in to reply to this topic. Login to reply