ManagementObject的问题.. [英] Problem with ManagementObject..

查看:47
本文介绍了ManagementObject的问题..的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



我正在尝试使用代码。


string fileObject = @" C:\Documents and Settings \ myfolder \ Temp .txt" ;;

ManagementBaseObject ret = null;

ManagementPath path = new ManagementPath();

path.Server = @" ServerName" ; //假设服务器名称是服务器我是

尝试连接


path.NamespacePath = @" root\cimv2" ;;

path.RelativePath = @" Win32_LogicalFileSecuritySetting.Path =" +"''" +

fileObject +"''" ;;

ManagementObject lfs = new ManagementObject(path);


//获取此对象的安全描述符

bool EnablePrivileges = lfs.Scope.Options.EnablePrivileges;

lfs.Scope.Options.EnablePrivileges = true;

//转储所有受托者(包括所有者)

string accountName,SID;

foreach(ManagementBaseObject b in lfs.GetRelated())

{

accountName =(string)b [" AccountName"]; - 我收到错误

这一行

SID =(字符串)b [" SID"];

Console.WriteLine( 受托人{0}是{1},b [" AccountName"],

b [" SID"]);

}


我在代码上面的标记( - 我在这一行上收到错误)的行上收到错误。

当我尝试上面的本地机器代码时,一切正常工作

罚款。

提前感谢您的帮助。


-

谢谢

SCS


I am trying following code.

string fileObject = @"C:\Documents and Settings\myfolder\Temp.txt";
ManagementBaseObject ret = null;
ManagementPath path = new ManagementPath( );
path.Server = @"ServerName"; // Assuming that server name is server i am
trying to connect to

path.NamespacePath = @"root\cimv2";
path.RelativePath = @"Win32_LogicalFileSecuritySetting.Path=" + "''" +
fileObject + "''";
ManagementObject lfs = new ManagementObject(path);

// Get the security descriptor for this object
bool EnablePrivileges = lfs.Scope.Options.EnablePrivileges;
lfs.Scope.Options.EnablePrivileges = true;
// Dump all trustees (this includes owner)
string accountName, SID;
foreach (ManagementBaseObject b in lfs.GetRelated())
{
accountName= (string)b["AccountName"]; --I am getting error on
this line
SID = (string)b["SID"];
Console.WriteLine("Trustees {0} is {1}", b["AccountName"],
b["SID"]);
}

I am getting error on the line marked(--I am getting error on this line) in
above code. When i tried above code for local machine everything is working
fine.
Thanks in advance for help.

--
Thanks
SCS

推荐答案

应该工作。

请发布错误消息或调用堆栈...


Willy。


" scsharma" < SH ****** @ noemail.nospam>在消息中写道

新闻:4B ********************************** @ microsof t.com ...
Should work.
Please post the error message or call stack...

Willy.

"scsharma" <sh******@noemail.nospam> wrote in message
news:4B**********************************@microsof t.com...

我正在尝试下面的代码。

string fileObject = @" C:\Documents and Settings \ myfolder \Temp.txt" ;;
ManagementBaseObject ret = null;
ManagementPath path = new ManagementPath();
path.Server = @" ServerName" ;; //假设服务器名称是服务器我试图连接到

path.NamespacePath = @" root\cimv2" ;;
path.RelativePath = @" Win32_LogicalFileSecuritySetting.Path = QUOT; +"''" +
fileObject +"''" ;;
ManagementObject lfs = new ManagementObject(path);

//获取此对象的安全描述符
bool EnablePrivileges = lfs.Scope.Options.EnablePrivileges;
lfs.Scope.Options.EnablePrivileges = true;
//转储所有受托人(包括所有者)
字符串accountName,SID;
foreach(ManagementBaseObject b in lfs.GetRelated())
{
accountName =(string)b [" AccountName"]; - 我收到错误
此行
SID =(字符串)b [" SID"];
Console.WriteLine(" Trustees {0}是{1}" ,b [" AccountName"],
b [" SID"]);
}

我在标记的行上收到错误( - 我收到错误在这条线上)
上面的代码。当我尝试上面的本地机器代码时,一切都工作
很好。
在此先感谢您的帮助。

-
谢谢
SCS

I am trying following code.

string fileObject = @"C:\Documents and Settings\myfolder\Temp.txt";
ManagementBaseObject ret = null;
ManagementPath path = new ManagementPath( );
path.Server = @"ServerName"; // Assuming that server name is server i am
trying to connect to

path.NamespacePath = @"root\cimv2";
path.RelativePath = @"Win32_LogicalFileSecuritySetting.Path=" + "''" +
fileObject + "''";
ManagementObject lfs = new ManagementObject(path);

