WMI and permissions on a shared directory


J

Jerome

Hi everybody,

I need to remove access to a shared directory before to execute a
process on the directory.
And put back the access on it after the execution.

So I wanted to set the permission of the Everyone user to Deny, execute
my process, and restore the permission to Allow.

There is the NET SHARE command, but it's to create or delete a share.
We don't have the RMTSHARE.exe tool and we cannot install another tool.

I readed some things about WMI and csharp but I never see an exemple
with the permisson on a share.
There are a lot of things about the permission about the folder, but I
want just the share.

So, I wanted to use WMI. I saw exemple to create a new permission or
delete one, but I cannot read the permission on the share.

Maybe somebody has some exemple to help me.

I use Visual Studio 2005 (and the framework 2.0). And the share is on a
win 2003 server.

Thanks in advance
Jerome
 
Ad

Advertisements

W

Willy Denoyette [MVP]

Jerome said:
Hi everybody,

I need to remove access to a shared directory before to execute a
process on the directory.
And put back the access on it after the execution.

So I wanted to set the permission of the Everyone user to Deny, execute
my process, and restore the permission to Allow.

There is the NET SHARE command, but it's to create or delete a share.
We don't have the RMTSHARE.exe tool and we cannot install another tool.

I readed some things about WMI and csharp but I never see an exemple
with the permisson on a share.
There are a lot of things about the permission about the folder, but I
want just the share.

So, I wanted to use WMI. I saw exemple to create a new permission or
delete one, but I cannot read the permission on the share.

Maybe somebody has some exemple to help me.

I use Visual Studio 2005 (and the framework 2.0). And the share is on a
win 2003 server.

Thanks in advance
Jerome

You can't modify the sharing permissions on an existing share, you can only "set" the
permissions when you create the share. So, basically what you should do is delete the share
and re-create it with the wanted permissions.

net share <sharename> /delete
net share <sharename>=c:\somepath /user:blush:nlyme,full
....run your application...
net share <sharename> /delete
net share <sharename>=c:\somepath /everyone,full

Note that you need to make sure there are no existing sessions with the share before you
delete the share and you'll need administrative privileges to do so.

Willy.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top