Author Topic: HD Serial number  (Read 3045 times)

0 Members and 1 Guest are viewing this topic.

Marc'Antonio Alessi

  • Swamp Rat
  • Posts: 1451
  • Marco
HD Serial number
« on: February 03, 2023, 02:55:15 AM »


I'm looking for a function that gives the same result as dos_serialno, the functions I report below (sorry if I didn't report all the credits)
[/size]get three different results...
[/size]"BCA30E72" -1130164622 "50026B775203E442"

Code: [Select]

(dos_serialno "C:")            => "BCA30E72"
(#Asmi_Get_Drive_Serial "c:") => -1130164622
(UsbDriveSerialNumber) => ((("C:" -1130164622) ("G:" 428019990) ("H:" 943522054) ("Z:" -693829664)) nil)
(VxGetDriveInfos "C:") => (2.15739e+008 4.28575e+007 2 "NTFS" -1130164622 "" "OS")
(gthardware:generateid) => ("-1130164622" "ASUS01" "User1")
(HDSerial)             => "50026B775203E442"




Code: [Select]
; drive type 1 is a usb 2 hard disk
(defun UsbDriveSerialNumber ( / fso HrdDsk UsbDsk)
  (setq fso (vlax-create-object "Scripting.FileSystemObject"))
  (vlax-for d (vlax-get fso 'Drives)
    (cond
      ( (= (Vlax-get d 'DriveType) 1)
        (setq UsbDsk (cons (list (vla-get-path d) (vla-get-SerialNumber d)) UsbDsk))
      )
      ( (= (Vlax-get d 'DriveType) 2)
        (setq HrdDsk (cons (list (vla-get-path d) (vla-get-SerialNumber d)) HrdDsk))
      )
    ; ( T (print d) )
    )
  )
  (vlax-release-object fso)
  (list (reverse HrdDsk) (reverse UsbDsk))
)
;;; PART OF 'ASMILIB' LIBRUARY  *
;;; Created: 07.10.2007          *
;;; Last modyfied: 07.10.2007    *
;;; © Alexanders Smirnovs (ASMI) *
(defun #Asmi_Get_Drive_Serial(Path / fsObj hSn abPth cDrv)
 (vl-load-com)
 (if
   (and
     (setq fsObj(vlax-create-object "Scripting.FileSystemObject"))
     (not
(vl-catch-all-error-p
  (setq abPth(vl-catch-all-apply 'vlax-invoke-method
       (list fsObj 'GetAbsolutePathName Path))
       ); end setq
   ); end vl-catch-all-error-p
); end not
  ); end and
   (progn
     (setq cDrv(vlax-invoke-method fsObj 'GetDrive
       (vlax-invoke-method fsObj 'GetDriveName abPth
       ); end vlax-invoke-method
     );end vlax-invoke-method
    ); end setq
    (if
      (vl-catch-all-error-p
  (setq hSn(vl-catch-all-apply 'vlax-get-property
    (list cDrv 'SerialNumber))))
    (progn
      (vlax-release-object cDrv)
      (setq hSn nil)
    ); end progn
      ); end if
   (vlax-release-object fsObj)
   ); end progn
  ); end if
 hSn
); end of #Asmi_Get_Drive_Serial


(defun HDSerial ( / wmi srv drv ser )
  (vl-catch-all-apply
    (function
      (lambda ( )
        (if
          (setq wmi (vlax-create-object "WbemScripting.SWbemLocator")
                srv (vlax-invoke wmi 'connectserver nil nil nil nil nil nil nil nil)
                drv (vlax-invoke srv 'execquery "Select SerialNumber from Win32_DiskDrive")
          )
          (vlax-for item drv
            (vlax-for prop (vlax-get item 'Properties_)
              (if (eq "SERIALNUMBER" (strcase (vlax-get prop 'name)))
                (setq ser (vl-string-trim " " (vlax-get prop 'value)))
              )
            )
          )
        )
      )
    )
  )
  (if drv (vlax-release-object drv))
  (if srv (vlax-release-object srv))
  (if wmi (vlax-release-object wmi))
  ser
)


(DEFUN gthardware:generateid (/ filesystemobject drives n serial wscript pcname pcuser)
  (SETQ serial 0
                pcname ""
                pcuser ""
  )
  (COND ((SETQ wscript (VLAX-CREATE-OBJECT "WScript.Network"))
                 (SETQ pcname (VLAX-GET-PROPERTY wscript "ComputerName") ; Computer Name
                           pcuser (VLAX-GET-PROPERTY wscript "UserName") ; UserName
                 )
                 (VLAX-RELEASE-OBJECT wscript)
                 ;; Obtain the first Hard drive serial number
                 (COND ((SETQ filesystemobject (VLAX-CREATE-OBJECT "Scripting.FilesystemObject"))
                                ;; access the Drives collection
                                (SETQ drives (VLAX-GET-PROPERTY filesystemobject 'drives))
                                ;; Check each drive for a fixed drive. When the first drive is found, exit.
                                (VL-CATCH-ALL-APPLY
                                  '(LAMBDA ()
                                         (VLAX-FOR n drives
                                           ;;If there drive is a fixed drive, get the serial and exit
                                           (IF (= (VLAX-GET-PROPERTY n 'drivetype) 2)
                                                 (PROGN
                                                   (SETQ serial (VLAX-GET-PROPERTY n 'serialnumber))
                                                   (EXIT)
                                                 )
                                           )
                                         )
                                   )
                                )
                                ;; Release the vla objects
                                (VLAX-RELEASE-OBJECT drives)
                                (VLAX-RELEASE-OBJECT filesystemobject)
                           )
                 )
                )
  )
  (list (ITOA serial) pcname pcuser)
)


; Copyright: ©2001 MENZI ENGINEERING GmbH, Switzerland
;
(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
)

d2010

  • Bull Frog
  • Posts: 326
Re: HD Serial number
« Reply #1 on: February 03, 2023, 05:12:48 AM »
Why you need, the serial number  of-HDD?
You, do insert more crashes inside  AutoCad?   
Perhaps you block the programs.fas, forced to operating system win11?

 :thinking:
« Last Edit: February 03, 2023, 06:09:26 AM by d2010 »

VovKa

  • Water Moccasin
  • Posts: 1629
  • Ukraine
Re: HD Serial number
« Reply #2 on: February 03, 2023, 05:27:17 AM »
works on win7
not sure about others
Code: [Select]
(defun vk_GetWbem (NameSpace Class Props / LocatorObj ServiceObj ObjectSetObj OutList)
  (and (setq LocatorObj (vlax-create-object "WbemScripting.SWbemLocator"))
       (setq ServiceObj (vlax-invoke-method LocatorObj 'ConnectServer "." NameSpace nil nil nil nil nil nil))
       (setq ObjectSetObj (vlax-invoke-method ServiceObj 'ExecQuery (strcat "SELECT * FROM " Class) nil nil nil))
       (vlax-for Obj ObjectSetObj
(setq OutList (cons (mapcar (function (lambda (p) (cons p (vlax-get Obj p)))) Props)
     OutList
       )
)
       )
  )
  (vk_ReleaseObjects (list ObjectSetObj ServiceObj LocatorObj))
  (reverse OutList)
)
(defun vk_GetHDDID (/)
  (mapcar 'list
  (mapcar 'cdar (vk_GetWbem "root\\cimv2" "Win32_DiskDrive" (list "Model")))
  (mapcar 'cdar (vk_GetWbem "root\\cimv2" "Win32_PhysicalMedia" (list "SerialNumber")))
  )
)

Marc'Antonio Alessi

  • Swamp Rat
  • Posts: 1451
  • Marco
Re: HD Serial number
« Reply #3 on: February 03, 2023, 05:39:43 AM »
works on win7
not sure about others
Code: [Select]
...
Code: [Select]
Thanks VovKa :
; errore: no function definition: VK_RELEASEOBJECTS

VovKa

  • Water Moccasin
  • Posts: 1629
  • Ukraine
Re: HD Serial number
« Reply #4 on: February 03, 2023, 05:53:40 AM »
Code: [Select]
Thanks VovKa :
; errore: no function definition: VK_RELEASEOBJECTS
nothing special, just substitute it with (mapcar 'vlax-release-object ... )

Marc'Antonio Alessi

  • Swamp Rat
  • Posts: 1451
  • Marco
Re: HD Serial number
« Reply #5 on: February 03, 2023, 11:03:48 AM »
Code: [Select]
Thanks VovKa :
; errore: no function definition: VK_RELEASEOBJECTS
nothing special, just substitute it with (mapcar 'vlax-release-object ... )
Thanks again,
(vk_GetHDDID) => (("RSH USB Device" "00A123456789    ") ("KINGSTON SV300S37A240G" "50026B775203E442"))

sorry again for my ignorance but with
(dos_serialno "C:")      => "BCA30E72"
why do I have a different result?

VovKa

  • Water Moccasin
  • Posts: 1629
  • Ukraine
Re: HD Serial number
« Reply #6 on: February 03, 2023, 01:38:04 PM »
why do I have a different result?
as i mentioned earlier, my code works on win7. that's the operating system i'm using
i removed my pc's cover and checked the returned serial against hdd's sticker, they match

and i've also found a comment in my lisp file concerning this function
;;;Win XP/2003 only, no SATA
so it's windows version dependent

It's Alive!

  • Retired
  • Needs a day job
  • Posts: 8691
  • AKA Daniel
Re: HD Serial number
« Reply #7 on: February 03, 2023, 03:19:10 PM »
are you looking for the volume label? XXXX-XXXX

"Select VolumeSerialNumber from Win32_LogicalDisk"
« Last Edit: February 03, 2023, 03:34:05 PM by beck's bolero »

BIGAL

  • Swamp Rat
  • Posts: 1409
  • 40 + years of using Autocad
Re: HD Serial number
« Reply #8 on: February 04, 2023, 01:43:17 AM »
A man who never made a mistake never made anything

It's Alive!

  • Retired
  • Needs a day job
  • Posts: 8691
  • AKA Daniel
Re: HD Serial number
« Reply #9 on: February 04, 2023, 02:23:32 AM »
(dos_serialno "C:")   used to return the volume serial
if you go to the command prompt c:\, type dir,  you should see it at the top
this serial changes when you format the volume, this is not to be confused with a hardware serial number

Marc'Antonio Alessi

  • Swamp Rat
  • Posts: 1451
  • Marco
Re: HD Serial number
« Reply #10 on: February 04, 2023, 03:45:28 AM »
... i removed my pc's cover and checked the returned serial against hdd's sticker, they match ...
Grazie..., thanks for your time.  :)

Marc'Antonio Alessi

  • Swamp Rat
  • Posts: 1451
  • Marco
Re: HD Serial number
« Reply #11 on: February 04, 2023, 03:49:40 AM »
I have modified the function HDSerial posted:
Code: [Select]
(defun ALE__Files_VolSerialLogNo ( / wmi srv drv ser)
  (vl-catch-all-apply
    (function
      (lambda ( )
        (if
          (setq wmi (vlax-create-object "WbemScripting.SWbemLocator")
                srv (vlax-invoke wmi 'connectserver nil nil nil nil nil nil nil nil)
                drv (vlax-invoke srv 'execquery "Select VolumeSerialNumber from Win32_LogicalDisk")
          )
          (vlax-for item drv
            (vlax-for prop (vlax-get item 'Properties_)
              (if (eq "VOLUMESERIALNUMBER" (strcase (vlax-get prop 'name)))
                (setq ser (vl-string-trim " " (vlax-get prop 'value)))
              )
            )
          )
        )
      )
    )
  )
  (foreach obj (list drv srv wmi) (and obj (vlax-release-object obj)))
  ser
)
(ALE__Files_VolSerialLogNo) => "BCA30E72"
(dos_serialno "C:")             => "BCA30E72"
Thanks Daniel and BIGAL  :)

kdub_nz

  • Mesozoic keyThumper
  • SuperMod
  • Water Moccasin
  • Posts: 2132
  • class keyThumper<T>:ILazy<T>
Re: HD Serial number
« Reply #12 on: February 04, 2023, 04:18:20 AM »
 user beware !
 perhaps, or perhaps not :


Called Kerry in my other life
Retired; but they dragged me back in !

I live at UTC + 13.00

---
some people complain about loading the dishwasher.
Sometimes the question is more important than the answer.

Marc'Antonio Alessi

  • Swamp Rat
  • Posts: 1451
  • Marco
Re: HD Serial number
« Reply #13 on: February 04, 2023, 04:21:58 AM »
New version...
Code: [Select]
(defun ALE_Files_VolSerialLogNos ( / wmi srv drv ser did vsn prp)
  (vl-catch-all-apply
    (function
      (lambda ( )
        (if
          (setq wmi (vlax-create-object "WbemScripting.SWbemLocator")
                srv (vlax-invoke wmi 'connectserver nil nil nil nil nil nil nil nil)
                drv (vlax-invoke srv 'execquery "Select VolumeSerialNumber from Win32_LogicalDisk")
          )
          (vlax-for item drv
            (vlax-for prop (vlax-get item 'Properties_)
              (setq prp (strcase (vlax-get prop 'name)))
              (cond
                ( (eq "DEVICEID"           prp) (setq did (vlax-get prop 'value)) )
                ( (eq "VOLUMESERIALNUMBER" prp) (setq vsn (vlax-get prop 'value)) )
              )
            ); (print prp) (princ "  ")  (prin1 did) (princ "  ")  (prin1 vsn)
            (and did vsn (setq ser (cons (cons did vsn) ser)))
          )
        )
      )
    )
  )
  (foreach obj (list drv srv wmi) (and obj (vlax-release-object obj)))
  ser
)
(ALE_Files_VolSerialLogNos) => (("Z:" . "D6A4FFE0") ("H:" . "383D0106") ("G:" . "19831116") ("C:" . "BCA30E72"))

kdub_nz

  • Mesozoic keyThumper
  • SuperMod
  • Water Moccasin
  • Posts: 2132
  • class keyThumper<T>:ILazy<T>
Re: HD Serial number
« Reply #14 on: February 04, 2023, 04:23:49 AM »
User beware !
Perhaps or perhaps not :
Called Kerry in my other life
Retired; but they dragged me back in !

I live at UTC + 13.00

---
some people complain about loading the dishwasher.
Sometimes the question is more important than the answer.

Marc'Antonio Alessi

  • Swamp Rat
  • Posts: 1451
  • Marco
Re: HD Serial number
« Reply #15 on: February 04, 2023, 05:02:00 AM »
User beware !
Perhaps or perhaps not :
does the new version have the same problems?

VovKa

  • Water Moccasin
  • Posts: 1629
  • Ukraine
Re: HD Serial number
« Reply #16 on: February 04, 2023, 07:14:22 AM »
do you plan to use this serial in some protection scheme?

It's Alive!

  • Retired
  • Needs a day job
  • Posts: 8691
  • AKA Daniel
Re: HD Serial number
« Reply #17 on: February 04, 2023, 07:33:21 AM »
do you plan to use this serial in some protection scheme?

Right, it can be changed pretty easily, I know a friend who did that a couple times

Marc'Antonio Alessi

  • Swamp Rat
  • Posts: 1451
  • Marco
Re: HD Serial number
« Reply #18 on: February 04, 2023, 09:13:00 AM »
do you plan to use this serial in some protection scheme?
yes, but I don't have any particular ultra-security needs  :D

drawdraw

  • Mosquito
  • Posts: 14
Re: HD Serial number
« Reply #19 on: January 08, 2024, 03:20:19 AM »
Can help to edit the code of Marc'Antonio Alessi, so that it only returns the serial number of the system drive, the drive where the operating system was installed ?

BIGAL

  • Swamp Rat
  • Posts: 1409
  • 40 + years of using Autocad
Re: HD Serial number
« Reply #20 on: January 08, 2024, 06:41:32 PM »
Just a comment, for protection use fas etc as 1st level, ok there is a DOS way to add to all your lisps in 1 go the security check, yes have used it often, so write the checkdisk id as a seperate lisp, using bat file etc copy ser.lsp+lisp1.lsp c:\compilelisps\lisp1.lsp, will have to find again, but security added and compiled 130 lisps in one go. I use (EXIT) in the check as that aborts the current lisp.

Do you know who to make bulk fas files etc. Can use lisp.

Post if want more information.

Personally yes had a phone call software not working, final result was trying to give software to some one else, security worked.
A man who never made a mistake never made anything

drawdraw

  • Mosquito
  • Posts: 14
Re: HD Serial number
« Reply #21 on: January 10, 2024, 12:22:20 AM »
Hi Bigal, appreciate your reply, but I do not really understand what you meant.
Could you elaborate more ?

For me, I use VLIDE, make a project, compiles my lisps into fas.
Then use Make Application to compile all fas into VLX.
Getting hard disk sn is part of security check, make sure user cannot simply copy my VLX and use in other unauthorised pc.

Do you think VLX can be decoded ? Saw someone said can.

Any suggestion, links to build a better security is welcomed.

ribarm

  • Gator
  • Posts: 3265
  • Marko Ribar, architect
Re: HD Serial number
« Reply #22 on: January 10, 2024, 02:23:37 AM »
Who made compiler, for sure made and decompiler, or knows how decompile works...
But that one for sure isn't interested in viewing our poor coding stuff...
Marko Ribar, d.i.a. (graduated engineer of architecture)

:)

M.R. on Youtube

drawdraw

  • Mosquito
  • Posts: 14
Re: HD Serial number
« Reply #23 on: January 10, 2024, 03:16:05 AM »
haha, you are right, just to protect from non-expert.
 :roll:

VovKa

  • Water Moccasin
  • Posts: 1629
  • Ukraine
Re: HD Serial number
« Reply #24 on: January 10, 2024, 07:58:13 AM »
go for mac-address

drawdraw

  • Mosquito
  • Posts: 14
Re: HD Serial number
« Reply #25 on: January 10, 2024, 08:22:26 PM »
Thank you very much !