Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Determining UNC coding 1

Status
Not open for further replies.

SGLong

Programmer
Jun 6, 2000
405
US
Is there any way in VFP to determine (and therefore utilize) the Universal Naming Convention settings for network drives? On my computer I reference 'N-Drive' which is \\Server2. On other computers, the \\Server2 might be called some other letter. If I could determine the UNC setting, then the apps I write would be truly portable from computer to computer thoughout our organization. [sig][/sig]
 
Using the Network Object of the Windows Scripting Host:

FUNCTION GetUNCPath
LPARAMETERS tcMappedDriveLetter

LOCAL lcRetPath,WshNetwork,oDrives,i

lcRetPath = ''
IF TYPE('tcMappedDriveLetter')<>'C'
RETURN lcRetPath
ENDIF
tcMappedDriveLetter=LEFT(tcMappedDriveLetter,1)
IF !DIRECTORY(tcMappedDriveLetter+':')
RETURN lcRetPath
ENDIF

WshNetwork = CREATEOBJECT(&quot;WScript.Network&quot;)
oDrives = WshNetwork.EnumNetworkDrives

*NOTE: this array is 0 based
FOR i = 0 To oDrives.Count - 1
IF oDrives.Item(i)=tcMappedDriveLetter
lcRetPath=oDrives.Item(i+1)
EXIT
ENDIF
ENDFOR

RETURN lcRetPath
ENDFUNC

If you can't use the WSH for whatever reasons, you can still do it with the API. [sig]<p>Jon Hawkins<br><a href=mailto: jonscott8@yahoo.com> jonscott8@yahoo.com</a><br><a href= > </a><br>Focus on the solution....Not the problem.[/sig]
 
The way I do it is to have a table called SERVERS with the fields.
Name c, 8 candidate tag name
UNC c, 25
DriveLtr c, 2
Description, c 50

I then have a function that opens the server table, seeks the server.name and returns a string from the field I want.
lcServer = server(&quot;SERVER2&quot; , &quot;UNC&quot;)
copy file xxx. to (lcServer +&quot;xxx&quot;)
or
lcServer = server(&quot;SERVER2&quot; , &quot;DRIVELTR&quot;)
copy file xxx. to (lcServer +&quot;xxx&quot;)
or
scatter the table to an array and use the array in applications as needed.

I'm sure 10 more people will give you about 20 more ways of doing it. [sig]<p>David W. Grewe<br><a href=mailto:Dave@internationalbid.net>Dave@internationalbid.net</a><br>[/sig]
 
Many thanks Jon and Dave. I'll try both these methods out and let you know the results. [sig][/sig]
 
Both Jon's and Dave's routines work fine. Jon's has the advantage of always having the latest info available without having to update a table, though. I took the code and reversed it into the following routine which will take the UNC path and return the local drive letter. Now my apps can be truly portable in WAN situations. Many thanks.

** FILE: UNC2LTR.PRG
** Take a UNC path and return the drive letter
lparameters tcUNCPath
local WshNetwork, oDrives, i, lcUNCPath
lcUNCPath=upper(tcUNCPath)
WshNetwork=createobject(&quot;WScript.Network&quot;)
oDrives=WshNetwork.EnumNetworkDrives
*NOTE: This array is 0 based
for i=0 to oDrives.count-1 step 2
if oDrives.Item(i+1)=lcUNCPath
return oDrives.Item(i)+':'
exit
endif
endfor
[sig][/sig]
 
Your routine works for servers you are connected when the routine is run. NOW, What do you do when you need to access a server/drive/file you are not connected to? Do you make a connection to all your servers/shared drives/directories on boot up? [sig]<p>David W. Grewe<br><a href=mailto:Dave@internationalbid.net>Dave@internationalbid.net</a><br>ICQ VFP ActiveList #46145644[/sig]
 
I have server name &quot;Checkin&quot;
On checkin i have share name TVQT
In TVTQ i have dbf worker.dbf

In VFP i use command:

use &quot;\\checkin\TVQT\worker&quot;. Surprisingly, it works

smiletiniest.gif


Jimmy K

[sig][/sig]
 
In Hacker's guide they said that directory() function don;t woks with UNC. It works! But need to be very careful, because sometimes this function weeps when share name is incorrect.
This shows that VFP works with UNC at all. BUT, it is quite slow to open tables by such way. In practise, working with data from mapped drive is more quick than working directly. [sig]<p>Vlad Grynchyshyn<br><a href=mailto:vgryn@softserve.lviv.ua>vgryn@softserve.lviv.ua</a><br>[/sig]
 
JimmyK,

I read your comment about &quot;Checkin&quot; and I must be missing something. What does this routine do?

SGLong
[sig][/sig]
 
JimmyK:

I read your comment about &quot;Checkin&quot; and I must be missing something. What does this routine do?

Dave:
In our organization, with over 200 workstations, we are all connected to the servers. It's just that not everybody uses the same drive designators across the board. What I might refer to as 'N-Drive' other users refer to by different drive letters. Storing the UNC in a file and then decoding that to the workstations mapping scheme makes all the files universally available without any 'unable to locate' problems.


SGLong
[sig][/sig]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top