// Get the security descriptor for this object
bool EnablePrivileges = lfs.Scope.Options.EnablePrivileges;
lfs.Scope.Options.EnablePrivileges = true;
// Dump all trustees (this includes owner)
string accountName, SID;
foreach (ManagementBaseObject b in lfs.GetRelated())
{
accountName= (string)b["AccountName"]; --I am getting error on
this line
SID = (string)b["SID"];
Console.WriteLine("Trustees {0} is {1}", b["AccountName"],
b["SID"]);
}

I am getting error on the line marked(--I am getting error on this line)
in
above code. When i tried above code for local machine everything is
working
fine.
Thanks in advance for help.

--
Thanks
SCS



对不起,我没有发布错误信息。

错误信息只是说找不到

和堆栈跟踪是




System.Management.ManagementException.ThrowWithExt endsInfo(ManagementStatus

errorCode)\\ \\\\ at System.Management.PropertyData.RefreshPropertyInfo()\\\\ n

在System.Management.PropertyData..ctor(ManagementBas eObject parent,String

$ B $ System $Management.ManagementBaseObject,System.Management.PropertyDataCollection.get_Item(String

propertyName)\\\\ n at
$ b propName)\\\ .GetProperty Value(String

propertyName)\\\ System.Management.ManagementBaseObject.get_Item(St ring

propertyName)\\\\ n at Tester.testWMI()in

c:\\ temp \\ eccconsole \\ batatchconsoleapp \\wmicodesampl e.cs:line 40" string


-

谢谢

SCS

" Willy Denoyette [MVP]"写道:
Sorry, I didnot post the error message.
Error message simply says "Not Found"
and stack trace is

at
System.Management.ManagementException.ThrowWithExt endedInfo(ManagementStatus
errorCode)\r\n at System.Management.PropertyData.RefreshPropertyInfo ()\r\n
at System.Management.PropertyData..ctor(ManagementBas eObject parent, String
propName)\r\n at System.Management.PropertyDataCollection.get_Item( String
propertyName)\r\n at
System.Management.ManagementBaseObject.GetProperty Value(String
propertyName)\r\n at System.Management.ManagementBaseObject.get_Item(St ring
propertyName)\r\n at Tester.testWMI() in
c:\\temp\\ecconsole\\batchconsoleapp\\wmicodesampl e.cs:line 40" string

--
Thanks
SCS
"Willy Denoyette [MVP]" wrote:
应该工作。
请发布错误信息或致电堆栈......

威利。

" scsharma" < SH ****** @ noemail.nospam>在消息中写道
新闻:4B ********************************** @ microsof t.com。 ..
Should work.
Please post the error message or call stack...

Willy.

"scsharma" <sh******@noemail.nospam> wrote in message
news:4B**********************************@microsof t.com...

我正在尝试下面的代码。

string fileObject = @" C:\Documents and Settings \ myfolder\Temp。 txt" ;;
ManagementBaseObject ret = null;
ManagementPath path = new ManagementPath();
path.Server = @" ServerName" ;; //假设服务器名称是服务器我试图连接到

path.NamespacePath = @" root\cimv2" ;;
path.RelativePath = @" Win32_LogicalFileSecuritySetting.Path = QUOT; +"''" +
fileObject +"''" ;;
ManagementObject lfs = new ManagementObject(path);

//获取此对象的安全描述符
bool EnablePrivileges = lfs.Scope.Options.EnablePrivileges;
lfs.Scope.Options.EnablePrivileges = true;
//转储所有受托人(包括所有者)
字符串accountName,SID;
foreach(ManagementBaseObject b in lfs.GetRelated())
{
accountName =(string)b [" AccountName"]; - 我收到错误
此行
SID =(字符串)b [" SID"];
Console.WriteLine(" Trustees {0}是{1}" ,b [" AccountName"],
b [" SID"]);
}

我在标记的行上收到错误( - 我收到错误在这条线上)
上面的代码。当我尝试上面的本地机器代码时,一切都工作
很好。
在此先感谢您的帮助。

-
谢谢
SCS

I am trying following code.

string fileObject = @"C:\Documents and Settings\myfolder\Temp.txt";
ManagementBaseObject ret = null;
ManagementPath path = new ManagementPath( );
path.Server = @"ServerName"; // Assuming that server name is server i am
trying to connect to

path.NamespacePath = @"root\cimv2";
path.RelativePath = @"Win32_LogicalFileSecuritySetting.Path=" + "''" +
fileObject + "''";
ManagementObject lfs = new ManagementObject(path);

