ASKER
using System;
using System.Security;
using System.Security.Permissions;
using System.Runtime.InteropServices;
using System.Management;
namespace GetUserInfo
{
static class Program
{
/// <summary>
/// The main entry point for the application.
/// </summary>
[STAThread]
static void Main()
{
//Connection credentials to the remote computer - not needed if the logged in account has access
ConnectionOptions oConn = new ConnectionOptions();
oConn.Username = "JohnDoe";
oConn.Password = "JohnsPass";
System.Management.ManagementScope oMs = new System.Management.ManagementScope("\\MachineX", oConn);
//get Fixed disk stats
System.Management.ObjectQuery oQuery = new System.Management.ObjectQuery("select FreeSpace,Size,Name from Win32_LogicalDisk where DriveType=3");
//Execute the query
ManagementObjectSearcher oSearcher = new ManagementObjectSearcher(oMs,oQuery);
//Get the results
ManagementObjectCollection oReturnCollection = oSearcher.Get();
//loop through found drives and write out info
foreach( ManagementObject oReturn in oReturnCollection )
{
// Disk name
Console.WriteLine("Name : " + oReturn["Name"].ToString());
// Free Space in bytes
Console.WriteLine("FreeSpace: " + oReturn["FreeSpace"].ToString());
// Size in bytes
Console.WriteLine("Size: " + oReturn["Size"].ToString());
}
return;
}
}
}
ASKER
ASKER
ASKER
ASKER
using System;
using System.Security;
using System.Security.Permissions;
using System.Runtime.InteropServices;
using System.Management;
namespace GetUserInfo
{
static class Program
{
/// <summary>
/// The main entry point for the application.
/// </summary>
[STAThread]
static void Main()
{
//Connection credentials to the remote computer - not needed if the logged in account has access
ConnectionOptions Options = new ConnectionOptions();
Options.Username = "JOEUSER"; // ************ ADMIN FOR REMOTE MACHINE *************//
Options.Password = "************";
Options.Authority = "NTLMDOMAIN:ServerX";
//System.Management.ManagementScope scope = new System.Management.ManagementScope("\\\\hbh8291", Options);
//scope.Connect();
ManagementScope scope = new ManagementScope("\\\\ServerX\\root\\cimv2", Options); // ************* wHAT IS THE "\\root\\cimv2" ALL ABOUT ?
scope.Connect(); // ****************** ERROR HERE ***************** //
//get Process objects
System.Management.ObjectQuery query = new System.Management.ObjectQuery("Select * from Win32_Process");
ManagementObjectSearcher searcher = new ManagementObjectSearcher(scope, query);
ManagementObjectCollection QueryCollection = searcher.Get();
foreach (ManagementObject QueryResult in QueryCollection)
{
//Name of process
Console.WriteLine(QueryResult["Name"].ToString().ToLower());
//arg to send with method invoke to return user and domain - below is link to SDK doc on it
string[] o = new String[2];
//Invoke the method and populate the o var with the user name and domain
QueryResult.InvokeMethod("GetOwner",(object[])o);
//write out user info that was returned
Console.WriteLine("User: " + o[1]+ "\\" + o[0]);
Console.WriteLine("PID: " + QueryResult["ProcessId"].ToString());
//get priority
if(QueryResult["Priority"] != null)
Console.WriteLine("Priority: " + QueryResult["Priority"].ToString());
/*get creation date - need managed code function to convert date -
if(QueryResult["CreationDate"] != null)
{
//get datetime string and convert
string s = QueryResult["CreationDate"].ToString();
//see ToDateTime function in sample code
DateTime dc = DateTime.ParseExact(s, "mmddyyyy hh:mm", System.Globalization.CultureInfo.CurrentUICulture.DateTimeFormat);
//write out creation date
Console.WriteLine("CreationDate: " + dc.AddTicks(-TimeZone.CurrentTimeZone.GetUtcOffset(DateTime.Now).Ticks).ToLocalTime().ToString());
}
*/
//this is the amount of memory used
if(QueryResult["WorkingSetSize"] != null)
{
long mem = Convert.ToInt64(QueryResult["WorkingSetSize"].ToString()) / 1024;
Console.WriteLine("Mem Usage: {0:#,###.##}Kb",mem);
}
}
return;
}
}
}
ASKER
ASKER
ASKER
The .NET Framework is not specific to any one programming language; rather, it includes a library of functions that allows developers to rapidly build applications. Several supported languages include C#, VB.NET, C++ or ASP.NET.
TRUSTED BY
I meant use the Terminal Services Counters provided by WMI, and I think these will only be useful if you have the Remote Desktop enabled.
This is the class you can use to determin if you have an active session Win32_PerfFormattedData_Te
Let me see what I can work out