.net - How to get the path of an antivirus installed in my system from my C# program? -
my c# program needs open antivirus installed in machine.
as of have hardcoded path follows:
system.diagnostics.process.start("c:/program files (x86)/myantivirus/myantivirus.exe");
however path varies 32 , 64 bit machine. cannot run same code on 64 bit windows 8.1 machine.
is there way path of antivirus installed in machine program machine independent?
instead of hardcoding path antivirus, can ask windows path is. antivirus programs report windows. windows wont report users no antivirus installed.
using wmi can query windows path.
var searcherprevista = new managementobjectsearcher(string.format(@"\\{0}\root\securitycenter", environment.machinename), "select * antivirusproduct"); var searcherpostvista = new managementobjectsearcher(string.format(@"\\{0}\root\securitycenter2", environment.machinename), "select * antivirusproduct"); var previstaresult = searcherprevista.get().oftype<managementobject>(); var postvistaresult = searcherpostvista.get().oftype<managementobject>(); var instances = previstaresult.concat(postvistaresult); var installedantivirusses = instances .select(i => i.properties.oftype<propertydata>()) .where(pd => pd.any(p => p.name == "displayname") && pd.any(p => p.name == "pathtosignedproductexe")) .select(pd => new { name = pd.single(p => p.name == "displayname").value, path = pd.single(p => p.name == "pathtosignedproductexe").value }) .toarray(); foreach (var antivirus in installedantivirusses) { console.writeline("{0}: {1}", antivirus.name, antivirus.path); }
to use code, need add following using statements:
using system; using system.linq; using system.management;
further more. add reference system.management
.
this code generate list of antivirusses installed. objects in list have name , path. if run code shows following:
microsoft security essentials: c:\program files\microsoft security client\msseces.exe
Comments
Post a Comment