用户权限和 COM 对象
我目前正在开发一个与 COM 对象交互的项目。在我的代码中,我调用以下内容:
CoInitialize(NULL); //Initialize COM system
HRESULT hr = spSSCProt.CreateInstance(("SSCProt.SSCprotector"));
这应该让我得到我需要的对象。如果失败,可能是因为 COM 服务器没有使用 regsvr32 注册 COM 对象。一切都很好,我有以下代码来处理这个问题:
/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());
如果用户不是管理员,就会出现问题。他们将无法执行注册 COM 服务器的代码部分。我的大多数用户可能不是管理员。
如果他们不是管理员,关于如何注册 com 服务器的任何想法。
谢谢
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
HRESULT 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
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
Windows 保护的全部目的就是防止您做类似的事情。 Windows 如何知道您不是试图安装某些恶意软件的病毒?
您唯一的希望是启动另一个程序,该程序通过其清单请求管理员权限。此时 Windows 将要求输入管理员密码。
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.
如果可能,进行 COM 注册的最佳位置是在安装过程中,该过程通常在管理员权限下运行。如果这不可能,还有另一种标准方法:Vista 和 Win7 上的大多数家庭用户确实拥有管理员权限 - 只是默认情况下未启用。要启用这些权限,您应该通过(臭名昭著的)UAC 请求提升。
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.