开发者

User Permissions and COM Objects

开发者 https://www.devze.com 2023-02-24 11:04 出处:网络
I am currently working on a project that interacts with a COM object. In my code I call the following:

I am currently working on a project that interacts with a COM object. In my code I call the following:


CoInitialize(NULL);  //Initialize COM system 
HRESUL开发者_运维技巧T hr = spSSCProt.CreateInstance(("SSCProt.SSCprotector"));

This should get me the object I need. If this fails, it is presumably because the COM Server does not have the COM object registered using regsvr32. All is fine and well, I have the following code to handle that:


/if its not, lets try to register it ourselves...create the command
CHAR cmdBuf[BUFSIZE];
GetCurrentDirectory(BUFSIZE,cmdBuf);
string cmd("regsvr32 -s \"");
cmd += cmdBuf;
cmd += "\\stixDlls\\SSCProt.dll\"";

//attempt to register it
system(cmd.c_str());

The problem arises if the user is not an admin. They wont be able to execute the section of code the registers the COM server. Most of my users will probably not be admins.

Any ideas on how I can register the com server if they are not an admin.

Thanks


The whole point of Windows protection is to prevent you from doing things like that. How is Windows supposed to know you're not a virus trying to install some malware?

Your only hope is to start up another program which requests administrator privileges via its manifest. At that point Windows will ask for the administrator password.


If possible, the best place to do COM registration is during the installation process, which is usually being run under admin privileges. If that's not possible, there's another standard way: most home users on Vista and Win7 do have admin privileges - it's just not enabled by default. To enable those privileges you should request elevation through the (in)famous UAC.

0

精彩评论

暂无评论...
验证码 换一张
取 消