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
    else
      -- No OS 9 version yet
    end if
    break
  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
    else
      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
    break
  end switch
  if tIsMatch then
    return tID
  else
    return "Error: Can't locate serial number."
  end if
end stsGetSerialNumber

HTH,

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