Home  |  Index  |  Dotnet4all Snippets  |  Submit resources
About  |  Mail us  
Dotnet4all Logo

  How to set file persmissions with WMI using a UNC path (Thursday, January 27, 2005)




Found the following interesting discussion in the Newsgroups:

Setting file persmissions with WMI using a UNC path
by:c_johan_asplund@hotmail.com (Johan)

Hi all

I'm trying to set the permissions of a file using WMI, and since i'm
writing a windows service i want to use UNC paths doing this because
the destination might not be a mapped path. I'we been looking around
here at google and gotten the impression that it is not possible to
use UNC paths when working with WMI, is that really so? Or does anyone
know how how to set file permissions using a UNC path? I'we gotten to
work ok with a mapped path to a file on another computer, but if I
feed the same code with a UNC path instead i get a error back saying
"Not Found". Here is the code that works with a mapped path.
Note that this i VB.NET and only a part of the code.

The reason for using WMI instead of ADSI is that I want this to work
in a Novell enviorment as well, and I imagine that WMI can manage
that.

Dim FolderPath as string = Any mapped path
Dim objFile As New ManagementObject(New
ManagementPath("Win32_LogicalfileSecuritySetting='" + _
FolderPath.Replace("\", "\\") + "'"))
Dim options As New InvokeMethodOptions(Nothing, New TimeSpan(0, 0, 0,
5))
Dim outparams As ManagementBaseObject =
objFile.InvokeMethod("GetSecurityDescriptor", Nothing, options)

Console.Write(objFile.GetText(TextFormat.Mof))
Another solution to my problem would be to do a temporary mapping the
the UNC path from withing my service. But if I do that it seams that
WMI does not get my temporary mapping. Can I make WMI to somehow
"reinit" itself so it gets the mapping i've made from the code.

Thanks
Johan


 Reply:
by:Gerry Hickman

 Hi,

As far as I know, WMI can only work with "local" files, however "local"
can mean on a different box because you can connect to WMI on a
different box.

It's a pain if you want to create a process whos image (exe file)
resides on a different computer. Some 3rd party vendors take the
approach of copying the whole file to every remote computer.
--
Gerry Hickman (London UK)








1 Comments:

Anonymous Anonymous said...

1. Check this link for logging in remotely:
http://www.microsoft.com/technet/scriptcenter/scripts/templates/wmi/connect/tmwcvb33.mspx

2: Combine this with a script to set file permissions.

1:12 AM  

Post a Comment

 
Previous Posts
    - Week date
    - How to set a dataset date value to null
    - If only MSDN examples would actually work!
    - How to use managed code in Office 2003
    - Click Event not fired
    - How to read a particular setting from a file
    - Distinct groupid
    - How to pass Control Parameters between Forms
    - How to fill multi dimensional array
    - Array of Properties ??? Please Help

Archives
    - 10/03/2004 - 10/10/2004
    - 10/10/2004 - 10/17/2004
    - 10/17/2004 - 10/24/2004
    - 10/24/2004 - 10/31/2004
    - 10/31/2004 - 11/07/2004
    - 11/21/2004 - 11/28/2004
    - 11/28/2004 - 12/05/2004
    - 12/05/2004 - 12/12/2004
    - 12/12/2004 - 12/19/2004
    - 12/19/2004 - 12/26/2004
    - 12/26/2004 - 01/02/2005
    - 01/23/2005 - 01/30/2005
    - 01/01/2006 - 01/08/2006
    - 09/24/2006 - 10/01/2006

Disclaimer & Terms of Use  | DotNet4All.Com concept & © 2004 - 2007 by  Zelders²  - Holland