WinBatch Tech Support Home

Database Search

If you can't find the information using the categories below, post a question over in our WinBatch Tech Support Forum.

TechHome

How To
plus
plus
plus
plus
plus
plus
plus
plus
plus
plus
plus

Can't find the information you are looking for here? Then leave a message over on our WinBatch Tech Support Forum.

How to Get Persistent Drive Mappings

Keywords:      Persistent Drive Mappings

Question:

Is there any way to read the persistant drive table in Window95? What file is the persitant drive table located?

Answer:

It is in the Registry:
	@REGCURRENT, "Network\Persistent"
Use RegQueryKeys to get any and all subkeys to the above key. They will be listed by drive letter.

If you have drives F: and Z: mapped persistently, you will have keys:

	@REGCURRENT, "Network\Persistent\F"
	@REGCURRENT, "Network\Persistent\Z"
Each drive key will have 3 values:
ProviderName, RemotePath, and UserName
	@REGCURRENT, "Network\Recent"
refers to a set of subkeys for non-persisten (ie-this session only) mappings. They are not listed by drive letter, but by the RemotePath (the mapping path).

Here's a routine to get the list of Permanent drives and save them to an INI file. Then I would use the file to delete the permanent connections and restore them later. This was to get around a bug with the Novell IntranetWare Client 2.20 which would change Microsoft Perm. mappings to Novell mappings and fail.

:GetPermDriveList

; initialize variable for itemized list
PersConDriveList=""
DriveList="Network\Persistent"

PersConKey=RegOpenKey(@REGCURRENT,DriveList)
   PersConList=RegQueryKeys(PersConKey)
RegCloseKey(PersConKey)

PersConListCnt=ItemCount(PersConList,@TAB)

; create loop to verify if connections are Microsoft Drive Mappings

For PersConListCheck=1 to PersConListCnt
   ; create list for each persistent connection
   PersConKeyListDrive=ItemExtract(PersConListCheck,PersConList,@TAB)
   PersConKey=StrCat(DriveList,"\",PersConKeyListDrive)
   ;PersConKey=StrCat(DriveList,"\","N")
   PersConCheckKey=RegOpenKey(@REGCURRENT, PersConKey)
   ; create list for parameters associated with current connection
   PersConCheckKeyList=RegQueryItem(@REGCURRENT,PersConKey)
   ;PersConCheckKeyList=RegQueryItem(PersConCheckKey,"\N")
   RegCloseKey(PersConCheckKey)
   
   PersConListCheckItemCnt=ItemCount(PersConCheckKeyList,@TAB)
   ; check for at least 3 items in list which indicates a current persistent drive mapping
   ; and don't bother checking for drive info if not
   
   If PersConListCheckItemCnt>=3
  
   ; if 3 items or more, check if Microsoft Network drive mapping
   
   PersConCheckMSDriveItem=StrCat(PersConKey,"\","[","ProviderName","]")
   PersConCheckMSDrive=RegQueryValue(@REGCURRENT,PersConCheckMSDriveItem)
   
      If StrCmp("Microsoft Network",PersConCheckMSDrive)==0
	; if Microsoft mapping, create list of drive letter and connection for later use
	 ;Display(2,"Current Drive Letter","Current Connection is %PersConKeyListDrive%")
	 ; add drive letter to list and add remote path name to list
   
	 PersConRemPath=StrCat(PersConKey,"\","[","RemotePath","]")
	 PersConRemPathValue=RegQueryValue(@REGCURRENT,PersConRemPath)
	 PersConDriveList=StrCat(PersConDriveList,PersConKeyListDrive,@TAB,PersConRemPathValue,@TAB)
      EndIf
   
   EndIf
Next PersConListCheck



;AskItemList("List of Microsoft Connected Drives",PersConDriveList,@tab,@unsorted,@single)
PersConDriveListCnt=ItemCount(PersConDriveList,@TAB)

For PersConDriveListPos=1 to PersConDriveListCnt by 2
   ;For PersConDriveParm=2 to PersConDriveListCnt by 2
   PersConDriveListIndex=PersConDriveListPos
   PersConDriveInfoData=ItemExtract(PersConDriveListIndex,PersConDriveList,@TAB)
   ; add : colon to drive letter info
   PersConDriveInfoData=StrCat(PersConDriveInfoData,":")
   PersConDriveListIndex=PersConDriveListIndex+1
   PersConDriveParmData=ItemExtract(PersConDriveListIndex,PersConDriveList,@TAB)
   ; create file with list of drive letters to save in case program crashes
   IniWritePvt("MS Persistent Connections",PersConDriveInfoData,PersConDriveParmData,"persdriv.ini")
   ;Display(2,"Info going to file","Writing %DriveInfo% to file")
Next PersConDriveListPos

; save list of drive mappings to Users's H:\Windows directory
If FileExist("c:\windows\persdriv.ini") then FileCopy("c:\windows\persdriv.ini","h:\windows",@FALSE)
return

; this routine will read the PERSDRIV.INI file to get previously mapped list of MS
; persistent drive mappings and delete them to avoid problems later on
:DelMSPermDrives

PersINIFile="persdriv.ini"
PersINIFileHeader="MS Persistent Connections"
DriveList=IniItemizePvt(PersINIFileHeader,PersINIFile)
;AskItemList("List of Drive Mappings",DriveList,@tab,@unsorted,@single)
DriveListCnt=ItemCount(DriveList,@TAB)

For DriveListCntData=1 to DriveListCnt
   DriveListData=ItemExtract(DriveListCntData,DriveList,@TAB)
   ErrorMode(@OFF)
   If StriCmp("O:",DriveListData)!=0 then w95CancelCon(DriveListData,@TRUE,@TRUE)
   ErrorMode(@CANCEL)
   DriveInfo=IniReadPvt(PersINIFileHeader,DriveListData,"",PersINIFile)
Next DriveListCntData

; all MS connected drives should be deleted by now
Return

Article ID:   W13159
Filename:   Get Persistent Drive Mappings.txt
File Created: 2005:09:15:12:27:52
Last Updated: 2005:09:15:12:27:52