A unique ID for protection?

  • Thread starter Thread starter CAA
  • Start date Start date
C

CAA

Hello, ..Hope you all enjoyed the jollies

Does anybody know a routine to get an unique ID from each computer.
would like to use it for preventative copying.

Thanks for looking
CA
 
Here is one way, get the C drive volume number

Function DiskVolumeId() As String
Dim FSO As Object

Set FSO = CreateObject("Scripting.FileSystemObject")
DiskVolumeId = Format(CDbl(FSO.Drives("C:").SerialNumber))
End Function

--

HTH

Bob Phillips
... looking out across Poole Harbour to the Purbecks
(remove nothere from the email address if mailing direct)
 
Hi
you may use the HD drive ID for this. The following code gets this
number:

Declare Function GetVolumeInformation Lib "kernel32" Alias _
"GetVolumeInformationA" (ByVal lpRootPathName As String, ByVal _
lpVolumeNameBuffer As String, ByVal nVolumeNameSize As Long, _
lpVolumeSerialNumber As Long, lpMaximumComponentLength As Long, _
lpFileSystemFlags As Long, ByVal lpFileSystemNameBuffer As String, _
ByVal nFileSystemNameSize As Long) As Long

Function get_drive_serial()
Const cMaxPath = 256, cDrive = "C:\"
Dim lngtemp
Dim strTemp As String, lngRet As Long
Dim lngVolSerial As Long, strVolName As String * cMaxPath
Dim lngMaxCompLen As Long, lngFileSysFlags As Long
Dim strFileSysName As String * cMaxPath

lngRet = GetVolumeInformation(cDrive, strVolName, cMaxPath, _
lngTemp, lngMaxCompLen, lngFileSysFlags, strFileSysName, _
cMaxPath)
strTemp = Format(Hex(lngTemp), "00000000")
strTemp = Left(strTemp, 4) & "-" & Right(strTemp, 4)

get_drive_serial = strTemp
End Sub
 
Hi Bob
this is not fair
I had the same idea but my code is much longer :-)
 
As I keep telling my kids, life ain't fair!

I once wrote a complex class for reading and writing to the registry, and
then WSH came out with a RegRead and RegWrite method. Half a dozen lines. So
don't talk to me about fair<G>

Bob
 
Excellent stuff Bob.

I'm amazed how simple you made that, i was expecting something mor
along the lines of Franks and the headache that follwed trying t
understand it, but now, ..wow. Very impressed.

Thankyou once again Bob for another on the ball answer.

Frank, what can i say, the guy on the motorbike will usually win th
marathon.

CA
 
The thing about Frank's is that you don't need to understand it if you want
a solution. When we provide API solutions they are never obvious, APIs
aren't, but if they work, what the heck, use them.

--

HTH

Bob Phillips
... looking out across Poole Harbour to the Purbecks
(remove nothere from the email address if mailing direct)
 
Excellent stuff Bob.
I'm amazed how simple you made that, i was expecting something more
along the lines of Franks and the headache that follwed trying to
understand it, but now, ..wow. Very impressed.

Thankyou once again Bob for another on the ball answer.

Frank, what can i say, the guy on the motorbike will usually win the
marathon.

lol
hat's really a got methapher
Regards
Frank
 
Hi,
this thread is just what I was looking for -- much thanks to all !
Having said that, I am going to show my ignorance.
I program in Visual Studio .NET VB for a while now & have not come accross
a part of your example :

strVolName As String * cMaxPath

VB gives me an error on the "* cMaxPath" expects end ot statment.

Not sure what this syntax means - Thanks Again


----- Frank Kabel wrote: -----

Hi
you may use the HD drive ID for this. The following code gets this
number:

Declare Function GetVolumeInformation Lib "kernel32" Alias _
"GetVolumeInformationA" (ByVal lpRootPathName As String, ByVal _
lpVolumeNameBuffer As String, ByVal nVolumeNameSize As Long, _
lpVolumeSerialNumber As Long, lpMaximumComponentLength As Long, _
lpFileSystemFlags As Long, ByVal lpFileSystemNameBuffer As String, _
ByVal nFileSystemNameSize As Long) As Long

Function get_drive_serial()
Const cMaxPath = 256, cDrive = "C:\"
Dim lngtemp
Dim strTemp As String, lngRet As Long
Dim lngVolSerial As Long, strVolName As String * cMaxPath
Dim lngMaxCompLen As Long, lngFileSysFlags As Long
Dim strFileSysName As String * cMaxPath

lngRet = GetVolumeInformation(cDrive, strVolName, cMaxPath, _
lngTemp, lngMaxCompLen, lngFileSysFlags, strFileSysName, _
cMaxPath)
strTemp = Format(Hex(lngTemp), "00000000")
strTemp = Left(strTemp, 4) & "-" & Right(strTemp, 4)

get_drive_serial = strTemp
End Sub
 
Dim strVolName As String * cMaxPath
in classic VB defines a fixed length string.

This has probably gone missing in .Net

The alternative is to dim the variable as string then make sure it's
long enough before using it.

Dim strVolName As String
Dim strFileSysName As String
strVolName = String$(255, Chr$(0))
strFileSysName = String$(255, Chr$(0))

also works in classic VB.

If the String$ function has also gone missing in .Net you may need to
try something else similar
 
Steve said:
Dim strVolName As String * cMaxPath
in classic VB defines a fixed length string.

This has probably gone missing in .Net

The alternative is to dim the variable as string then make sure it's
long enough before using it.

Dim strVolName As String
Dim strFileSysName As String
strVolName = String$(255, Chr$(0))
strFileSysName = String$(255, Chr$(0))

also works in classic VB.

Sorry, that should have more properly been:

strVolName = String$(cMaxPath, Chr$(0))
strFileSysName = String$(cMaxPath, Chr$(0))
 
If it makes you feel any better, Frank, Bob's nasty code doesn't work
here. :-)

We disable WSH at ever reboot.

Getting it to die is another matter though.
 
Steve - Thanks much - in now makes sense.
It's always amazes me how we can spend so much time on such small issues
Thanks again
 
I'm not really very familiar with vb.net syntax and this thread is
rapidly drifting off-topic for this group.

However, you seem to have changed the logic of the function so that it
returns lngRet instead of lngtemp, which is where the volume serial
number for drive c:\ is returned.

lngRet is the return value of the API function and the only thing I know
about it for sure is that zero indicates failure.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top