Hard drive serial number

Ken Ray kray at sonsothunder.com
Mon Jan 17 10:42:45 EST 2005

On 1/17/05 8:28 AM, "Paul Salyers" <ps1 at softseven.org> wrote:

> I have need to read the hard drive serial number. How is this did?

Here's my solution for OS X and WIndows (don't have an OS 9 solution handy).
For OS X, you just call it without the parameter; for Windows, the parameter
is optional (it'll use "C:" if you don't provide one).

function stsGetSerialNumber pDriveLetter
  local tID
  switch (the platform)
  case "MacOS"
    if isOSX() then
      put shell("system_profiler SPHardwareDataType") into tData
      put matchText(tData,"(?s)Serial Number:\W*(.*?)\n",tID) into tIsMatch
      -- No OS 9 version yet
    end if
  case "Win32"
    if pDriveLetter = "" then put "C:" into pDriveLetter
    if length(pDriveLetter) = 1 then put ":" after pDriveLetter
    set the hideConsoleWindows to true
    if the shellCommand <> "command.com" then
      put shell(pDriveLetter && "& dir") into tData
      put "c:\temp.bat" into tBatPath
      put pDriveLetter & cr & "dir" into url ("file:" & tBatPath)
      put shell("start" && tBatPath) into tData
      delete file tBatPath
    end if
    put matchText(tData,"(?s)Serial Number is\W*(.*?)\n",tID) into tIsMatch
  end switch
  if tIsMatch then
    return tID
    return "Error: Can't locate serial number."
  end if
end stsGetSerialNumber


Ken Ray
Sons of Thunder Software
Web site: http://www.sonsothunder.com/
Email: kray at sonsothunder.com

More information about the Use-livecode mailing list