[[+content_image]]
D
D
Darexu2019-03-21 04:50:21
API
Darexu, 2019-03-21 04:50:21

How to get hard drive serial number via Win API in Lua?

local ffi = require("ffi")
ffi.cdef[[
int __stdcall GetVolumeInformationA(
    const char* lpRootPathName,
    char* lpVolumeNameBuffer,
    uint32_t nVolumeNameSize,
    uint32_t* lpVolumeSerialNumber,
    uint32_t* lpMaximumComponentLength,
    uint32_t* lpFileSystemFlags,
    char* lpFileSystemNameBuffer,
    uint32_t nFileSystemNameSize
);
]]
local serial = ffi.new("unsigned long[1]", 0)
ffi.C.GetVolumeInformationA(nil, nil, 0, serial, nil, nil, nil, 0)
serial1 = serial[0]

This is how you can get the serial number of a logical drive, but how can you get the serial number of a hard drive?

Answer the question

In order to leave comments, you need to log in

[[+comments_count]] answer(s)
Z
Zettabyte, 2019-03-21
@Zettabyte

Through WinAPI on pure Lua, I think that it will hardly work. But with the use of some module, I think it is possible. But there is already a question to the API of the module.
And one more thing: if you are interested in the combination "working with hard disks + LUA" , then be sure to look at R.tester .
We have built the LUA interpreter inside the program and drive diagnostics is carried out using the rules described in the form of a program code.
The project is developing with might and main and we have yet to write a detailed guide on how to create our own scripts and rules, but the program can already be used right now. The emphasis is specifically placed on the safety of work, so that something will not be spoiled or ruined.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question