mary Posted September 23, 2010 Share Posted September 23, 2010 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 userany help please ? Link to comment Share on other sites More sharing options...
KaFu Posted September 23, 2010 Share Posted September 23, 2010 Maybe a check on "explorer.exe" with the _ProcessGetOwner() does the trick? OS: Win10-22H2 - 64bit - German, AutoIt Version: 3.3.16.1, AutoIt Editor: SciTE, Website: https://funk.eu AMT - Auto-Movie-Thumbnailer (2024-Oct-13) BIC - Batch-Image-Cropper (2023-Apr-01) COP - Color Picker (2009-May-21) DCS - Dynamic Cursor Selector (2024-Oct-13) HMW - Hide my Windows (2024-Oct-19) HRC - HotKey Resolution Changer (2012-May-16) ICU - Icon Configuration Utility (2018-Sep-16) SMF - Search my Files (2024-Oct-20) - THE file info and duplicates search tool SSD - Set Sound Device (2017-Sep-16) Link to comment Share on other sites More sharing options...
rudi Posted September 23, 2010 Share Posted September 23, 2010 ;-) 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! Link to comment Share on other sites More sharing options...
mary Posted September 23, 2010 Author Share Posted September 23, 2010 Maybe a check on "explorer.exe" with the _ProcessGetOwner() does the trick?_ProcessGetOwner() gives the pid of "lancher" and not the owner user Link to comment Share on other sites More sharing options...
Tankbuster Posted September 23, 2010 Share Posted September 23, 2010 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? Link to comment Share on other sites More sharing options...
Tankbuster Posted September 23, 2010 Share Posted September 23, 2010 (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 September 23, 2010 by Tankbuster Link to comment Share on other sites More sharing options...
KaFu Posted September 23, 2010 Share Posted September 23, 2010 This works if NOT called from a service, give it a try ... #include<_ProcessFunctions.au3> $hProcess = _ProcessOpen(ProcessExists("explorer.exe"),0x20000) MsgBox(0,"",_ProcessGetOwner($hProcess)) _ProcessCloseHandle($hProcess) OS: Win10-22H2 - 64bit - German, AutoIt Version: 3.3.16.1, AutoIt Editor: SciTE, Website: https://funk.eu AMT - Auto-Movie-Thumbnailer (2024-Oct-13) BIC - Batch-Image-Cropper (2023-Apr-01) COP - Color Picker (2009-May-21) DCS - Dynamic Cursor Selector (2024-Oct-13) HMW - Hide my Windows (2024-Oct-19) HRC - HotKey Resolution Changer (2012-May-16) ICU - Icon Configuration Utility (2018-Sep-16) SMF - Search my Files (2024-Oct-20) - THE file info and duplicates search tool SSD - Set Sound Device (2017-Sep-16) Link to comment Share on other sites More sharing options...
mary Posted September 24, 2010 Author Share Posted September 24, 2010 (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 September 24, 2010 by mary Link to comment Share on other sites More sharing options...
Tankbuster Posted September 24, 2010 Share Posted September 24, 2010 Thx, you're welcome Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now