Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
How to identify the server name.
Message
From
07/08/2003 14:40:53
 
 
To
07/08/2003 14:26:53
General information
Forum:
Visual FoxPro
Category:
Windows API functions
Miscellaneous
Thread ID:
00817893
Message ID:
00817907
Views:
17
Is the driver letter a UNC path? You could grab the UNC path which typically includes the servername...

For example:
clear
lcdrive=LEFT(sys(16),2)
lcunc=getuncname(lcdrive)
?lcunc
* or an example where driver K: is the one I want:
lcdrive='K:'
lcunc=getuncname(lcdrive)
? lcunc
return

FUNCTION getuncname
PARAMETERS lcdrive
*lcdrive typically is c: or k: or Y:, etc.
lcunc=getunc(lcdrive)
IF !EMPTY(lcunc) .and. "\\" $ lcunc
        * Strip out the share name
	lcunc=SUBSTR(lcunc,(AT('\\',lcunc)+2),AT('\',lcunc,3)-(AT('\\',lcunc)+2))
ENDIF
?lcunc
return lcunc


 FUNCTION GetUNC
LPARAMETER cDriveLetterToCheck
LOCAL cBuffer, nResult, lcUnc
IF TYPE('cDriveLetterToCheck') # 'C' OR ;
   LEN(cDriveLetterToCheck) < 2 OR ;
   SUBSTR(cDriveLetterToCheck,2,1) # ':' OR ;
   ! BETWEEN(UPPER(LEFT(cDriveLetterToCheck,1)),'A','Z')
   RETURN ''
ENDIF
DECLARE INTEGER WNetGetConnection IN Win32API ;
   STRING   @cLocalDrive, ;
   STRING   @cRemoteUNCBuffer, ;
   INTEGER  @nSizeOfBuffer
cBuffer = SPACE(511)
nResult = WNetGetConnection(LEFT(cDriveLetterToCheck,2), ;
                            @cBuffer, ;
                            511)
IF nResult # 0
   *  Failed - it's probably not a mapped drive,
   *  or nothing is mapped to it
   RETURN ''
ELSE
   lcUnc=LEFT(cBuffer,AT(CHR(0),cBuffer)-1)
   RETURN lcUnc
   *RETURN LEFT(cBuffer,AT(CHR(0),cBuffer)-1)
ENDIF
>I have a need to identify the server name that an executable is running from. I know I can get the path of the executable, but that contains the logical drive letter, not the name of the server. Is there a Windows API call or VFP SYS() function for this.
>
>Many thanks,
.·*´¨)
.·`TCH
(..·*

010000110101001101101000011000010111001001110000010011110111001001000010011101010111001101110100
"When the debate is lost, slander becomes the tool of the loser." - Socrates
Vita contingit, Vive cum eo. (Life Happens, Live With it.)
"Life is not measured by the number of breaths we take, but by the moments that take our breath away." -- author unknown
"De omnibus dubitandum"
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform