@@ -643,7 +643,45 @@ public static DateTime GetStartupTime(string server)
643
643
}
644
644
}
645
645
646
- [ DllImport ( "winspool.drv" , CharSet = CharSet . Unicode , EntryPoint = "OpenPrinterW" , SetLastError = true ) ]
646
+ [ StructLayout ( LayoutKind . Sequential , CharSet = CharSet . Unicode ) ]
647
+ public struct WKSTA_INFO_100
648
+ {
649
+ public int platform_id ;
650
+ public string computer_name ;
651
+ public string lan_group ;
652
+ public int ver_major ;
653
+ public int ver_minor ;
654
+ }
655
+
656
+ [ DllImport ( "netapi32.dll" , CharSet = CharSet . Unicode ) ]
657
+ internal static extern uint NetWkstaGetInfo (
658
+ string servername ,
659
+ int level ,
660
+ out IntPtr bufptr ) ;
661
+
662
+ [ SecurityPermission ( SecurityAction . Demand , Flags = SecurityPermissionFlag . UnmanagedCode ) ]
663
+ public static string GetComputerVersion ( string server )
664
+ {
665
+ IntPtr buffer = IntPtr . Zero ;
666
+ uint ret = NetWkstaGetInfo ( server , 100 , out buffer ) ;
667
+ if ( ret != 0 )
668
+ {
669
+ Trace . WriteLine ( "GetComputerVersion " + server + " returned " + ret ) ;
670
+ return "not found" ;
671
+ }
672
+ try
673
+ {
674
+ WKSTA_INFO_100 data = ( WKSTA_INFO_100 ) Marshal . PtrToStructure ( buffer , typeof ( WKSTA_INFO_100 ) ) ;
675
+ string version = data . ver_major . ToString ( ) + "." + data . ver_minor . ToString ( ) ;
676
+ return version ;
677
+ }
678
+ finally
679
+ {
680
+ NetApiBufferFree ( buffer ) ;
681
+ }
682
+ }
683
+
684
+ [ DllImport ( "winspool.drv" , CharSet = CharSet . Unicode , EntryPoint = "OpenPrinterW" , SetLastError = true ) ]
647
685
internal static extern bool OpenPrinter ( string pPrinterName , out IntPtr phPrinter , IntPtr pDefault ) ;
648
686
649
687
[ DllImport ( "winspool.drv" , CharSet = CharSet . Unicode , EntryPoint = "ClosePrinter" , SetLastError = true ) ]
0 commit comments