// Get the security descriptor for this object
bool EnablePrivileges = lfs.Scope.Options.EnablePrivileges;
lfs.Scope.Options.EnablePrivileges = true;
// Dump all trustees (this includes owner)
string accountName, SID;
foreach (ManagementBaseObject b in lfs.GetRelated())
{
accountName= (string)b["AccountName"]; --I am getting error on
this line
SID = (string)b["SID"];
Console.WriteLine("Trustees {0} is {1}", b["AccountName"],
b["SID"]);
}

I am getting error on the line marked(--I am getting error on this line)
in
above code. When i tried above code for local machine everything is
working
fine.
Thanks in advance for help.

--
Thanks
SCS






" scsharma" < SH ****** @ noemail.nospam>在留言中写道

news:98 ********************************** @ microsof t.com ...

"scsharma" <sh******@noemail.nospam> wrote in message
news:98**********************************@microsof t.com...
抱歉,我没有发布错误信息。
错误信息只是说找不到
并且堆栈跟踪是

在System.Management.PropertyData.RefreshPropertyInfo()\\\\ n System.Management.PropertyDataCollection.get_Item(String String
propName)\\\\ n
System.Management.ManagementBaseObject.GetProperty Value(String
propertyName)\\\\ n
System.Management.ManagementBaseObject.get_Item(/> propertyName)\\\\ n St环
propertyName)\\\ at Tester.testWMI()in
c:\\ temp \\ eccconsole \\batchconsoleapp\\wmi codesampl e.cs:第40行字符串

-
谢谢
SCS
Sorry, I didnot post the error message.
Error message simply says "Not Found"
and stack trace is

at
System.Management.ManagementException.ThrowWithExt endedInfo(ManagementStatus
errorCode)\r\n at
System.Management.PropertyData.RefreshPropertyInfo ()\r\n
at System.Management.PropertyData..ctor(ManagementBas eObject parent,
String
propName)\r\n at
System.Management.PropertyDataCollection.get_Item( String
propertyName)\r\n at
System.Management.ManagementBaseObject.GetProperty Value(String
propertyName)\r\n at
System.Management.ManagementBaseObject.get_Item(St ring
propertyName)\r\n at Tester.testWMI() in
c:\\temp\\ecconsole\\batchconsoleapp\\wmicodesampl e.cs:line 40" string

--
Thanks
SCS




这对我有用(在XP及更高版本上),


使用System;

使用System.Management;

使用System.Collections;


class Tester {

public static void Main()

{

//创建将文件对象(文件路径)传递给
ctor。

//观察双反斜杠!!!!

string FileSystemObject = @" c:\\\\sfeed.xml" ;


ManagementPath path = new ManagementPath();

path.RelativePath = @" Win32_LogicalFileSecuritySetting.Path =" +"''" +

FileSystemObject +"''" ;;

ManagementObject lfs = new ManagementObject(path);

foreach(lfs中的ManagementBaseObject b)。 GetRelated())

{

string domainName = b [" ReferencedDomainName"]。ToString();

string accountName = b [" ; AccountName"]。ToString();

string SID = b [" SID"]。ToString();

Console.WriteLine(" Trustees {0} \\ {1}是{2}",

b [" ReferencedDomainName"],b [" AccountName"],b [" SID"]);

}

}

}


如果它不适合你,我建议你试试wbemtest.exe并发出

相同的查询并检查Win32_LogicalFileSecuritySetting对象

关联器以查看返回的内容。


Willy。




This works for me (on XP and higher),

using System;
using System.Management;
using System.Collections;

class Tester {
public static void Main()
{
// Create FileObjectSecurity passing the file object (filepath) to the
ctor.
// Watch the double backslashes !!!!
string FileSystemObject = @"c:\\rssfeed.xml";

ManagementPath path = new ManagementPath( );

path.RelativePath = @"Win32_LogicalFileSecuritySetting.Path=" + "''" +
FileSystemObject + "''";
ManagementObject lfs = new ManagementObject(path);
foreach (ManagementBaseObject b in lfs.GetRelated())
{
string domainName= b["ReferencedDomainName"].ToString();
string accountName= b["AccountName"].ToString();
string SID = b["SID"].ToString();
Console.WriteLine("Trustees {0}\\{1} is {2}",
b["ReferencedDomainName"], b["AccountName"], b["SID"]);
}
}
}

if it doesn''t work for you, I would suggest you try wbemtest.exe and issue
the same query and check the Win32_LogicalFileSecuritySetting object
associators to see what is returned.

Willy.



这篇关于ManagementObject的问题..的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