强制重新加载 Windows 视频驱动程序。有可能吗?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/2500411/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Force windows video driver reload. Is it possible at all?
提问by somemorebytes
Some drivers use parameters written in the registry to configure themselves when they get loaded at boot time. I can modify those values and then reboot, but I would like to know if it is possible to force the driver reload, making the changes effective without rebooting.
某些驱动程序在启动时加载时使用写入注册表的参数来配置自己。我可以修改这些值然后重新启动,但我想知道是否可以强制重新加载驱动程序,使更改生效而无需重新启动。
Specifically, I am talking about the video driver (nvidia).
具体来说,我说的是视频驱动程序(nvidia)。
I read somewhere, that calling through pINvoke() [User32.ll]::ChangeDisplaySettings() with a 640x480x8bits resolution,(which is so low that it should not be supported by a modern driver) will force windows to load the "Standard VGA driver", and making another call with the current resolution will load the nvidia driver again.
我在某处读到,通过 pINvoke() [User32.ll]::ChangeDisplaySettings() 以 640x480x8bits 分辨率调用(它太低以至于现代驱动程序不支持)将强制 Windows 加载“标准 VGA驱动程序”,并以当前分辨率再次调用将再次加载 nvidia 驱动程序。
This does not work though. At least in Windows 7, even if the low res is not displayed as "supported" the system reduces the screen to a little square in the center of the screen, showing the low res wihtout unloading the nvidia driver.
但这不起作用。至少在 Windows 7 中,即使低分辨率未显示为“支持”,系统也会将屏幕缩小到屏幕中央的一个小方块,显示低分辨率而无需卸载 nvidia 驱动程序。
So, is there any .NET/Win32 API, service to restart, or any way at all to force a video driver reload?
那么,是否有任何 .NET/Win32 API、要重新启动的服务或任何强制重新加载视频驱动程序的方法?
Perhaps programatically disabling the device (as you could do from the Device Manager) and reenabling it again?
也许以编程方式禁用设备(就像您可以从设备管理器中执行的那样)并再次重新启用它?
Any idea?
任何的想法?
Thanks a lot.
非常感谢。
回答by somemorebytes
I finally did it. Following the idea of disabling/reenabling the device actually worked.
我终于做到了。遵循禁用/重新启用设备的想法实际上有效。
Of course the problem is that disabling your video card device from the Device Manager could not be a great idea, as maybe you are not able to reenable it again.
当然,问题是从设备管理器禁用您的视频卡设备不是一个好主意,因为您可能无法再次重新启用它。
Doing it programatically, does not appear so unsafe though. In theory, asuming that the app has successfully disabled the device, reenabling it should not pose a problem.
以编程方式进行,虽然看起来并不那么不安全。理论上,假设应用程序已成功禁用设备,重新启用它应该不会造成问题。
I found here, in stackoverflow a fantasticclass to accomplish this, thanks to Justin Grant.
感谢 Justin Grant,我在 stackoverflow 中找到了一个很棒的类来完成此任务。
The video driver reloads itself as the video device is reenabled.
当重新启用视频设备时,视频驱动程序会重新加载自身。
Hope it helps someone.
希望它可以帮助某人。
回答by Luke
It depends on the driver. If it was written to support stopping and restarting then it is possible; otherwise, you're out of luck. If you find the name of the service you can do "sc stop [name]" followed by "sc start [name]". Win32 equivalent is OpenService/ControlService.
这取决于司机。如果它是为了支持停止和重新启动而编写的,那么它是可能的;否则,你就不走运了。如果您找到服务的名称,您可以执行“sc stop [name]”后跟“sc start [name]”。Win32 等效项是 OpenService/ControlService。