Hi All.
I try to browse the network enviroment using examinedirectory(). But I do not get it work.
Anyone knows how to handle this? I tried "\" and "\\" and path$ for network enviroment, but it does not work.
Any hint?
Browse network enviroment with ExamineDirectory()
-
- PureBasic Expert
- Posts: 4229
- Joined: Sat Apr 26, 2003 8:27 am
- Location: Strasbourg / France
- Contact:
It seems to work here
And you can use a mapped drive ("s:\mydir") instead of the UNC path ("\\server\shared\mydir").
Code: Select all
If ExamineDirectory(0, "\\EFSA1\EFSA\MyDir\", "*.*")
While NextDirectoryEntry(0)
If DirectoryEntryType(0) = #PB_DirectoryEntry_File
Type$ = " [File] "
Else
Type$ = " [Sub-Dir] "
EndIf
Debug DirectoryEntryName(0) + Type$ + "- Size in byte: " + Str(DirectoryEntrySize(0))
Wend
FinishDirectory(0)
EndIf
For free libraries and tools, visit my web site (also home of jaPBe V3 and PureFORM).
The Network environment is not part of the file system structure. It is part of the shell namespace.
Thats why the Explorer type gadgets cannot read it as well.
You'll have to get the namespace object for the network environment and examine its properties.
I may be able to show you some code once i get home.
Thats why the Explorer type gadgets cannot read it as well.
You'll have to get the namespace object for the network environment and examine its properties.
I may be able to show you some code once i get home.
quidquid Latine dictum sit altum videtur
Here we go. I hope the comments make it understandable.
Basically all you need is the IShellFolder Interface to walk the shell namespace.
You can have a closer look at that in the SDK for more information.
Basically all you need is the IShellFolder Interface to walk the shell namespace.
You can have a closer look at that in the SDK for more information.
Code: Select all
; Special Shell folders CLSID values:
;
; Note: those are "relative" values, so since the control panel is inside
; "My Computer", the path to it is actually this:
; "::{20d04fe0-3aea-1069-a2d8-08002b30309d}\::{21ec2020-3aea-1069-a2dd-08002b30309d}"
; Some can be used directly (like My Network Places), but most need to
; be put together with their parents CLSIDs to work.
;
; ::{d20ea4e1-3957-11d2-a40b-0c5020524153} Administrative Tools
; ::{85bbd920-42a0-1069-a2e4-08002b30309d} Briefcase
; ::{21ec2020-3aea-1069-a2dd-08002b30309d} Control Panel
; ::{d20ea4e1-3957-11d2-a40b-0c5020524152} Fonts
; ::{ff393560-c2a7-11cf-bff4-444553540000} History
; ::{00020d75-0000-0000-c000-000000000046} Inbox
; ::{00028b00-0000-0000-c000-000000000046} Microsoft Network
; ::{20d04fe0-3aea-1069-a2d8-08002b30309d} My Computer
; ::{450d8fba-ad25-11d0-98a8-0800361b1103} My Documents
; ::{208d2c60-3aea-1069-a2d7-08002b30309d} My Network Places
; ::{1f4de370-d627-11d1-ba4f-00a0c91eedba} Network Computers
; ::{7007acc7-3202-11d1-aad2-00805fc1270e} Network Connections
; ::{2227a280-3aea-1069-a2de-08002b30309d} Printers And Faxes
; ::{7be9d83c-a729-4d97-b5a7-1b7313c39e0a} Programs Folder
; ::{645ff040-5081-101b-9f08-00aa002f954e} Recycle Bin
; ::{e211b736-43fd-11d1-9efb-0000f8757fcd} Scanners And Cameras
; ::{d6277990-4c6a-11cf-8d87-00aa0060f5bf} Scheduled Tasks
; ::{48e7caab-b918-4e58-a94d-505519c795dc} Start Menu Folder
; ::{7bd29e00-76c1-11cf-9dd0-00a0c9034933} Temporary Internet Files
; ::{bdeadf00-c265-11d0-bced-00a0c90ab50f} Web Folders
; Some stuff that is needed:
;
#SHCONTF_FOLDERS = $0020; // only want folders enumerated (SFGAO_FOLDER)
#SHCONTF_NONFOLDERS = $0040; // include non folders
#SHCONTF_INCLUDEHIDDEN = $0080; // show items normally hidden
#SHCONTF_INIT_ON_FIRST_NEXT = $0100; // allow EnumObject() To Return before validating enum
#SHCONTF_NETPRINTERSRCH = $0200; // hint that client is looking For printers
#SHCONTF_SHAREABLE = $0400; // hint that client is looking sharable resources (remote shares)
#SHCONTF_STORAGE = $0800; // include all items With accessible storage And their ancestors
#_SHGDN_NORMAL = $0000; // Default (display purpose)
#_SHGDN_INFOLDER = $0001; // displayed under a folder (relative)
#_SHGDN_FOREDITING = $1000; // For in-place editing
#_SHGDN_FORADDRESSBAR = $4000; // UI friendly parsing name (remove ugly stuff)
#_SHGDN_FORPARSING = $8000; // parsing name For ParseDisplayName()
Structure STRRET
uType.l
StructureUnion
*pOleStr
uOffset.l
cStr.b[#MAX_PATH]
EndStructureUnion
EndStructure
#STRRET_WSTR = 0
#STRRET_OFFSET = $1
#STRRET_CSTR = $2
DataSection
IID_IShellFolder: ; {000214E6-0000-0000-C000-000000000046}
Data.l $000214E6
Data.w $0000, $0000
Data.b $C0, $00, $00, $00, $00, $00, $00, $46
EndDataSection
; Helper function to read the content of the filled STRRET structure
; correctly, and release any memory it allocated.
;
Procedure.s ReadSTRRET(*ret.STRRET)
If *ret\uType = #STRRET_WSTR And *ret\pOleStr
Result$ = PeekS(*ret\pOleStr, -1, #PB_Unicode)
CoTaskMemFree_(*ret\pOleStr)
*ret\pOleStr = 0
ElseIf *ret\uType = #STRRET_OFFSET
Result$ = "" ; SDK is not fully clear on how to handle this.
ElseIf *ret\uType = #STRRET_CSTR
Result$ = PeekS(@*ret\cstr[0], #MAX_PATH, #PB_Ascii)
EndIf
ProcedureReturn Result$
EndProcedure
; Function to recursively scan a Shell folder up to a maximum level
; of recursivity (so not the entire file structure is read.)
;
Procedure ScanShellFolder(Folder.IShellFolder, Sublevel, MaxSublevel)
; Try to get an enumerator object for the children of this object.
; Play around a bit with the flags to exclude certain objects from the enumeration
;
If Folder\EnumObjects(0, #SHCONTF_FOLDERS|#SHCONTF_NONFOLDERS|#SHCONTF_INCLUDEHIDDEN|#SHCONTF_SHAREABLE, @Enum.IEnumIDList) = #S_OK
; get the child *idl pointers from the enumerator object
;
While Enum\Next(1, @*idl.ITEMIDLIST, 0) = #NOERROR
; get the display name for the object
;
If Folder\GetDisplayNameOf(*idl, #_SHGDN_NORMAL, @result.STRRET) = #S_OK
Name$ = ReadSTRRET(@result)
EndIf
; get a "parsable" name for the object
; for files or normal folders, this is a path
;
If Folder\GetDisplayNameOf(*idl, #_SHGDN_FORPARSING, @result.STRRET) = #S_OK
Path$ = ReadSTRRET(@result)
EndIf
; add to tree
;
AddGadgetItem(0, -1, Name$ + " (" + Path$ + ")", 0, Sublevel)
index = CountGadgetItems(0)-1
If Sublevel <= MaxSublevel
;
; To scan the children of this item as well, we need to get a IShellFolder
; pointer from the *idl value
;
If Folder\BindToObject(*idl, 0, ?IID_IShellFolder, @NewFolder.IShellFolder) = #S_OK
; once again a scan
ScanShellFolder(NewFolder, Sublevel + 1, MaxSublevel)
NewFolder\Release()
EndIf
EndIf
SetGadgetItemState(0, index, #PB_Tree_Expanded)
; free idl memory
CoTaskMemFree_(*idl)
Wend
; free enumerator object
Enum\Release()
EndIf
EndProcedure
; Code Start
;
If OpenWindow(0, 0, 0, 400, 500, "Shell Folders", #PB_Window_SystemMenu|#PB_Window_ScreenCentered)
CreateGadgetList(WindowID(0))
TreeGadget(0, 10, 10, 380, 480)
; To get to a shell folder, we always start with the desktop object, so get it:
;
If SHGetDesktopFolder_(@Desktop.IShellFolder) = #NOERROR
; Now parse the CLSID to get to the "My Network Places".
; Try the second line to explore the content of the Control Panel
;
If Desktop\ParseDisplayName(0, 0, "::{208d2c60-3aea-1069-a2d7-08002b30309d}", 0, @*idl.ITEMIDLIST, 0) = #S_OK
;If Desktop\ParseDisplayName(0, 0, "::{20d04fe0-3aea-1069-a2d8-08002b30309d}\::{21ec2020-3aea-1069-a2dd-08002b30309d}", 0, @*idl.ITEMIDLIST, 0) = #S_OK
; What we have now is the *idl pointer. This sort of a path in the Shell
; From that we get a new IShellFolder object representing the "My Network Places"
;
If Desktop\BindToObject(*idl, 0, ?IID_IShellFolder, @Network.IShellFolder) = #S_OK
; Lets get the display name of "My Network Places"
; This is done on the parent object, with our *idl
;
If Desktop\GetDisplayNameOf(*idl, #_SHGDN_NORMAL, @result.STRRET) = #S_OK
AddGadgetItem(0, -1, ReadSTRRET(@result), 0, 0)
EndIf
; call our scan procedure for this object. max 4 levels depth
;
ScanShellFolder(Network, 1, 3)
SetGadgetItemState(0, 0, #PB_Tree_Expanded)
; Release objects
Network\Release()
EndIf
; the memory used by an IDL must be freed
CoTaskMemFree_(*idl)
EndIf
; Release desktop object
Desktop\Release()
EndIf
Repeat
Until WaitWindowEvent() = #PB_Event_CloseWindow
EndIf
End
quidquid Latine dictum sit altum videtur
Oh good, I hoped there where an more earier way of struggeling with interfaces. (I hate them )
I tried your code here at work. It only opens a blank window with an hour-clock pointer. (maybe reading the network in background for now about 5 Minutes)
Really could not believe that there is no direct API command to scan the Network for available Networks and Computers.
Maybe I only need some time to understand what is happening there.
Thanks for your support freak!
EDIT:
Okay, now I tried a litte bit and powered google to find any VB script showing how to use this interface without many success.
I'm not able to get it work to list all Available Networks and their computers. This is what I tried:
I used Desktop\ParseDisplayName with CLSID ::{208d2c60-3aea-1069-a2d7-08002b30309d} and got these results (cutted a little bit):
But this gives me no results.
I tried your code here at work. It only opens a blank window with an hour-clock pointer. (maybe reading the network in background for now about 5 Minutes)
Really could not believe that there is no direct API command to scan the Network for available Networks and Computers.
Maybe I only need some time to understand what is happening there.
Thanks for your support freak!
EDIT:
Okay, now I tried a litte bit and powered google to find any VB script showing how to use this interface without many success.
I'm not able to get it work to list all Available Networks and their computers. This is what I tried:
I used Desktop\ParseDisplayName with CLSID ::{208d2c60-3aea-1069-a2d7-08002b30309d} and got these results (cutted a little bit):
What I tried to access was the "gesamtes netzwerk" (complete network in engl.) so I added the CLSID like this:::{208D2C60-3AEA-1069-A2D7-08002B30309D}\::{D4480A50-BA28-11D1-8E75-00C04FA31A86}
D:\Dokumente und Einstellungen\MikeDelling\Netzwerkumgebung\dellingm.10$ auf Bkusva41001
\\Bkusva41001\dellingm.10$\18_06.10.06.pdf
\\Bkusva41001\dellingm.10$\ablehnung.pdf
\\Bkusva41001\dellingm.10$\Alle-Glocken1.mp3
\\Bkusva41001\dellingm.10$\Alle-Glocken2.mp3
\\Bkusva41001\dellingm.10$\bestätigung.pdf
\\Bkusva41001\dellingm.10$\bewerbung.doc
- SNIPP -
D:\Dokumente und Einstellungen\MikeDelling\Netzwerkumgebung\gruppen1015 auf Bkusva61003
D:\Dokumente und Einstellungen\MikeDelling\Netzwerkumgebung\gruppen1015 auf Bkusva61003\target.lnk
Gesamtes Netzwerk
Gesamtes Netzwerk\::{FE1290F0-CFBD-11CF-A330-00AA00C16E65}
-SNIPP-
Microsoft Windows-Netzwerk
Code: Select all
If Desktop\ParseDisplayName(0, 0, "::{208d2c60-3aea-1069-a2d7-08002b30309d}\::{FE1290F0-CFBD-11CF-A330-00AA00C16E65}", 0, @*idl.ITEMIDLIST, 0) = #S_OK
Tranquil