c# run RegSvr32 programmatically through Windows Form and get its DialogBox's message
i'm creating c# windows form application register and/or unregister dlls programmatically. that, use instance of system.diagnostic.process
class. redirect both stdoutput , stderror inside textbox
element.
using following code, when reg or unreg managed .dll file (that use regasm.exe) can obtain redirecting goal.
in case of regsvr32.exe problem occurs: regsvr32's resulting dialogbox raises (in both success or error cases)... message totally blank.
so have tried use regsvr32's /s
flag option... dialogbox not raise up, nothing becomes written inside textbox.
is there can me solve problem? i'm getting crazy! thanks!
a curious note: i'm stubborn, i've tried register unmanaged dll, using simple code (without /s
flag), implementing c# console application... regsvr32 dialog box pretty visible in both success , error cases.
so i've substituted process
block code in old code regsvr32 dialog box still not appear!!!
here windows form code:
in form1
class implemented following delegates , methods print inside form1.textbox
element stdoutput , stderror:
void appendline( string line ) { if( textbox.text.length == 0 ) textbox.text = value; else textbox.appendtext( "\r\n" + value ); } void onoutputreceivedevent( object sender, datareceivedeventargs e ) { appendlinemultithread( e.data ); } void onerrorreceivedevent( object sender, datareceivedeventargs e ) { appendlinemultithread( e.data ); } delegate void appendlinemultithreadhandler( string text ); private void appendlinemultithread( string line ) { // invokerequired required compares thread id of calling thread thread id of creating thread. if these threads different, returns true. if(invokerequired ) { appendlinemultithreadhandler d = new appendlinemultithreadhandler( appendline ); invoke( d, line ); } else { appendline( line ); // call directly } }
inside form1.run()
method (it called when user click on run
button) each item registers both events, , execute reg or unreg process:
void run() { foreach( registereritem in config.regitems ) { i.errorreceivedevent += onerrorreceivedevent; i.outputreceivedevent += onoutputreceivedevent; i.execute(); } }
and here registereritem.execute()
method:
/// <summary> /// method used register or unregister dll. /// </summary> public void execute() { string exe = "depending on hidden parameters here have 'regsvr32.exe' or 'regasm.exe'"; string args = "depending on hidden parameters here have '/codebase /s' or '/u /s'"; try { using( process reg = new process() ) { reg.startinfo.filename = exe; reg.startinfo.arguments = args; reg.startinfo.useshellexecute = false; reg.startinfo.createnowindow = true; reg.startinfo.redirectstandardoutput = true; reg.startinfo.redirectstandarderror = true; reg.errordatareceived += onerrordatareceived; reg.outputdatareceived += onoutputdatareceived; reg.enableraisingevents = true; reg.start(); reg.beginerrorreadline(); reg.beginoutputreadline(); //reg.waitforexit(); // commented 'cause @ moment don't care it } } catch( exception exc ) { throw new exception( exe + " " + args, exc ); } } public delegate void datareceivedeventhandler( object sender, datareceivedeventargs e ); public event datareceivedeventhandler errorreceivedevent; void onerrordatareceived( object sender, datareceivedeventargs e ) { if( errorreceivedevent != null ) errorreceivedevent( sender, e ); } public event datareceivedeventhandler outputreceivedevent; void onoutputdatareceived( object sender, datareceivedeventargs e ) { if( outputreceivedevent != null ) outputreceivedevent( sender, e ); }
hi,
my suggestion not call such methods.
registering dll (unamanged / com) quite easy. regsvr32 not doing special. loading library , calls dllregisterserver. instead of calling regsvr32 executable, on own, too.
you can find example code at
https://social.msdn.microsoft.com/forums/vstudio/en-us/491e8d05-4662-4e3c-87b2-764eb16aa4c1/programmatically-register-com-activex-dlls-via-managed-code?forum=clr
with kind regards,
Visual Studio Languages , .NET Framework > Visual C#
Comments
Post a Comment