Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

A unique ID for protection?

1 view
Skip to first unread message

CAA <>

unread,
Apr 13, 2004, 5:09:19 PM4/13/04
to
Hello, ..Hope you all enjoyed the jollies

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

Thanks for looking
CAA


---
Message posted from http://www.ExcelForum.com/

Bob Phillips

unread,
Apr 13, 2004, 5:51:02 PM4/13/04
to
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)

"CAA >" <<CAA.1...@excelforum-nospam.com> wrote in message
news:CAA.1...@excelforum-nospam.com...

Frank Kabel

unread,
Apr 13, 2004, 5:54:09 PM4/13/04
to
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

--
Regards
Frank Kabel
Frankfurt, Germany

Frank Kabel

unread,
Apr 13, 2004, 5:55:51 PM4/13/04
to
Hi Bob
this is not fair
I had the same idea but my code is much longer :-)

--
Regards
Frank Kabel
Frankfurt, Germany


Bob Phillips wrote:
> 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
>
>

Bob Phillips

unread,
Apr 13, 2004, 6:19:06 PM4/13/04
to
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


"Frank Kabel" <frank...@freenet.de> wrote in message
news:Oy7MVIaI...@tk2msftngp13.phx.gbl...

CAA <>

unread,
Apr 14, 2004, 6:47:06 AM4/14/04
to
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.

Bob Phillips

unread,
Apr 14, 2004, 7:10:35 AM4/14/04
to
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)

"CAA >" <<CAA.1...@excelforum-nospam.com> wrote in message
news:CAA.1...@excelforum-nospam.com...

Frank Kabel

unread,
Apr 14, 2004, 8:21:07 AM4/14/04
to
> 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

Steve Garman

unread,
Apr 15, 2004, 1:57:01 AM4/15/04
to
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

Gehres wrote:

> 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: -----

Steve Garman

unread,
Apr 15, 2004, 2:02:44 AM4/15/04
to
Steve Garman wrote:
> 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))

Steve Garman

unread,
Apr 15, 2004, 2:10:00 AM4/15/04
to
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.

Frank Kabel

unread,
Apr 15, 2004, 3:31:44 AM4/15/04
to

Hi Steve
you made my day <vbg>

Steve Garman

unread,
Apr 16, 2004, 1:06:01 AM4/16/04
to
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.

Gehres wrote:

> Hi again - more questions
>
> to get this code to return a value in VB.NET I altered it to the code shown below. It returns a 16 digit integer/string but I am not sure what the value represents. The Function GetVolumeInformation is not specific as to the value it returns. Is that the physical hard drives serial #? if so How does one tell?


>
> Declare Function GetVolumeInformation Lib "kernel32" Alias _
> "GetVolumeInformationA" (ByVal lpRootPathName As String, ByVal _
> lpVolumeNameBuffer As String, ByVal nVolumeNameSize As Long, _

> ByVal lpVolumeSerialNumber As Long, ByVal lpMaximumComponentLength As Long, _
> ByVal 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.ToString


> Dim lngMaxCompLen As Long, lngFileSysFlags As Long

> Dim strFileSysName As String = cMaxPath.ToString


>
> lngRet = GetVolumeInformation(cDrive, strVolName, cMaxPath, _

> lngtemp, lngMaxCompLen, lngFileSysFlags, strFileSysName, _
> cMaxPath)
>
> strTemp = lngRet.ToString
>
> get_drive_serial = strTemp
> End Function

0 new messages