TheSwamp

Code Red => AutoLISP (Vanilla / Visual) => Topic started by: DEVITG on July 20, 2009, 07:44:55 AM

Title: mother board , and hard disk data
Post by: DEVITG on July 20, 2009, 07:44:55 AM
Hi all , have a good day .

There is any way by lisp to get data about the Mother Board , and or , hard disk data , like serial number, and so on??

Thank in advance

Title: Re: mother board , and hard disk data
Post by: It's Alive! on July 20, 2009, 08:55:24 AM
sure, though WMI and WSH

here are a couple of samples


Code: [Select]
(DEFUN WMIGETSREENRESOLUTION (/ ITEM METH1 METH2 S ITEMS WMI HR)
  (VL-LOAD-COM)
  (SETQ WMI (VLAX-CREATE-OBJECT "WbemScripting.SWbemLocator")
METH1 (VLAX-INVOKE WMI 'CONNECTSERVER NIL NIL NIL NIL NIL NIL NIL NIL)
METH2 (VLAX-INVOKE METH1 'EXECQUERY "Select * from Win32_VideoController")
HR (VLAX-FOR ITEM METH2
  (SETQ ITEMS (LIST (VLAX-GET ITEM 'CURRENTHORIZONTALRESOLUTION)
    (VLAX-GET ITEM 'CURRENTVERTICALRESOLUTION ))))
  )
  (VLAX-RELEASE-OBJECT METH1)
  (VLAX-RELEASE-OBJECT METH2)
  (VLAX-RELEASE-OBJECT WMI)
  HR
)
;;;
(defun WmiGetOsSerialNumber (/ item meth1 meth2 s serx wmi)
  (vl-load-com)
  (setq WMI (vlax-create-object "WbemScripting.SWbemLocator")
meth1 (VLAX-INVOKE WMI 'ConnectServer nil nil nil nil nil nil nil nil)
meth2 (vlax-invoke meth1 'ExecQuery "select SerialNumber from Win32_OperatingSystem")
s (vlax-for item meth2 (setq serx (list (vlax-get item 'SerialNumber))))
  )
  (vlax-release-object meth1)
  (vlax-release-object meth2)
  (vlax-release-object wmi)
  (car s)
)
;;;
(defun WmiGetOsCaption (/ item meth1 meth2 s serx wmi)
  (vl-load-com)
  (setq WMI (vlax-create-object "WbemScripting.SWbemLocator")
meth1 (VLAX-INVOKE WMI 'ConnectServer nil nil nil nil nil nil nil nil)
meth2 (vlax-invoke meth1 'ExecQuery "select Caption from Win32_OperatingSystem")
s (vlax-for item meth2 (setq serx (list (vlax-get item 'Caption))))
  )
  (vlax-release-object meth1)
  (vlax-release-object meth2)
  (vlax-release-object wmi)
  (car s)
)
;;;
(defun WmiTotalPhysicalMemory (/ item meth1 meth2 s serx wmi)
  (vl-load-com)
  (setq WMI (vlax-create-object "WbemScripting.SWbemLocator")
meth1 (VLAX-INVOKE WMI 'ConnectServer nil nil nil nil nil nil nil nil)
meth2 (vlax-invoke meth1 'ExecQuery "select TotalPhysicalMemory from Win32_LogicalMemoryConfiguration")
s (vlax-for item meth2 (setq serx (list (vlax-get item 'TotalPhysicalMemory))))
  )
  (vlax-release-object meth1)
  (vlax-release-object meth2)
  (vlax-release-object wmi)
  (strcat (itoa (fix (/ (car s) 1024))) " Mbytes")
)
;;;
(defun wmiMaxClockSpeed (/ item meth1 meth2 s serx wmi)
  (vl-load-com)
  (setq WMI (vlax-create-object "WbemScripting.SWbemLocator")
meth1 (VLAX-INVOKE WMI 'ConnectServer nil nil nil nil nil nil nil nil)
meth2 (vlax-invoke meth1 'ExecQuery "select MaxClockSpeed from Win32_Processor")
s (vlax-for item meth2 (setq serx (list (vlax-get item 'MaxClockSpeed))))
  )
  (vlax-release-object meth1)
  (vlax-release-object meth2)
  (vlax-release-object wmi)
  (strcat (itoa (car s)) " MHz")
)
;;;
(defun wmiProcessorType (/ item meth1 meth2 s serx wmi)
  (vl-load-com)
  (setq WMI (vlax-create-object "WbemScripting.SWbemLocator")
meth1 (VLAX-INVOKE WMI 'ConnectServer nil nil nil nil nil nil nil nil)
meth2 (vlax-invoke meth1 'ExecQuery "select Name from Win32_Processor")
s (vlax-for item meth2 (setq serx (list (vlax-get item 'Name))))
  )
  (vlax-release-object meth1)
  (vlax-release-object meth2)
  (vlax-release-object wmi)
  (car s)
)
;;;
(defun wmiProcessorType2 (/ item meth1 meth2 s serx wmi)
  (vl-load-com)
  (setq WMI (vlax-create-object "WbemScripting.SWbemLocator")
meth1 (VLAX-INVOKE WMI 'ConnectServer nil nil nil nil nil nil nil nil)
meth2 (vlax-invoke meth1 'ExecQuery "select DataWidth from Win32_Processor")
s (vlax-for item meth2 (setq serx (list (vlax-get item 'DataWidth))))
  )
  (vlax-release-object meth1)
  (vlax-release-object meth2)
  (vlax-release-object wmi)
  (car s)
)
;;;
(defun wmiProcessorType3 (/ item meth1 meth2 s serx wmi)
  (vl-load-com)
  (setq WMI (vlax-create-object "WbemScripting.SWbemLocator")
meth1 (VLAX-INVOKE WMI 'ConnectServer nil nil nil nil nil nil nil nil)
meth2 (vlax-invoke meth1 'ExecQuery "select Architecture from Win32_Processor")
s (vlax-for item meth2 (setq serx (list (vlax-get item 'Architecture))))
  )
  (vlax-release-object meth1)
  (vlax-release-object meth2)
  (vlax-release-object wmi)
  (car s)
)
Title: Re: mother board , and hard disk data
Post by: It's Alive! on July 20, 2009, 09:30:46 AM
and more specifically

Code: [Select]
(defun MainBoardSerial (/ item meth1 meth2 s serx wmi)
  (vl-load-com)
  (setq WMI (vlax-create-object "WbemScripting.SWbemLocator")
meth1 (VLAX-INVOKE WMI 'ConnectServer nil nil nil nil nil nil nil nil)
meth2 (vlax-invoke meth1 'ExecQuery "select SerialNumber from Win32_BaseBoard")
s (vlax-for item meth2 (setq serx (list (vlax-get item 'SerialNumber))))
  )
  (vlax-release-object meth1)
  (vlax-release-object meth2)
  (vlax-release-object wmi)
  (car s)
)


Code: [Select]
class Win32_BaseBoard : CIM_Card
{
  string   Caption;
  string   ConfigOptions[];
  string   CreationClassName;
  real32   Depth;
  string   Description;
  real32   Height;
  boolean  HostingBoard;
  boolean  HotSwappable;
  datetime InstallDate;
  string   Manufacturer;
  string   Model;
  string   Name;
  string   OtherIdentifyingInfo;
  string   PartNumber;
  boolean  PoweredOn;
  string   Product;
  boolean  Removable;
  boolean  Replaceable;
  string   RequirementsDescription;
  boolean  RequiresDaughterBoard;
  string   SerialNumber;
  string   SKU;
  string   SlotLayout;
  boolean  SpecialRequirements;
  string   Status;
  string   Tag;
  string   Version;
  real32   Weight;
  real32   Width;
};

and

Code: [Select]
class Win32_DiskDrive : CIM_DiskDrive
{
  uint16   Availability;
  uint32   BytesPerSector;
  uint16   Capabilities[];
  string   CapabilityDescriptions[];
  string   Caption;
  string   CompressionMethod;
  uint32   ConfigManagerErrorCode;
  boolean  ConfigManagerUserConfig;
  string   CreationClassName;
  uint64   DefaultBlockSize;
  string   Description;
  string   DeviceID;
  boolean  ErrorCleared;
  string   ErrorDescription;
  string   ErrorMethodology;
  string   FirmwareRevision;
  uint32   Index;
  datetime InstallDate;
  string   InterfaceType;
  uint32   LastErrorCode;
  string   Manufacturer;
  uint64   MaxBlockSize;
  uint64   MaxMediaSize;
  boolean  MediaLoaded;
  string   MediaType;
  uint64   MinBlockSize;
  string   Model;
  string   Name;
  boolean  NeedsCleaning;
  uint32   NumberOfMediaSupported;
  uint32   Partitions;
  string   PNPDeviceID;
  uint16   PowerManagementCapabilities[];
  boolean  PowerManagementSupported;
  uint32   SCSIBus;
  uint16   SCSILogicalUnit;
  uint16   SCSIPort;
  uint16   SCSITargetId;
  uint32   SectorsPerTrack;
  string   SerialNumber;
  uint32   Signature;
  uint64   Size;
  string   Status;
  uint16   StatusInfo;
  string   SystemCreationClassName;
  string   SystemName;
  uint64   TotalCylinders;
  uint32   TotalHeads;
  uint64   TotalSectors;
  uint64   TotalTracks;
  uint32   TracksPerCylinder;
};
Title: Re: mother board , and hard disk data
Post by: DEVITG on July 20, 2009, 09:45:37 AM
Thanks for the help.
I will try it
Best regards
Gabriel.

 
Title: Re: mother board , and hard disk data
Post by: Lee Mac on July 20, 2009, 10:02:00 AM
Daniel,

May I ask, what reference do you use for determining the arguments needed for these methods?

Lee
Title: Re: mother board , and hard disk data
Post by: It's Alive! on July 20, 2009, 10:22:51 AM
I use the WMI Reference
http://msdn.microsoft.com/en-us/library/aa394582(VS.85).aspx

and I tend to use WQL type statements when I can
http://msdn.microsoft.com/en-us/library/aa392902(VS.85).aspx
Title: Re: mother board , and hard disk data
Post by: Lee Mac on July 20, 2009, 10:35:40 AM
I see, thanks.

I think that may be a bit beyond me  :oops:
Title: Re: mother board , and hard disk data
Post by: It's Alive! on July 20, 2009, 10:50:15 AM
Its worth it to learn a little WMI mojo as you can use it with other languges as well
In fact I just used it last week with C++/CLI && .net


Code: [Select]
  System::String^ GetWindowsID()
  {
    String ^value = nullptr;
    try
    {
      ManagementScope ^scope =
        gcnew ManagementScope("\\\\LocalHost\\root\\cimv2");
      ObjectQuery ^oQuery =
        gcnew ObjectQuery("Select SerialNumber from win32_operatingsystem ");
      ManagementObjectSearcher ^oSearcher =
        gcnew ManagementObjectSearcher(scope,oQuery);
      ManagementObjectCollection ^col =  oSearcher->Get();

      for each(ManagementObject ^o in col)
      {
        value = o["SerialNumber"]->ToString();
        break;
      }
    }
    catch (System::Exception ^e)
    {
      sds_alert(CString(e->Message));
    }
    return value;
  }
Title: Re: mother board , and hard disk data
Post by: Keith™ on July 20, 2009, 11:38:31 AM
I just tried to retrieve the serial number from the HD .. it returned nil ... did I miss something?
Title: Re: mother board , and hard disk data
Post by: Spike Wilbury on July 20, 2009, 12:54:38 PM
Its worth it to learn a little WMI mojo as you can use it with other languges as well
In fact I just used it last week with C++/CLI && .net

Dang... you know to much  :-P
Title: Re: mother board , and hard disk data
Post by: VovKa on July 20, 2009, 03:02:17 PM
I just tried to retrieve the serial number from the HD .. it returned nil ... did I miss something?
you are not alone, Keith™
this method doesn't work in 9 cases out of 10 :(

as far as i understood, DEVITG is trying to bind his code to a certain machine
the only good method to achieve this (that i know of) is reading the macaddress
Code: [Select]
(vl-load-com)
(defun GetMacAddress
       (/ LocatorObj ServiceObj SecurityObj ObjectSetObj OutList)
  (setq LocatorObj (vlax-create-object "WbemScripting.SWbemLocator"))
  (setq
    ServiceObj (vlax-invoke LocatorObj 'ConnectServer nil nil nil nil nil nil nil nil)
  )
  (setq ObjectSetObj
(vlax-invoke ServiceObj 'ExecQuery "Select * from Win32_NetworkAdapter")
  )
  (vlax-for Obj ObjectSetObj
    (if (wcmatch (vl-princ-to-string (vlax-get Obj 'AdapterType)) "Ethernet 802.*")
      (setq OutList (cons (vlax-get Obj 'MACAddress) OutList))
    )
  )
  (foreach Obj (list LocatorObj ServiceObj SecurityObj ObjectSetObj)
    (and Obj (vlax-release-object Obj))
  )
  OutList
)
Title: Re: mother board , and hard disk data
Post by: Keith™ on July 20, 2009, 03:25:16 PM
yeah .. and even that can be spoofed, but not on the same newtork unless they are using different DHCP servers or are statically addressed .. at least that is my understanding  ... as feeble as that might be .. maybe someone can enlighten me as to the correctness.
Title: Re: mother board , and hard disk data
Post by: It's Alive! on July 20, 2009, 07:09:52 PM
Some drives do not return a serial number.
If your tring to bind your software to a certain machine, you should collect ID's/data from a few sources, then run the results through a hash calulator
Title: Re: mother board , and hard disk data
Post by: TopoWAR on July 28, 2009, 01:46:48 PM
Daniel Hello to all. The following code works for me perfect in a 32-bit processor, but in one of 64 bits it does not work.   Can he be done for 64 bits ? Thanks and that they spend good day.

Code: [Select]
;;;
(defun WmiTotalPhysicalMemory (/ item meth1 meth2 s serx wmi)
  (vl-load-com)
  (setq WMI (vlax-create-object "WbemScripting.SWbemLocator")
meth1 (VLAX-INVOKE WMI 'ConnectServer nil nil nil nil nil nil nil nil)
meth2 (vlax-invoke meth1 'ExecQuery "select TotalPhysicalMemory from Win32_LogicalMemoryConfiguration")
s (vlax-for item meth2 (setq serx (list (vlax-get item 'TotalPhysicalMemory))))
  )
  (vlax-release-object meth1)
  (vlax-release-object meth2)
  (vlax-release-object wmi)
  (strcat (itoa (fix (/ (car s) 1024))) " Mbytes")
)
;;;
Title: Re: mother board , and hard disk data
Post by: DEVITG on July 28, 2009, 02:16:47 PM
Hi TOPO , wellcome aboard.

Gabriel.
Title: Re: mother board , and hard disk data
Post by: minosdam on August 02, 2010, 12:38:10 PM
I just tried to retrieve the serial number from the HD .. it returned nil ... did I miss something?
; -- Function VxGetDriveInfos
; Returns information's from a drive.
; Copyright:
;   ©2001 MENZI ENGINEERING GmbH, Switzerland
; Arguments [Type]:
;   Drv = Drive character, e.g. "C" or "C:" [STR]
; Return [Type]:
;   > Drive infos '(TotalSize FreeSpace DriveType FileSystem SerialNumber
;                   ShareName VolumeName) [REAL]
;       Returns the total space of a drive or network share.
;     - FreeSpace (kB) [REAL]
;       Returns the amount of space available to a user on the specified drive
;       or network share.
;     - DriveType [INT]
;       0 = "Unknown"
;       1 = "Removable"
;       2 = "Fixed"
;       3 = "Network"
;       4 = "CD-ROM"
;       5 = "RAM Disk"
;     - FileSystem [STR]
;       Returns the type of file system in use for the specified drive, e.g.
;       "FAT", "NTFS", "CDFS".
;     - SerialNumber [INT]
;       Returns the serial number used to uniquely identify a disk volume.
;     - ShareName [STR]
;       Returns the network share name (UNC) for the specified drive. If it's
;       not a network drive, ShareName returns a zero-length string ("").
;     - VolumeName [STR]
;       Returns the volume name of the specified drive.
;   >  0 The drive doesn't exist.
;   > -1 The drive is not ready. For removable-media drives and CD-ROM drives,
;        VxGetDriveInfos returns -1 when the appropriate media is not inserted
;        or not ready for access.
; Notes:
;   - Requires ScrRun.dll (see also notes at top of page).
;
(defun VxGetDriveInfos (Drv / DrvObj FilSys RetVal)
 (vl-load-com)
 (setq FilSys (vlax-create-object "Scripting.FileSystemObject")
       RetVal (cond
               ((= (vlax-invoke FilSys 'DriveExists Drv) 0) 0)
               ((setq DrvObj (vlax-invoke FilSys 'GetDrive Drv))
                (cond
                 ((= (vlax-get DrvObj 'IsReady) 0) -1)
                 ((list
                   (/ (vlax-get DrvObj 'TotalSize) 1000.0)
                   (/ (vlax-get DrvObj 'FreeSpace) 1000.0)
                   (vlax-get DrvObj 'DriveType)
                   (vlax-get DrvObj 'FileSystem)
                   (vlax-get DrvObj 'SerialNumber)
                   (vlax-get DrvObj 'ShareName)
                   (vlax-get DrvObj 'VolumeName)
                  )
                 )
                )
               )
              )
 )
 (if DrvObj (vlax-release-object DrvObj))
 (vlax-release-object FilSys)
 RetVal
)
Title: Re: mother board , and hard disk data
Post by: TopoWAR on September 09, 2013, 03:25:25 PM
hi all, please I need your help, I used this code but now it gives me error: SWbemServicesEx: Generic error in win 8, which may be happening??? I appreciate your ideas to solve this problem!

This is the code that gives me error that may have problem?
Code: [Select]
(setq WMI (vlax-create-object "WbemScripting.SWbemLocator")
meth1 (VLAX-INVOKE WMI 'ConnectServer nil nil nil nil nil nil nil nil)
meth2 (vlax-invoke meth1 'ExecQuery "select DataWidth from Win32_Processor")
s (vlax-for item meth2 (setq serx (list (vlax-get item 'DataWidth))))
  )
Title: Re: mother board , and hard disk data
Post by: ronjonp on September 11, 2013, 12:20:20 PM
Works for me on Windows 8 Pro x64


Quote
_$


(64)
; 1 form loaded from #<editor "<Untitled-1> loading...">
_$
Title: Re: mother board , and hard disk data
Post by: TopoWAR on September 11, 2013, 12:40:58 PM
ronjonp , NO on all pc's this error occurs, there is something in win 8 which prevents the communication of wmi from autocad, but is it???