Win32: API calls to list available network shares on a server?

一世执手 提交于 2019-12-10 10:38:59

问题


Assume I have access to a SMB server at IP 1.2.3.4, how can I determine the list of available shares?

Windows Explorer can do it when I enter a UNC path \\1.2.3.4\ - but command prompt "dir \\1.2.3.4\" fails!

I've tried the usual FindFirstFile/FindNext calls - which I use successfully to read the files and directories on each share, but they don't work directly on the server root.

Ideally, I need something that works for XP onwards.

Edit: I want to do this programatically, rather than from command line. Redirecting and parsing the output from 'net view 1.2.3.4' would work, but I'm ideally looking for an API for this job.


回答1:


According to the docs there's a NetShareEnum and a WNetEnumResource function.




回答2:


net view \\1.2.3.4

Check out http://www.ss64.com/nt/net_share.html

Edit: If you want to do this programmatically, it looks like NetShareEnum would work.




回答3:


It appears you can use WMI to get this information. Check this post for some neat PowerShell tutorials that show now to use the Win32_Share WMI object.




回答4:


Never use WMI (not installed natively)
Use Win32 api to enumerate shares, posted millions of times on google groups( win32)



来源:https://stackoverflow.com/questions/899995/win32-api-calls-to-list-available-network-shares-on-a-server

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!