Jump to content

Recommended Posts

Posted

my script run as service.

@username return "SYSTEM"

my question: how to get to current username or access to his HKCU from my service?

MS says in LocalSystem account, the registry key HKEY_CURRENT_USER is associated with the default user, not the current user. To access another user's profile, impersonate the user

any help please ?

Posted

;-) Your two Avatars below each other are really giving a funny combination:

- a beatuiful lady

- a bit-byte-keyboard maniac without face

<scnr>

;-)

Earth is flat, pigs can fly, and Nuclear Power is SAFE!

Posted

I do not know the solution, but just want to add a possible gap in the solution.

Keep in mind, that maybe multiple users are logged in (not often but possible)

But in the Win32_LogonSession Class you may find something to help you

http://msdn.microsoft.com/en-us/library/aa394189%28VS.85%29.aspx

I will try it with my service.....and it worked:

I used a VBS like this

Start it with: cscript getuser.vbs //nologo

strComputer = "."   ' " use "." for local computer

Set objWMI = GetObject("winmgmts:" _
              & "{impersonationLevel=impersonate}!\\" _
              & strComputer & "\root\cimv2")

Set colSessions = objWMI.ExecQuery _
    ("Select * from Win32_LogonSession Where LogonType = 2 OR LogonType = 10")

If colSessions.Count = 0 Then
   Wscript.Echo "No interactive users found"
Else
   For Each objSession in colSessions
     Set colList = objWMI.ExecQuery("Associators of " _
         & "{Win32_LogonSession.LogonId=" & objSession.LogonId & "} " _
         & "Where AssocClass=Win32_LoggedOnUser Role=Dependent" )

     For Each objItem in colList
       WScript.Echo "User: " & objItem.Name
       WScript.Echo "FullName: " & objItem.FullName
       WScript.Echo "Domain: " & objItem.Domain
     Next
     Wscript.Echo "Session start time: " & objSession.StartTime
   Next
End If

I tested this script running as a service with Windows XP Pro (Sp2). User was System while the .vbs gave me the logged in user. And if two or more users are logged in at the same pc, you will get all users from the vbs.

Maybe there is a autoit function/udf?

Posted (edited)

Holy.....

Even more simple:

There is a .EXE inside XP/Vista/Win7

QWINSTA.EXE

Also for Remote

Gives output like this

SESSIONNAME       USERNAME             ID  STATE  TYP         DEVICE
 services                               0   active wdcon
>console           test                 1   Disc   wdcon
Edited by Tankbuster
Posted
Posted (edited)

Holy.....

Even more simple:

There is a .EXE inside XP/Vista/Win7

QWINSTA.EXE

Good idea !

Thanks for all your helps ( KaFu and Tankbuster)

Edited by mary

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...