Get Windows service dependencies using C# -
i can use powershell easily, looking c# way this. ps, can use get-service iterate on collection , check collections in there called dependentservices , requiredservices list of dependent , required services given service.
i've looked wmi model using query "select * win32_service", returns collection of win32_service objects not seem have collections interested in. feel missing here. have looked around , tried various searches, i've not turned c#-centric way of doing this.
i want query given service , collections mentioned above (dependentservices , requiredservices). sorry if missed obvious, have not been able find relevant topics.
you can use servicecontroller class:
stringbuilder sb = new system.text.stringbuilder(); foreach (var svc in system.serviceprocess.servicecontroller.getservices()) { sb.appendline("============================"); sb.appendline(svc.displayname); foreach (var dep in svc.dependentservices) { sb.appendformat("\t{0}", dep.displayname); sb.appendline(); } } messagebox.show(sb.tostring());
Comments
Post a Comment