Last active
April 4, 2022 13:44
-
-
Save 0xbadjuju/550fb602a8b7aa610436d533c94a1885 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using System.Collections; | |
using System.Management; | |
using System.Management.Instrumentation; | |
using System.Runtime.InteropServices; | |
using System.Configuration.Install; | |
/* | |
* Added references: | |
* system.configuration.install | |
* system.enterpriseservices | |
* system.management | |
* system.management.instrumentation | |
* | |
* "C:\Windows\Microsoft.NET\Framework\v4.0.30319\csc.exe" /target:library /R:system.configuration.install.dll /R:system.enterpriseservices.dll /R:system.management.dll /R:system.management.instrumentation.dll wmitest.cs | |
* | |
* Install: | |
* InstallUtil.exe WMITest.dll | |
* C:\Windows\Microsoft.NET\Framework64\v4.0.30319\InstallUtil.exe wmitest.dll | |
* [System.Configuration.Install.ManagedInstallerClass]::InstallHelper(@( ".\WMITest.dll")) | |
* | |
* Need to copy file to gac or wbem folder | |
* copy wmitest.dll c:\windows\system32\wbem\ | |
* | |
* Run command | |
* Invoke-WmiMethod -Class Win32_Template -Name RunSomething | |
*/ | |
[assembly: WmiConfiguration(@"root\cimv2", HostingModel = ManagementHostingModel.LocalSystem)] | |
namespace WMITest | |
{ | |
[System.ComponentModel.RunInstaller(true)] | |
public class MyInstall : DefaultManagementInstaller | |
{ | |
//private static string fileName = System.Diagnostics.Process.GetCurrentProcess().MainModule.FileName; | |
public override void Install(IDictionary stateSaver) | |
{ | |
try | |
{ | |
base.Install(stateSaver); | |
RegistrationServices registrationServices = new RegistrationServices(); | |
} | |
catch { } | |
} | |
public override void Uninstall(IDictionary savedState) | |
{ | |
try | |
{ | |
ManagementClass managementClass = new ManagementClass(@"root\cimv2:Win32_Template"); | |
managementClass.Delete(); | |
} | |
catch { } | |
try | |
{ | |
base.Uninstall(savedState); | |
} | |
catch { } | |
} | |
} | |
[ManagementEntity(Name = "Win32_Template")] | |
public class Class1 | |
{ | |
[ManagementTask] | |
public static string RunSomething(string command, string parameters) | |
{ | |
return "test"; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment