c# - Using COM component fails as admin -



c# - Using COM component fails as admin -

i have .net wrapper on native dll. seek register component current user based on : link runs fine, except if right click executable , "run admin.." tool fail cannot find class.

this code use, there missing , think might related : link

thanks!

public int register(serveraction action, string servername) { int hr = 0; string szfunction = (action == serveraction.register) ? "dllregisterserver" : "dllunregisterserver"; logger.info("filereader->try " + szfunction + " " + servername); seek { intptr hmod = loadlibrary(servername); if (hmod.toint32() != 0) { intptr registerdllserver_procaddress = getprocaddress(hmod, szfunction); dllregisterserverinvoker pfndllproc = (dllregisterserverinvoker)marshal.getdelegateforfunctionpointer(registerdllserver_procaddress, typeof(dllregisterserverinvoker)); if (pfndllproc != null) { if (isuseradminandprocesselevated()) { logger.info("user admin , process elevated!"); } else { logger.info("user not admin!"); hr = overrideclassesroot(hkey_current_user, "software\\classes"); } } hr = pfndllproc(); pfndllproc = null; freelibrary(hmod); } else { hr = this.gethresultfromwin32(); } } grab { console.writeline("filereader->" + szfunction + " " + servername + " failed!"); } string errormessage = new win32exception(hr).message; logger.fatal(errormessage); homecoming hr; } private int32 overrideclassesroot(uintptr hkeybase, string overridekey) { uintptr hkey = new uintptr(); int l = regopenkeya(hkeybase, overridekey, ref hkey); if (l == 0) { l = regoverridepredefkey(hkey_classes_root, hkey); regclosekey(hkey); } homecoming this.gethresultfromwin32(); }

still haven't figured out fixed : msdn link

c# com registry registrykey

Comments

Popular posts from this blog

Delphi change the assembly code of a running process -

json - Hibernate and Jackson (java.lang.IllegalStateException: Cannot call sendError() after the response has been committed) -

C++ 11 "class" keyword -