Thursday, 15 September 2011

c# - Remotely determine interactive/active user on Windows 7 machine -



c# - Remotely determine interactive/active user on Windows 7 machine -

anyone else had determine logged on user remotely in windows 7 environment? using .net 4.0 , c#. environment mixed xp , 7.

wmi queries involving sessions result in active sessions, not session interactive. username computersystem (wmi) returns null exception if user connected via remote desktop, mutual plenty method cannot used. psloggedon takes long purposes (yes, 300 ms long) , surprisingly not accurate 100% of time using p/invoke wtsgetactiveconsolesessionid or lsaenumeratelogonsessions complicated , prone memory leaks (from i've read) tasklist /s <computername> homecoming info xp systems, windows 7 won't agreeable lovely uac. hkcu (win registry) inaccessible remotely due permissions restrictions, hku accessible, volatile environment doesn't appear have tag "active"

so far, reliable way using psexec remotely execute qwinsta command line , traverse output text remotely. annoying , takes time (more psloggedon), i'm running out of ideas here reliability. reliability before speed, speed of import in terms of cost benefit.

third party tools not option, has script, preferably wmi , c#. delved hitting dc using principal objects, i'm afraid might have confused myself more. also, user accounts administrators.

i've done lot of research on google, thinking maybe looking in wrong place.

any takers?

you can accomplish browsing win32_computersystem class's username propperty :

connectionoptions con = new connectionoptions(); con.username = "administrator"; con.password = "********"; managementscope scope = new managementscope(@"\\" + stripaddress + @"\root\cimv2", con); scope.connect(); //check scope.isconnected, process managementobjectsearcher searcher =new managementobjectsearcher(@"\\" + stripaddress + @"\root\cimv2", "select * win32_computersystem"); foreach (managementobject queryobj in searcher.get()) { console.writeline("-----------------------------------"); console.writeline("win32_computersystem instance"); console.writeline("-----------------------------------"); console.writeline("username: {0}", queryobj["username"]); }

c# windows-7 cmd wmi

No comments:

Post a Comment