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:
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.
Post a Comment