确定,这里就是我在做蒸馏只System.Management电话:
OK, here's what I'm doing distilled to only the System.Management calls:
简单的查询和方法调用通过相同的连接工作。该查询不会。而该文件存在于远程计算机上。线索?
Simple queries and Method invokes work over the same connection. This query won't. And the file exists on the remote machine. Clues?
myQuery = "Select * from CIM_DataFile Where Drive = 'C:' AND Path = 'UserssomeguyDocuments' AND FileName = 'Default' AND Extension = 'rdp'";
options = new ConnectionOptions();
options.Username = myUsername;
options.Password = myPassword;
options.Authority = "ntlmdomain:MYDOMAIN";
scope = new ManagementScope("\REMOTEMACHINErootCIMV2", options);
scope.Connect();
searcher = new ManagementObjectSearcher(scope, new ObjectQuery(myQuery));
myResults = searcher.Get();
ManagementObjectSearcher.Get()让我一个ManagementException说:无效的查询。一个简单的查询,比如,说:SELECT * FROM Win32_NetworkAdapter这工作。
ManagementObjectSearcher.Get() gets me a ManagementException saying "Invalid query." A simpler query, like, say, "SELECT * FROM Win32_NetworkAdapter", works.
我试图减少哪来到只有一个,即SELECT * FROM CIM_DataFile凡拓='RDP'。它的工作原理,但显然没有得到我想要的。 (编辑之前,我误以为它没有工作,即使是这样,见注释)。我在这里穷途末路
I tried to reduce the WHERE's to just one, i.e. "Select * from CIM_DataFile Where Extension = 'rdp'". It works, although obviously it doesn't get me what I want. (Before the edit I mistakenly thought it didn't work even then; see comments) I'm at the end of the rope here.
推荐答案
我是个白痴。请不要打我。
I am an idiot. Please don't beat me up.
首先,查询功能仅对如果你通过文件名的所有组件在WHERE子句。
Firstly, the query only works reliably if you pass ALL components of the file name in WHERE clauses.
其次,我不得不反斜线一倍,在路径组成部分,我是做错了。我所做的:
Secondly, I had to double the backslashes in the path component, and I was doing it wrong. I did:
pathPath.Replace("", "\");
而我所要做的就是:
Whereas what I had to do was:
pathPath = pathPath.Replace("", "\");
这是正确的。我的工作是与string.replace()改变了字符串在线的假设下。坏C#新手。坏的。
That's right. I worked under the assumption that String.Replace() changed the string in-line. Bad C# newbie. Bad.
相关推荐
最新文章