ConnectionOptions oConn = new ConnectionOptions()
ManagementScope scope = new ManagementScope("\\\\server\\root\\cimv2", oConn)
sb.Append("SELECT * FROM CIM_Datafile WHERE Extension = 'config' AND FileName = 'machine'行凳")// AND path LIKE '%\\win2000\\microsoft.net\\framework%'")
ObjectQuery oQuery = new ObjectQuery(sb.ToString())
ManagementObjectSearcher oSearcher = new ManagementObjectSearcher(scope, oQuery)
ManagementObjectCollection oReturnCollection = oSearcher.Get()
foreach (ManagementObject oReturn in oReturnCollection)
{
//MessageBox.Show(oReturn["Name"].ToString())
oReturn.InvokeMethod("Copy"贺扒, new object[] { oReturn["Name"], "\\yourServer\\禅带昌path\\filename.ext" })
试一下这个?
如果你不介意用第三方工具的话,那么介绍你一个微软合作伙伴赛门铁克出品的鼎鼎有名的psexec。该工具可以简单的远程执行肆咐命令/程序。裂丛纯比方说你想远程 *** 作192.168.0.102上面D盘根目录下的名叫abc.cmd的郑塌批处理文件,并且得到输出结果,你可以这样写代码。
Process myProcess = new Process()
myProcess.StartInfo.UseShellExecute = false
myProcess.StartInfo.RedirectStandardOutput = true
myProcess.StartInfo.FileName = "psexec"
myProcess.StartInfo.Arguments = @"\\192.168.0.102 -u Administrator -p 123456 cmd /c d:\abc.cmd"
myProcess.Start()
myProcess.WaitForExit()
string strRst = myProcess.StandardOutput.ReadToEnd()
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)