Force windows video driver reload. Is it possible at all?
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).
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.
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.
So, is there any .NET/Win32 API, service to restart, or any way at 开发者_JAVA技巧all to force a video driver reload?
Perhaps programatically disabling the device (as you could do from the Device Manager) and reenabling it again?
Any idea?
Thanks a lot.
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 fantastic class to accomplish this, thanks to Justin Grant.
The video driver reloads itself as the video device is reenabled.
Hope it helps someone.
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.
精彩评论