*/***************************************************************************
*# WScript.Network.Information
*/Program : UNC_INFO.PRG
*/System : library
*/Purpose : Take a UNC path / Drive Letter and returns the drive letter / UNC Path
*/Syntax : string = unc_info(Action,Value)
*/Parameter : action - string - Type of Action to perform
*/ : Value - string - A UNC name or a Drive Letter to act on
*/Returns : string - drive letter or UNC for the users computer
*/Defaults : none
*/Requires : none
*/Changes : none
*/Calls : none
*/Version :
*/Dated : 01/10/2005
*/Written By: David Grewe
*/***************************************************************************
*&Utility
*
* Action Values - Network
* L=Drive Letter - Value format needs to be \\server\volume
* M=Map Drive - Value format needs to be \\server\volume
* R=Remove Map - Value format needs to be "D:"
* S=Server UNC - Value format needs to be "D:"
*
* Action Values - Computer
* N=Computer Name - Value not required
* D=Domain Name - Value not required
* U=User Name - Value not required
*
*/***************************************************************************
*/ Record Of Change
*/
*/***************************************************************************
FUNCTION UNC_INFO
LPARAMETERS pcAction,pcValue
IF PARAMETERS()<1 OR VARTYPE(pcAction)<>"C" OR EMPTY(pcAction)
RETURN ''
ENDIF
IF PARAMETERS()<2 OR VARTYPE(pcValue)<>"C" OR EMPTY(pcValue)
RETURN ''
ENDIF
*
LOCAL WshNetwork,oDrives,i,lcValue,lcRetVal
STORE ALLTRIM(UPPER(pcValue)) TO pcValue,lcValue
STORE '' TO lcRetVal
*
* Get an array of Drive letters used and the UNC's assigned to them
*
WshNetwork=createobject("WScript.Network")
oDrives=WshNetwork.EnumNetworkDrives &&NOTE: This array is 0 based
*
DO CASE
CASE pcAction = "L" && drive letter for UNC -
*
* pcValue should be "\\Server\volume" format
* Check to see if UNC is in the array
*
FOR i=0 TO oDrives.count-1 STEP 2
lcValue=ALLTRIM(UPPER(oDrives.Item[i+1]))
IF lcValue=pcValue
lcRetVal=ADDBS(oDrives.Item[i])
EXIT
ENDIF
ENDFOR
*
CASE pcAction = "M" && Map a new drive letter
*
* pcValue should be "\\Server\volume" format
* Find an unused Drive letter on Computer
*
DIMENSION laFields[1]
LOCAL lnOnError,llError
FOR i = 69 TO 90
=ADIR(laFiles,CHR(i)+":" , "SV")
IF EMPTY(laFiles[1])
lcRetVal = CHR(i)+":"
EXIT
ENDIF
ENDFOR
IF !EMPTY(lcRetVal)
lcOnError = ON("ERROR")
ON ERROR llError=.t.
WshNetWork.MapNetWorkDrive(lcRetVal , pcValue)
ON ERROR &lcOnError
ENDIF
*
lcRetVal=IIF(llError,'',lcRetVal)
RELEASE laFields,lcOnError,llError
*
CASE pcAction = "R" && Remove Drive letter Map
*
* pcValue should be "M:" format
* Does the Drive Letter Map still exist
*
pcValue = LEFT(pcValue,2)
LOCAL lcOnError,llError
DIMENSION laFiles[1]
*
=ADIR(laFiles,pcValue , "SV")
IF !EMPTY(laFiles[1])
lcOnError = ON("ERROR")
ON ERROR llError=.t.
WshNetWork.RemoveNetWorkDrive(pcValue, .t., .t.)
ON ERROR &lcOnError
ENDIF
*
lcRetVal=IIF(llError,pcValue,'')
RELEASE laFiles,lcOnError,llError
*
CASE pcAction = "S" && Server Name for Drive Letter
*
* pcValue should be "M:" format
* Check to see if UNC is in the array
*
FOR i=0 TO oDrives.count-1 STEP 2
IF ALLTRIM(UPPER(oDrives.Item[i])) = pcValue
lcRetVal=ADDBS(oDrives.Item[i+1])
EXIT
ENDIF
ENDFOR
*
CASE pcAction = "C" && Computer Name
lcRetVal=WshNetwork.ComputerName
*
CASE pcAction = "D" && Domain
lcRetVal=WshNetwork.UserDomain
*
CASE pcAction = "U" && User NAme
lcRetVal=WshNetwork.UserName
*
ENDCASE
*
RELEASE pcAction,pcValue
RELEASE WshNetwork,oDrives
RELEASE i,lcValue
RETURN lcRetVal