[python-win32] Getting Remote Share User Group Names and Permissions
Rod Person
rodperson at rodperson.com
Mon Feb 20 13:11:57 CET 2012
On Mon, 20 Feb 2012 11:53:46 +0000
Tim Golden <mail at timgolden.me.uk> wrote:
>
> Let's see. I think where we're at is this: you have a number of shares
> on server1 (sharea, shareb) which you wish to set up on server2 so
> that, in effect, the same users can access them in the same way. (And,
> if you DNS-rename the servers around each other, without realising
> that anything's changed).
>
> Although WMI can help you in doing this, it's a bit of a clumsy tool
> unless you have no other way of getting there. In particular, if
> you're in an AD setup (or in an NT domain) and have suitably
> administrative privs, you should be able to use either AD or the
> Win32 API NetShare* functions (which are exposed via the win32net
> module in pywin32).
>
> I'm not sure if you can simply disregard the share permissions --
> which would certainly be the most common approach -- or whether you
> want them, but are happy for them to match the NTFS permissions for
> the underlying path. The former is certainly easier; the latter is
> certainly possible.
>
> Ok; let's keep things simple. Assuming suitable admin privs across
> all relevant machines, this code will read the shares from one
> machine and recreate them on another assuming that the corresponding
> paths are already in place:
>
> <code>
> import win32net
>
> def shares (system):
> share_infos, total, hResume = win32net.NetShareEnum (system, 2, 0)
> for share_info in share_infos:
> if share_info['type'] == 0:
> yield share_info
> while hResume > 0:
> share_infos, total, hResume = win32net.NetShareEnum (
> system, 2, hResume
> )
> for share_info in share_infos:
> if share_info['type'] == 0:
> yield share_info
>
> def create_share (system, share_info):
> win32net.NetShareAdd (system, 2, share_info)
>
> for share_info in shares ("server1"):
> create_share ("server2", share_info)
>
> </code>
>
>
> Could you see how far that takes you towards your goal? I'm
> not clear whether you need help specifying the perms on
> the underlying paths, since that would normally be done by
> some kind of backup-restore toolset. But if you need something
> I can certainly advise.
>
> TJG
Thanks you again, Tim.
I will look at this later today or tomorrow. Permission in my case
aren't any problems I have domain administration rights, but that is a
relic of when our IT department was 3 people.
But yes, the basic goal here is to duplicate a servers shares, the
server in question has 150 or so shares and the person in charge wants
to do all that by hand...which is seems ridiculous to, especially since
he is a programmer...anyway in this situation the two servers will be
on the network and the new server will eventually renamed to what the
old server name is.
--
Rod Person http://www.rodperson.com rodperson at rodperson.com
'Silence is a fence around wisdom'
More information about the python-win32
mailing list