减慢 Windows 进程的速度?
如何减慢 Windows 进程的速度?
我知道我需要挂钩 QueryPerformanceCounter
但接下来我需要做什么?
需要 Delphi 或 C++ 的帮助
How can I slow down a Windows Process?
I understand that I need to hook QueryPerformanceCounter
but what do I need to do next?
Need help for Delphi or C++
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
我不确定我是否理解挂钩 QueryPerformanceCounter 与减慢您所描述的进程之间的关系。也许如果您详细说明原来的问题或评论,我可以进一步帮助您。
要回答您的问题,您可以使用 Windows 2000 资源工具包中的 cpustres.exe 给系统施加负载,从而导致上下文切换。如果您放置足够的负载并超额订阅所有可用的 CPU,您的进程将会减慢。根据您使用 cpustres 设置选择的负载级别,您可以或多或少地减慢进程速度。
如果您想以更受控的方式以编程方式减慢进程而不使其崩溃(如果是游戏),您可以使用卡萨布兰卡的答案,但将 Sleep(10) 替换为:
I am not sure I understand the relationship of hooking QueryPerformanceCounter to slowing down a process that you described. Perhaps if you elaborate in the original question or a comment, I can help you further.
To answer your question, you can use cpustres.exe from the Windows 2000 resource kit to put a load on your system, causing context switching. If you put enough of a load and oversubscribe all available CPUs, you will slow down your process. Depending on the load level you select with the cpustres settings, you can slow your process down a lot or a little.
If you want to slow down the process programmatically in a more controlled way without crashing it if it is a game, you can use casablanca's answer, but replace Sleep(10) with:
我能想到的一种方法是使用专用线程
SuspendThread
在您想要减慢速度的线程上,等待一会儿,然后恢复线程:One way I can think of is to have a dedicated thread use
SuspendThread
on the thread that you want to slow down, wait for a little while and then resume the thread:我不明白你的问题的动机/背景是什么,因为你没有解释清楚。但是,使用
SetPriorityClass()
,可以将指定进程的优先级设置为BELOW_NORMAL_PRIORITY_CLASS
,甚至设置为IDLE_PRIORITY_CLASS
,使进程运行速度变慢;您还可以将指定进程的优先级设置为ABOVE_NORMAL_PRIORITY_CLASS
,甚至设置为HIGH_PRIORITY_CLASS
,以便进程运行得更快。在此之前,您需要通过 PID 获取目标进程的句柄,请查看此处。I don't understand what is the motive/background of your question since you didn't explain it clearly. However, using
SetPriorityClass()
, you can sets the priority class for the specified process toBELOW_NORMAL_PRIORITY_CLASS
or even toIDLE_PRIORITY_CLASS
so that the process running slower; and you can also sets the priority class for the specified process toABOVE_NORMAL_PRIORITY_CLASS
or even toHIGH_PRIORITY_CLASS
so that the process running faster. Before doing that, you'll need to get handle of target process by its PID, look here.Windows 2000 在内部进程管理上引入了一个新层,允许对一个或多个进程设置额外的限制:作业。我不确定它是否允许设置所用处理器时间的限制,但如果应用程序尚未使用该方法,您可能只能调用 AssignProcessToJobObject 和 SetInformationJobObject 施加额外的限制。
Windows 2000 introduced a new layer over internal process management that allows to set extra limits on one or more processes: Jobs. I'm not sure if it allows to set a limit on processor time used, but if the application isn't using the method already, you might just be able to call AssignProcessToJobObject and SetInformationJobObject to impose extra limitations.