C#与SCCM连接并查询并在文本框中显示结果 [英] C# with SCCM connecting and Query and show results on the textbox
问题描述
我想连接到sccm并从计算机查询sccm。这是我的代码
I would like to connect to sccm and query sccm from a computer. Here is my code
SmsNamedValuesDictionary namedValues =
跨度>
<跨度风格=" 颜色:蓝;字型家族:索拉;字体 - 大小:10pt">新 SmsNamedValuesDictionary();
WqlConnectionManager连接=
new <跨度风格= "字体家庭:索拉;字体大小:10PT"> WqlConnectionManager(namedValues); 跨度>
<跨度风格="字体家庭:索拉;字体 - 大小:10PT">&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP; connection.Connect(" ServerName" );
connection.Connect("ServerName");
string query =
" select SMS_R_System.MACAddresses,SMS_R_System.IPAddresses,SMS_R_System.IPSubnets,SMS_R_System.LastLogonUserName from  ; SMS_R_SYSTEM其中SMS_R_System.Name = QUOT; 跨度> + txtName.Text +
的"'" 跨度> 跨度>
string query = "select SMS_R_System.MACAddresses, SMS_R_System.IPAddresses,SMS_R_System.IPSubnets, SMS_R_System.LastLogonUserName from SMS_R_System where SMS_R_System.Name =" + txtName.Text + "'";
试用
{
&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP; IResultObject queryResults = connection.QueryProcessor.ExecuteQuery(query);
foreach (WqlResultObject obj
in queryResults)
foreach (WqlResultObject obj in queryResults)
<跨度风格= "字体家庭:索拉;字体大小:10PT">&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP ; {&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;
var macaddress = obj.GetSingleItem(" SMS_R_System.MACAddresses" )。PropertyList [" MACAddress" ];
var macaddress = obj.GetSingleItem("SMS_R_System.MACAddresses").PropertyList["MACAddress"];
if (macaddress!=
null )
if (macaddress != null)
&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP; {
&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP; Console.WriteLine(MACADDRESS); 跨度>
<跨度风格= "字体家庭:索拉;字体大小:10PT">&NBSP;&NBSP;&NBSP;&NBSP;&NBSP; &NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP; }
&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP; }
&NBSP;&NBSP;&NBSP; }
catch (SmsException ex)
&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP; {
&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP; Console.WriteLine(
"无法执行查询:' " + query +
"':" 跨度> + ex.Message +的
" \\\
Inner异常:" 跨度> + ex.InnerException.Message); 跨度>
"Failed to execute query: '" + query + "': " + ex.Message + "\nInner Exception:" + ex.InnerException.Message);
throw ex
&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP; }
}
这是我得到的错误:
Microsoft.ConfigurationManagement.ManagementProvider.WqlQueryEngine.WqlQueryException: 'SMS提供商
报告错误。'
Freddy91761_1
Freddy91761_1
推荐答案
如果这是你的代码:
If this is literally your code:
string query
= "从SMS_R_System选择SMS_R_System.MACAddresses,SMS_R_System.IPAddresses,SMS_R_System.IPSubnets,SMS_R_System.LastLogonUserName
,其中SMS_R_System.Name =" + txtName.Text +  ; "'" ;
string query = "select SMS_R_System.MACAddresses, SMS_R_System.IPAddresses,SMS_R_System.IPSubnets, SMS_R_System.LastLogonUserName from SMS_R_System where SMS_R_System.Name =" + txtName.Text + "'";
然后问题是您在等号后面缺少单引号。
Then the problem is that you are missing a single quote mark just after the equal sign.
这篇关于C#与SCCM连接并查询并在文本框中显示结果的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!