System.Management Problem

A

agarrettb

Hi all,

Willy kindly gave me this code recently but it doesn't work when I try
to use a UNC for fileObject. Has anyone ran into this issue?

string fileObject = @"c:\\temp"; // Watch the double Backslashes
using(ManagementObject lfs = new
ManagementObject(@"Win32_LogicalFileSecuritySetting.Path=" + "'" +
fileObject + "'"))

{do some stuff...}
 
C

Chris R. Timmons

(e-mail address removed) wrote in
Hi all,

Willy kindly gave me this code recently but it doesn't work when
I try to use a UNC for fileObject. Has anyone ran into this
issue?

string fileObject = @"c:\\temp"; // Watch the double Backslashes
using(ManagementObject lfs = new
ManagementObject(@"Win32_LogicalFileSecuritySetting.Path=" + "'"
+ fileObject + "'"))

{do some stuff...}

"c:\\temp" is not a valid UNC name. UNC names do not have a drive
identifier like "c:". Instead, they have a server name, like this:

\\server\folder\subfolder


See this for more info:

http://msdn.microsoft.com/library/default.asp?url=/library/en-
us/off2000/html/defUNC.asp

or

http://tinyurl.com/5pofp
 
A

agarrettb

I should have been more clear. When I do use a UNC name \\blah blah
blah the Management object can't find the directory even though I have
full permission to see it.

Thanks
 
G

Glenn Wilson

Looking at the code you have the @ in front of the text string for the drive
path... I would either take it out or remove the double back slash and try
it with one.
From my reading the @ infront of a string means to take it as written, if
you leave it off the single backslash is used as a leader for a format
character like /n for new line.
 
W

Willy Denoyette [MVP]

Unfortunatelly, Path only accepts Directory or File paths not UNC paths.
Two possible options exists to solve this:
- map the path to a local drive .
- connect to the system exporting the share, and get the security descriptor
of shared directory/file path (use Win32_LogicalShareSecuritySetting
instead of Win32_LogicalFileSecuritySetting ).

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