Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Determine Drive Space and Serial Number 2

Status
Not open for further replies.

RonSeidl

Technical User
Aug 2, 2020
1
US
VFP - Determine Drive Space and Serial Number
I did a search and could not find out how to do this, So I did it myself.

objFSO = CreateObject('Scripting.FileSystemObject')
objDrive = objFSO.GetDrive('C:')
MESSAGEBOX('Available space: ' + chr(13)+TRANSFORM(objDrive.AvailableSpace,'999,999,999,999,999'+' kb' ))
MESSAGEBOX(objDrive.SerialNumber)
 
The hard drive serial number gives me a negative value, but this does not.

[pre]? 'Physical Disk'
loPhyDrives = loWMIService.ExecQuery('Select * from Win32_PhysicalMedia')
For Each loPhyDrive In loPhyDrives
? loPhyDrive.Tag,;
loPhyDrive.SerialNumber
Endfor[/pre]



If you want to get the best response to a question, please check out FAQ184-2483 first.
 
Hi,

It's good that you share your finding. You could have found this, too, and also asking even when you find something can yield some more ideas and resources you dodn't know.

VFP for example also has a DISKSPACE() function.
Code:
? TRANSFORM(Diskspace("C",2),'999,999,999,999,999'+' Bytes' )
gives the same number as the FSO drive object for me, but the reference says it's Bytes. And that works out.

Serialnumber isn't covered by native VFP language, true, but you're actually not the first to post something like that.
thread184-886892
thread184-951493
thread184-137380
thread184-756938
thread184-289352
...

In general, if you need something OS and Hardware related, VFP surely isn't #1 tool, but WNI scripts can easily be adapted for VFP. Once you have the WMIService Object (missing from Mike's code):
Code:
loWMIService = GETOBJECT("winmgmts:\\.")
or more specific like GetObject("winmgmts:\\.\root\directory\LDAP") for AD access
And others. Well, the world of WMI.

Today I'd like to do more with Powershell. Doug Henning has written about that and the last few pages also show how to run this from VFP with the help of the wwDotNetBridge:

Otherwise, a classic resource of all the functionalities the OS offers:

And one specifically sometimes problematic topic with API calls asking for structs can be covered by struct.zip by Chris Wollenhaupt, see
Anyway, some things are actually also part of VFP itself. And I wouldn't even look for how to get free Diskspace of the current user in the current thread by helper COM objects or API, when there is a native VFP function for it-

By the way, any programming language is heavily stealing from the API or nowadays the .net framework when it comes to commands related to os or hardware and that's also a reason some things like low level file functions look the same in so many languages. Once you know that DECLARE almost becomes a language extension command.

Bye, Olaf.

Olaf Doschke Software Engineering
 
In my blog I posted about retrieving several system infos, that are beyond VFP implemented abilities.
So here comes a small link list :)

in 2016
Collecting Systeminformation to generate a unique fingerprint
in 2010
Retrieving RAM infos
in 2007
Using Windows Scripting Host to query drive informations

IMHO the first link is the most interesting one as it also shows how to retrieve MAC adresses, drivetypes and CPU-IDs

The idea behind it was to generate a SystemID that doesn't become obsolet as soon as a CPU, HD or Networkcard had to be replaced. So the generated ID has several parts and has to be renewed only if this happened to more than 1 segment.

JM2C ;)


-Tom
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top