View previous topic :: View next topic |
Author |
Message |
yazigegeda Expert Cheater
Reputation: 0
Joined: 22 Jan 2019 Posts: 183
|
Posted: Sat Aug 22, 2020 7:29 pm Post subject: How to get a list of drives? |
|
|
Hypothesis:
Code: |
a=Getdrivelist()
for i,v in ipairs(a) do
print(v)
end
print:
C
D
E
F
|
Can it be achieved? help me!
Description: |
|
Filesize: |
24.23 KB |
Viewed: |
1576 Time(s) |

|
|
|
Back to top |
|
 |
panraven Grandmaster Cheater
Reputation: 62
Joined: 01 Oct 2008 Posts: 958
|
Posted: Sun Aug 23, 2020 4:44 am Post subject: |
|
|
Only work for single letter drives, other info may be easier via an external os command ( power shell thing? )
Code: |
function GetDriveLetters() -- return an array table of drive letters
local M = executeCodeLocal'GetLogicalDrives'
local drives, dc,dclast = {}, string.byte('AZ',1,-1)
while M and M ~= 0 and dc <= dclast do
if (M & 1) ~= 0 then drives[1+#drives] = string.char(dc)end
dc, M = dc + 1, M >> 1
end
return drives
end
--
print(table.concat(GetDriveLetters(),'\r\n'))
|
_________________
- Retarded. |
|
Back to top |
|
 |
Corroder Grandmaster Cheater Supreme
Reputation: 75
Joined: 10 Apr 2015 Posts: 1668
|
Posted: Sun Aug 23, 2020 6:40 am Post subject: |
|
|
If want the result as : "C:\" or "D:\", etc then change @Panraven script:
from:
Code: | if (M & 1) ~= 0 then drives[1+#drives] = string.char(dc)end |
to:
Code: | if (M & 1) ~= 0 then drives[1+#drives] = string.char(dc)..":\\" end |
Other solution:
Using WMI and pipe output to text file:
Code: |
os.execute("wmic /OUTPUT:D:\\mydrive.txt logicaldisk get caption,description,drivetype,providername,volumename")
shellExecute("D:\\mydrive.txt") |
Question:
@Panraven, could you show how to use kernel32 "GetLogicalDriveStrings()' in CE Lua?. Thanks in advance
_________________
Stealing Code From Stolen Code...
And Admit It.. Hmmm....Typically LOL |
|
Back to top |
|
 |
panraven Grandmaster Cheater
Reputation: 62
Joined: 01 Oct 2008 Posts: 958
|
Posted: Sun Aug 23, 2020 7:54 am Post subject: |
|
|
Code: |
function GetLogicalDriveStrings()
local ms = createMemoryStream()
local ret = executeCodeLocalEx('GetLogicalDriveStringsW',0,0)--get size in char
if ret and ret>0 then
ms.Size = ret * 2 -- wide char x2 bytes
ret = executeCodeLocalEx('GetLogicalDriveStringsW',ret,ms.Memory)
end
local bt = ret and ret~=0 and readBytesLocal(ms.Memory,ret * 2,true)
if bt then
for i=1,#bt,2 do -- replace null speartor
if bt[i]==0 then bt[i]=string.byte';'end
end
end
ret = bt and byteTableToWideString(bt)
ms.Destroy()
if not ret then
return nil,'failed, ret='..tostring(ret)
else
return ret
end
end
--
print(GetLogicalDriveStrings())
|
note: executeCodeLocalEx not work for 32bit ce
fixedx2: ^<del>make sure ms memory has been setup before call</del> should use readBytesLocal
_________________
- Retarded. |
|
Back to top |
|
 |
Corroder Grandmaster Cheater Supreme
Reputation: 75
Joined: 10 Apr 2015 Posts: 1668
|
Posted: Sun Aug 23, 2020 10:31 am Post subject: |
|
|
Thanks @Panraven, I see. So the GetLogicalDriveStrings(bufferLength, buffer) function, for the buffer is use createMemoryStream() CE Lua function.
Your script example is clear and easier to understand.
_________________
Stealing Code From Stolen Code...
And Admit It.. Hmmm....Typically LOL |
|
Back to top |
|
 |
|