如何在Windows 7上致电Win32 API具有高架特权[英] How to call a Win32 API with elevated priviledges on Windows 7

本文是小编为大家收集整理的关于如何在Windows 7上致电Win32 API具有高架特权的处理方法,想解了如何在Windows 7上致电Win32 API具有高架特权的问题怎么解决?如何在Windows 7上致电Win32 API具有高架特权问题的解决办法?如何在Windows 7上致电Win32 API具有高架特权问题的解决方案?那么可以参考本文帮助大家快速定位并解决问题,译文如有不准确的地方,大家可以切到English参考源文内容。

问题描述

我们刚刚发现,调用win32 SetDateTime函数的代码需要在Windows 7中以高架模式运行,即即使以管理员的身份登录,仍然必须选择运行设置的日期代码作为管理员更改日期的电话.

我可以在代码中执行任何操作,可以始终在高架特权下调用此功能?

推荐答案

这不是安全性工作的方式.更改时钟是A 非常侵入性操作,它具有大量的副作用. Windows或任何其他操作系统都没有机制,您可以在其中启动有限特权的过程,然后任意绕过这些限制并突然获得管理员权利.如果可能的话,运行有限特权的程序将没有任何意义.

如果您想做这样的事情,那么您必须以提高权利运行程序.在Vista和Win7上,需要您作为服务或计划的任务运行.要求管理员安装. UAC为常规程序提供了一种获得管理权的方式,您必须在程序中包括一份清单,以便将用户通知您的特权高程. Google"需求administrator",首次命中.

其他推荐答案

您可以使用Shellexecute API调用来启动具有高架特权的可执行文件.

但是,如果在计算机上启用了UAC(用户访问控制),则用户仍将获取UAC提示,要求使用权限运行.

因此,我认为您无法避免提示高程许可,但是至少您的用户不必手动以管理员的身份运行该程序.

请告诉我,如果您需要帮助如何启动管理员的帮助.

其他推荐答案

就像其他人所说的那样,您需要产生一个新的流程以获得提升的权限,这将导致UAC对话框.

如果这是您需要无人值守的东西,则可以尝试作为服务运行.那将为您提供所需的高架上下文.

本文地址:https://www.itbaoku.cn/post/2254118.html

问题描述

We have just discovered that code that calls the Win32 SetDateTime function needs to run in elevated mode in Windows 7, i.e. even when logged in as an administrator, one still has to choose to run the Set Date code as Administrator for the call to change the date.

Is there anything I can do in code to always call this function under elevated privileges?

推荐答案

This is just not how security works. Changing the clock is a very intrusive operation, it has a very large number of side effects. There is no mechanism in Windows, or any other operating system for that matter, where you could start a process with limited privileges and then just arbitrarily bypass these limitations and suddenly gain administrator rights. There wouldn't be any point whatsoever to running programs with limited privileges if that was possible.

If you want to do something like this then you'll have to run your program with elevated rights. On Vista and Win7 that requires you to run as a service or a scheduled task. Which require an administrator to get installed. UAC provides a way gain admin rights for regular programs, you have to include a manifest in your program so the user is notified about your privilege elevation. Google 'requireadministrator', take the first hit.

其他推荐答案

You can use the ShellExecute API call to launch an executable with elevated privileges.

However, if UAC (user access control) is enabled on the machine, the user will still get the UAC prompt asking for permissions to run elevated.

So I don't think you can avoid the prompt for elevation permission, but at least your user doesn't have to manually run the program as an admin.

Please let me know if you need help in how to launch an executable as an admin.

其他推荐答案

Like others have said, you need to spawn a new process to get elevated permissions, which will result in a UAC dialog.

If this is something you need to run unattended you could try running as a service. That would give you the elevated context you need.

查看更多