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 SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Use of UNC name for mapped drive. 3

Status
Not open for further replies.

coldan

Programmer
Oct 19, 2008
98
0
0
AU
In my application I allow the user to select a path ( to replace an existing path)

Sometimes these will be on a NAS.

I also use the app on more than one PC - each has a different drive letter mapped to the root of the share on the NAS.

At the moment the newly selected path is inserted as the mapped path. - say U: or V: for example

Consequently when used on the other PC the path cannot be found.

I would like to mandate that the FULL UNC patrh is used for a path selection.

Is this possible?

Thanks

Coldan
 
You could quite easily do that by ensuring that the path started with a double backslash.

Code:
IF LEFT(myPath,2) <> "\\"
  Messagebox("You must use a full UNC path name",48,"Problem")
Endif

Regards

Griff
Keep [Smile]ing

There are 10 kinds of people in the world, those who understand binary and those who don't.
 
Griff,

Sorry,

Thanks for that but the selection is made within the code/prg by the use of the seldirdlg() dialogue box. I should have made this clear before.

Coldan

 
You need to lookup which UNC name should go for a mapped drive after the directory selection. First of all Drivetype("U") would be 4, if it's a mapped drive. And then you can find out to where it points via run net use U: > remoteunc.txt.

Afterwards read in the txt and parse the UNC path from the second line.

There should even be a more elegant API function for that, the main point is DriveType() is telling you, it's not a local but a network attached drive.

Bye, Olaf.
 
Check:
ANETRESOURCES() function in HELP.

Borislav Borissov
VFP9 SP2, SQL Server 2000/2005.
 
Hi,
try to user my function who use an API-call.
FUNCTION GetUNCPath
LPARAMETERS tcPath
LOCAL lcBuffer, lnBufsize, lnError, lcReturn

lcReturn = ""
lnBufsize = 260
tcPath = LEFT( tcPath, 1 ) + ":"
lcBuffer = REPLICATE( CHR(0), lnBufsize )

DECLARE INTEGER WNetGetConnection IN WIN32API STRING lpLocalName, STRING @lpRemoteName, INTEGER @lpnLen

lnError = WNetGetConnection( tcPath, @lcBuffer, @lnBufsize )

IF lnError = 0
lcReturn = ADDBS( LEFT( lcBuffer, AT(CHR(0), lcBuffer ) -1 ) )
ENDIF

RETURN lcReturn
 
Thanks SoftArt,

I have one problem with it eg

U: is a mapped server share say MyABCData

I want to select a folder in a subfolder in \projects

so

Input path U:\Projects\Coldan\

Output path \\SERVER\MyABCData

Any ideas how to get \\SERVER\MyABCData\Projects\Coldan\ ?

Thanks Coldan
 
Problem Solved

in seldirdlg()

cMypictarget = Addbs(cPathToReturn)
cPathToReturn = GetUNCPath(cMypictarget)
Return cPathToReturn

Function GetUNCPath
Lparameters tcPath,tcFolder
Local lcBuffer, lnBufsize, lnError, lcReturn

lcReturn = ""
lnBufsize = 260
tcorigpath = tcPath
tcFolder = Subst( tcPath, 4,Len(tcPath) )
tcPath = Left( tcPath, 1 ) + ":"
lcBuffer = Replicate( Chr(0), lnBufsize )

Declare Integer WNetGetConnection In WIN32API String lpLocalName, String @lpRemoteName, Integer @lpnLen

lnError = WNetGetConnection( tcPath, @lcBuffer, @lnBufsize )

If lnError = 0
lcReturn = Addbs( Left( lcBuffer, At(Chr(0), lcBuffer ) -1 ) )
lcReturn = lcReturn+tcFolder
Else
lcReturn = tcorigpath
Endif

Return lcReturn
 
Well, you already solved it. But you could simply split you path U:\Projects\Coldan\ into the pure drive letter portion U:\ and the path \Projects\Coldan\, lookup the UNC path for U: and append \Projects\Coldan\ to get the result value.

But WNetGetConnection was what I was thinking of initially anyway. It's also used here:
Bye, Olaf.
 
Olaf,

Thanks for that.

I ran the prg and I see my mapped drives showing red crosses showing red crosses.

I use WIN 7 'sleep' all the time and I find that when the PC wakes up my mapped drive shows the crosses.

It seems to me that it would be desirable to

1 Check if mapped drive is available.

2 'Open' the mapped drives.

Is there a way to do point 2 in my program as image files are often stored on a NAS and my program will report that they are missing if the drive is not available?

Regards

Coldan
 
I have added this code into my seldirdlg() so that I msg if a network drive is selected and give the user the option to proceed or select another drive.

I found that this routine 'woke up' the sleeping drives so I have added it to main.prg. to wake them all up before the application starts the mainform. Then it won't matter where the image files are.

I will test this tomorrow when I start work as this is when I see the red crosses.

Coldan
 
Sadly that did not wake up the drives this morning. But a selection in seldirdlg() does.

Is there another API I could use?


Coldan
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top