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/
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...
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
--
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
>
>
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...
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.
--
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...
lol
hat's really a got methapher
Regards
Frank
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: -----
Sorry, that should have more properly been:
strVolName = String$(cMaxPath, Chr$(0))
strFileSysName = String$(cMaxPath, Chr$(0))
We disable WSH at ever reboot.
Getting it to die is another matter though.
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