Author Topic: mother board , and hard disk data  (Read 9396 times)

0 Members and 1 Guest are viewing this topic.

DEVITG

  • Bull Frog
  • Posts: 480
mother board , and hard disk data
« 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

Location @ Córdoba Argentina Using ACAD 2019  at Window 10

It's Alive!

  • Retired
  • Needs a day job
  • Posts: 8706
  • AKA Daniel
Re: mother board , and hard disk data
« Reply #1 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)
)

It's Alive!

  • Retired
  • Needs a day job
  • Posts: 8706
  • AKA Daniel
Re: mother board , and hard disk data
« Reply #2 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;
};

DEVITG

  • Bull Frog
  • Posts: 480
Re: mother board , and hard disk data
« Reply #3 on: July 20, 2009, 09:45:37 AM »
Thanks for the help.
I will try it
Best regards
Gabriel.

 
Location @ Córdoba Argentina Using ACAD 2019  at Window 10

Lee Mac

  • Seagull
  • Posts: 12914
  • London, England
Re: mother board , and hard disk data
« Reply #4 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

It's Alive!

  • Retired
  • Needs a day job
  • Posts: 8706
  • AKA Daniel
Re: mother board , and hard disk data
« Reply #5 on: July 20, 2009, 10:22:51 AM »

Lee Mac

  • Seagull
  • Posts: 12914
  • London, England
Re: mother board , and hard disk data
« Reply #6 on: July 20, 2009, 10:35:40 AM »
I see, thanks.

I think that may be a bit beyond me  :oops:

It's Alive!

  • Retired
  • Needs a day job
  • Posts: 8706
  • AKA Daniel
Re: mother board , and hard disk data
« Reply #7 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;
  }
« Last Edit: July 20, 2009, 10:55:24 AM by Daniel »

Keith™

  • Villiage Idiot
  • Seagull
  • Posts: 16899
  • Superior Stupidity at its best
Re: mother board , and hard disk data
« Reply #8 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?
Proud provider of opinion and arrogance since November 22, 2003 at 09:35:31 am
CadJockey Militia Field Marshal

Find me on https://parler.com @kblackie

Spike Wilbury

  • Guest
Re: mother board , and hard disk data
« Reply #9 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

VovKa

  • Water Moccasin
  • Posts: 1631
  • Ukraine
Re: mother board , and hard disk data
« Reply #10 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
)

Keith™

  • Villiage Idiot
  • Seagull
  • Posts: 16899
  • Superior Stupidity at its best
Re: mother board , and hard disk data
« Reply #11 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.
Proud provider of opinion and arrogance since November 22, 2003 at 09:35:31 am
CadJockey Militia Field Marshal

Find me on https://parler.com @kblackie

It's Alive!

  • Retired
  • Needs a day job
  • Posts: 8706
  • AKA Daniel
Re: mother board , and hard disk data
« Reply #12 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

TopoWAR

  • Guest
Re: mother board , and hard disk data
« Reply #13 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")
)
;;;

DEVITG

  • Bull Frog
  • Posts: 480
Re: mother board , and hard disk data
« Reply #14 on: July 28, 2009, 02:16:47 PM »
Hi TOPO , wellcome aboard.

Gabriel.
Location @ Córdoba Argentina Using ACAD 2019  at Window 10