VBA - How to get the serial number of UNC Drive Without API calling

Luthius

Active Member
Joined
Apr 5, 2011
Messages
271
Guys
For security reasons I want that my workbook can only be used if it is on a network.
This network sometimes is mapped by user with different Letters.
I would like to find a way to get the serial number of the network drive based on the UNC path instead of Drive Letter.
But I would like to do it without API calling because some computers have issues on their Windows.
 

Some videos you may like

Excel Facts

How can you turn a range sideways?
Copy the range. Select a blank cell. Right-click, Paste Special, then choose Transpose.

Luthius

Active Member
Joined
Apr 5, 2011
Messages
271
I have the code below but is necessary to inform the Letter. I want by UNC drive path.

Code:
[COLOR=#0000ff]Public Function[/COLOR] HDSerialNumber() [COLOR=#0000ff]As String

[/COLOR][COLOR=#0000ff]Dim[/COLOR] fsObj [COLOR=#0000ff]As Object[/COLOR]
[COLOR=#0000ff]Dim [/COLOR]Drv [COLOR=#0000ff]As Object[/COLOR]
    [COLOR=#0000ff]Set[/COLOR] fsObj = [COLOR=#0000ff]New [/COLOR]Scripting.FileSystemObject
    [COLOR=#0000ff]Set[/COLOR] Drv = fsObj.Drives("[COLOR=#ff0000][B]J[/B][/COLOR]")
    HDSerialNumber = Left(Hex(Drv.SerialNumber), 4) _
                     & "-" & Right(Hex(Drv.SerialNumber), 4)
   
[COLOR=#0000ff]End Function[/COLOR]
 
Last edited:

Watch MrExcel Video

Forum statistics

Threads
1,089,969
Messages
5,411,571
Members
403,380
Latest member
ifog671

This Week's Hot Topics

Top