WMI connection error C# -
using system; using system.management; public class class1 { public static void main() { string strcomputer = string.format(@"machinename.domainname\root\cimv2"); connectionoptions options = new connectionoptions(); options.enableprivileges = true; options.impersonation = impersonationlevel.impersonate; options.authentication = authenticationlevel.packet; options.authority = "ntlmdomain:instil.com:instil.com"; options.username = "usr"; options.password = "pwd"; managementscope oms = new managementscope(strcomputer, options); selectquery query =new selectquery("select * win32_directory name ='"+string.format(@"c:\scripts")+"'"); managementobjectsearcher osearcher = new managementobjectsearcher(oms,query); managementobjectcollection oreturncollection = osearcher.get(); if (oreturncollection.count < 1) { console.writeline("folder not exist"); } else { console.writeline("folder exist"); } } }
i'm trying connect remote machine , checking existence of folder.but i'm getting below mentioned error.
i tried , incorporated changes discussed in remote wmi connection c# - invalid parameter error
program abruptly stops working , throws below error:
unhandled exception: system.management.managementexception: invalid parameter @ system.management.managementexception.throwwithextendedinfo(managementstat errorcode) @ system.management.managementpath.createwbempath(string path) @ system.management.managementpath..ctor(string path) @ class1.main()
you need backslashes before machine name. change this:
string strcomputer = string.format(@"machinename.domainname\root\cimv2");
to this:
string strcomputer = string.format(@"\\machinename.domainname\root\cimv2");
Comments
Post a Comment