usingSystem;usingSystem.Collections.Generic;usingSystem.Linq;usingSystem.Text;usingSystem.Threading.Tasks;usingSystem.Diagnostics;usingSystem.IO;usingMicrosoft.Win32;namespacecommonutility{ Public classCMD {Private Static ReadOnlyCMD instance =NewCMD (); Public StaticCmd Instance {Get{returninstance;} } Private stringregsvr32 ="regsvr32-s {0}";//"-S" does not display a message box (unsuccessful) Public voidRegsvr32 (stringfileName) { stringStrcmd =string. Format (regsvr32, fileName); Execute (Strcmd); } /// <summary> ///executing commands with cmd/// </summary> /// <param name= "Strcmd" ></param> /// <returns></returns> Private voidExecute (stringstrcmd) { Try{ProcessStartInfo ProcessStartInfo=NewProcessStartInfo () {FileName="Cmd.exe", UseShellExecute=false, Redirectstandardoutput=false, CreateNoWindow=true, Arguments="/ C"+Strcmd}; Process myprocess=NewProcess () {startinfo=ProcessStartInfo}; Myprocess.start (); Myprocess.close (); } Catch { Throw; } } }}
C # registering COM components with code