Get Workstation information : Native Windows Function « Windows « C# / CSharp Tutorial






/*
NET Development for Java Programmers
# By Paul Gibbons
# ISBN: 1-59059-038-4
# 432 pp.
# Published: Jul 2002
*/
using System;
using System.Runtime.InteropServices;
using System.Text;

class NWGetInfo
{
  [ StructLayout( LayoutKind.Sequential ) ]
  struct WkstaInfo102
  {
    public uint platform_id;
    public IntPtr computername;
    public IntPtr langroup;
    public uint ver_major;
    public uint ver_minor;
    public IntPtr lanroot;
    public uint logged_on_users;
  }

  [ DllImport( "Netapi32.dll" ) ]
  static extern unsafe int NetWkstaGetInfo( IntPtr servername, int level, byte** bufptr );

  [ DllImport( "Netapi32.dll" ) ]
  static extern unsafe int NetApiBufferFree( byte* bufptr );

  [STAThread]
  static unsafe void Main(string[] args)
  {
    byte* bp = null;
    int rc = NetWkstaGetInfo( IntPtr.Zero, 102, &bp );

    WkstaInfo102* wip = (WkstaInfo102*)bp;
    Console.WriteLine( "System {0} has {1} users logged on", Marshal.PtrToStringAuto( wip->computername ), wip->logged_on_users );

    rc = NetApiBufferFree( bp );
  }
}
System JAVA2S has 3 users logged on








29.10.Native Windows Function
29.10.1.Calling Native DLL Functions
29.10.2.Calling a Function with a Structure Parameter
29.10.3.Enumerate Display Monitors
29.10.4.Get Workstation information
29.10.5.Get Computer name (char * parameter)
29.10.6.Get free disk space
29.10.7.Use native windows function to read file
29.10.8.The windows version information
29.10.9.Get current Active Window
29.10.10.Writing INI file: Write Private Profile String
29.10.11.Reading INI file: Get Private Profile String
29.10.12.GetVersionEx by using kernel32.dll
29.10.13.Get computer name (StringBuilder parameter)
29.10.14.Lock work station
29.10.15.Get Monitor Information