Use UNC Names to Refer to Network Drives

If you write programs that access information on a network server, you never want to hard-code drive letters. Not all software vendors take advantage of the Uniform Naming Convention (UNC) (for example, \SERVERVOLUME ) technology. Use these API declarations:

 Public 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 LongPublic Function GetNetworkDrive(FileSystem _	As String, VolumeName As String) As String	'Returns the first mapped drive letter 	'if successful or "NODRIVE" if fails.	'FileSystem and SysName refer to the 	'Network file system type: 	'NWCOMPA	=> Novell	'NTFS	=> Microsoft	'FAT		=> LocalMicrosoft	Dim SerialNum As Long, SysFlags As Long	Dim retVal As Long, Complength As Long	Dim VolBuff As String * 255, SysName As String * 255	Dim DrivePath As String	Dim i As Integer	GetNetworkDrive = "NODRIVE"	For i = 70 To 90		DrivePath = Chr(i) & ":"		retVal = GetVolumeInformation _			(DrivePath, VolBuff, 255, _			SerialNum, Complength, SysFlags, SysName, 255)		If (Mid$(VolBuff, 1, Len(VolumeName)) _			= UCase$(VolumeName)) And(Mid$(SysName,1, Len _			(FileSystem)) = FileSystem) Then				GetNetworkDrive = DrivePath				Exit For		End If	Next iEnd Function

Here’s the wrong and right ways to refer to network drives:

 Option ExplicitPublic Sub OpenDatabase()	'The Wrong Way!	Dim filespec as String	filespec = "H:PUBLICAPPSBTRIEVEMYDB.RDB"	'Some third-party control that opens the 	'database file.	...	...	... End SubPublic Sub OpenDatabase()	'A Better Way!	Dim filespec as String	Dim Vol1Drive As String	Vol1Drive = GetNetworkDrive("NWCOMPA","VOL1")	If Vol1Drive = "NODRIVE" Then 		MsgBox "Unable to open database. " & _			"The user does not have a " & _			"drive letter mapped to VOL1" 	Else		filespec = Vol1Drive & _			"PUBLICAPPSBTRIEVEMYDB.RDB"		'Some third-party control that opens 		'the database file. 		...		... 		...	End IfEnd Sub
Share the Post:
Share on facebook
Share on twitter
Share on linkedin


The Latest

your company's audio

4 Areas of Your Company Where Your Audio Really Matters

Your company probably relies on audio more than you realize. Whether you’re creating a spoken text message to a colleague or giving a speech, you want your audio to shine. Otherwise, you could cause avoidable friction points and potentially hurt your brand reputation. For example, let’s say you create a

chrome os developer mode

How to Turn on Chrome OS Developer Mode

Google’s Chrome OS is a popular operating system that is widely used on Chromebooks and other devices. While it is designed to be simple and user-friendly, there are times when users may want to access additional features and functionality. One way to do this is by turning on Chrome OS

homes in the real estate industry

Exploring the Latest Tech Trends Impacting the Real Estate Industry

The real estate industry is changing thanks to the newest technological advancements. These new developments — from blockchain and AI to virtual reality and 3D printing — are poised to change how we buy and sell homes. Real estate brokers, buyers, sellers, wholesale real estate professionals, fix and flippers, and beyond may