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

RAS

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

RasItemize Issue on Vista and Newer

 Keywords: RasItemize RasItemizeEx Win7 Vista XP RasEnumEntries 



; RasItemize for Windows XP a newer
#DefineFunction RasItemizeEx(szPhoneBook)
   ; [szphonebook] must be a full file path to an existing 'rasphone.pbk' file or a blank string to
   ; enumerate from all the remote access phone-book files in the AllUsers profile and the user's profile.
   ;szphonebook = 'C:\Users\All Users\Microsoft\Network\Connections\Pbk\rasphone.pbk'
   ;szPhoneBook = 'C:\Users\Standard\AppData\Roaming\Microsoft\Network\Connections\Pbk\rasphone.pbk'
   ;szphonebook = ''

   ;Check if phonebook file exists
   If szPhoneBook != ''
      If !FileExist(szPhoneBook)
         Pause('RasItemizeEx Failed:', 'Phonebook file does not exist')
         Exit
      EndIf
   EndIf

   ERROR_SUCCESS = 0
   BUFFER_TOO_SMALL = 603
   MaxEntryName = 256
   entrylist = ''
   dllfilename = StrCat(DirWindows(1), "Rasapi32.dll")

   If WinVersion(1)>=6 ;Vista or newer
      ;~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
      ; Get RASENTRY Size
      ;~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
      lpcb = BinaryAlloc(4)
      BinaryPoke4(lpcb, 0, 0)
      lpcEntries  = BinaryAlloc(4)
      BinaryPoke4(lpcEntries, 0, 0)
      If szphonebook == "" Then ret = DllCall( dllfilename, LONG:'RasEnumEntriesA', LPNULL, LPNULL, LPNULL, LPBINARY:lpcb,LPBINARY:lpcEntries)
      Else ret = DllCall( dllfilename, LONG:'RasEnumEntriesA', LPNULL, LPSTR:szphonebook, LPNULL, LPBINARY:lpcb,LPBINARY:lpcEntries)
      If ret != BUFFER_TOO_SMALL ;Unexpected Error occured
         error = DllLastError()
         Pause('RasEnumEntriesA Failed: ':ret, error)
         BinaryFree(lpcb)
         BinaryFree(lpcEntries)
         Exit
      EndIf
      nEntries = BinaryPeek4(lpcEntries, 0 )
      nBufSize =  BinaryPeek4(lpcb, 0 )
      ;Pause( 'BufSize ':nBufSize, 'Ras Entry Count ':nEntries)
      BinaryFree(lpcb)
      BinaryFree(lpcEntries)
      If nEntries<1
         ;Pause('RasEnumEntriesA','Sorry no Ras Entries.')
         ;exit
         Return entrylist
      EndIf
   Else ;XP
      ;~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
      ; Get RASENTRY Size
      ;~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
      lprasentryname = BinaryAlloc(532)
      BinaryPoke4(lprasentryname, 0, 532)
      lpcb = BinaryAlloc(4)
      BinaryPoke4(lpcb, 0, 532)
      lpcEntries  = BinaryAlloc(4)
      BinaryPoke4(lpcEntries, 0, 0)
      If szphonebook == "" Then ret = DllCall( dllfilename, LONG:'RasEnumEntriesA', LPNULL, LPNULL, LPBINARY:lprasentryname, LPBINARY:lpcb,LPBINARY:lpcEntries)
      Else ret = DllCall( dllfilename, LONG:'RasEnumEntriesA', LPNULL, LPSTR:szphonebook, LPBINARY:lprasentryname, LPBINARY:lpcb,LPBINARY:lpcEntries)
      If ret != BUFFER_TOO_SMALL ;Unexpected Error occured
         error = DllLastError()
         Pause('RasEnumEntriesA Failed: ':ret, error)
         BinaryFree(lpcb)
         BinaryFree(lpcEntries)
         Exit
      EndIf
      nEntries = BinaryPeek4(lpcEntries, 0 )
      nBufSize =  BinaryPeek4(lpcb, 0 )
      ;Pause( 'BufSize ':nBufSize, 'Ras Entry Count ':nEntries)
      BinaryFree(lpcb)
      BinaryFree(lpcEntries)
      If nEntries<1
         ;Pause('RasEnumEntriesA','Sorry no Ras Entries.')
         ;exit
         Return entrylist
      EndIf
   EndIf
   ;~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
   ; Enumerate Ras Entries
   ;~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

   totalbuffsize = nBufSize
   lprasentryname = BinaryAlloc(nBufSize)

   BinaryEodSet(lprasentryname, 0)
   BinaryPoke4(lprasentryname, 0, nBufSize/nEntries)  ;Set DWSIZE
   lpcb = BinaryAlloc(4)
   ;BinaryPoke4(lpcb, 0, nBufSize*nEntries)
   BinaryPoke4(lpcb, 0, nBufSize)
   lpcEntries  = BinaryAlloc(4)
   BinaryPoke4(lpcEntries, 0, 0)
   If szphonebook == "" Then ret = DllCall( dllfilename, LONG:'RasEnumEntriesA', LPNULL, LPNULL, LPBINARY:lprasentryname, LPBINARY:lpcb, LPBINARY:lpcEntries)
   Else ret = DllCall( dllfilename, LONG:'RasEnumEntriesA', LPNULL, LPSTR:szphonebook, LPBINARY:lprasentryname, LPBINARY:lpcb, LPBINARY:lpcEntries)
   BinaryEodSet( lprasentryname, totalbuffsize )
   If ret != ERROR_SUCCESS ; Error occured
      error = DllLastError()
      Pause('RasEnumEntriesA Failed: ':ret, error)
      BinaryFree(lpcb)
      BinaryFree(lpcEntries)
      BinaryFree(lprasentryname)
      Exit
   EndIf

   nEntries = BinaryPeek4(lpcEntries, 0 )
   nBufSize =  BinaryPeek4(lpcb, 0 )
   offset_entryname = 4
   offset_flags = offset_entryname+MaxEntryName+4
   offset_pbk =  offset_entryname+MaxEntryName+8
   For x = 1 To nEntries
    entryname = BinaryPeekStr(lprasentryname, offset_entryname, MaxEntryName)
    flag = BinaryPeek4(lprasentryname, offset_flags)
    pbk = BinaryPeekStr(lprasentryname, offset_pbk, MaxEntryName)
    ;Pause("Results",pbk:@LF:flag:@LF:entryname)
    If entrylist == "" Then entrylist = entryname
    Else entrylist = entrylist:@TAB:entryname
    offset_entryname = offset_entryname+(nBufSize/nEntries)
    offset_flags = offset_flags+(nBufSize/nEntries)
    offset_pbk = offset_pbk+(nBufSize/nEntries)
   Next

   BinaryFree(lpcb)
   BinaryFree(lpcEntries)
   BinaryFree(lprasentryname)
   Return entrylist
#EndFunction

user = Environment('USERNAME')
;szphonebook = 'C:\Users\':user:'\AppData\Roaming\Microsoft\Network\Connections\Pbk\rasphone.pbk'
;szphonebook = 'C:\Users\All Users\Microsoft\Network\Connections\Pbk\rasphone.pbk'
;szphonebook = 'C:\Users\Standard\AppData\Roaming\Microsoft\Network\Connections\Pbk\rasphone.pbk'
szphonebook = ''

list = RasItemizeEx(szPhoneBook)
AskItemlist("List of Ras Entries",list,@TAB,@UNSORTED, @SINGLE)

Article ID:   W17599
Filename:   RasItemize Issue on Vista and Newer.txt
File Created: 2011:08:01:13:24:56
Last Updated: 2011:08:01:13:24:56