ManagementClass mc = new ManagementClass("Win32_LoggedOnUser");
ManagementObjectCollection mcCollection = mc.GetInstances();
foreach( ManagementObject mo in mcCollection )
{
Console.WriteLine( "------------------------------------------");
Console.WriteLine( "User '{0}' has logon session '{1}'\n",
mo["Antecedent"], mo["Dependent"]);
ManagementObject user = new ManagementObject(mo["Antecedent"].ToString());
ManagementObject session = new ManagementObject(mo["Dependent"].ToString());
if ((uint)session["LogonType"] == 2)
Console.WriteLine( "Interactive User is '{0}'\n", user["Name"]);
}
--
Gwyn Cole
co-author of "Developing WMI Solutions"
Dim mc As New ManagementClass("Win32_LoggedOnUser")
Dim mcCollection As ManagementObjectCollection = mc.GetInstances()
Dim mo As ManagementObject
For Each mo In mcCollection
Console.WriteLine("------------------------------------------")
Console.WriteLine("User '" & mo("Antecedent").ToString() & "' has logon
session '" & mo("Dependent").ToString() & "'")
Dim user As New ManagementObject(mo("Antecedent").ToString())
Dim session As New ManagementObject(mo("Dependent").ToString())
Dim logon As Integer = Convert.ToInt32(session("LogonType"))
If logon = 2 Then
Console.WriteLine("Interactive User is '{0}'", user("Name").ToString())
End If
Next mo
strComputer = "."
Set objWMIService = GetObject("winmgmts:" _
& "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
Set colComputer = objWMIService.ExecQuery _
("Select * from Win32_ComputerSystem")
For Each objComputer in colComputer
Wscript.Echo objComputer.UserName &vbCrlf &vbCrlf
Next
"Gwyn Cole" <gwyn...@btinternet.com> wrote in message
news:OPstGQgzCHA.1900@TK2MSFTNGP10...
Gwyn, thank you for taking time out to learn enough
VB.NET to help me. I am actually learning C# myself so if
converting to VB.net is too much of a pain I can do the
conversion the other way.
>.
>
Mathieu
"Chad Wilson" <chad....@sertech.com> wrote in message
news:047e01c2cec4$0ab19fc0$3301...@phx.gbl...