我需要在用戶不應具有管理員權限的計算機上自動重新啟動圖形驅動程序。我的歸檔選項是使用 powershell 或從 powershell 調用的 C# 代碼。這個問題中提到了重新啟動圖形驅動程序的最簡單方法: PowerShell禁用和啟用驅動程序 $d = Get-PnpDevice| where {$_.class -like "Display*"}
$d | Disable-PnpDevice -Confirm:$false
$d | Enable-PnpDevice -Confirm:$false但我無法使用它,因為它需要管理員權限才能執行。第二種也是更好的方法是使用 win + ctrl + shift + b 熱鍵,它不需要管理員權限。我在這個網站上找到了一個如何組合按下 win 鍵的好例子:https://github.com/stefanstranger/PowerShell/blob/master/WinKeys.ps1并根據我的需要構建它。我的實際代碼是這樣的: $source = @" using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Runtime.InteropServices; using System.Windows.Forms; namespace KeyboardSend { public class KeyboardSend { [DllImport("user32.dll")] public static extern void keybd_event(byte bVk, byte bScan, int dwFlags, int dwExtraInfo); private const int KEYEVENTF_EXTENDEDKEY = 1; private const int KEYEVENTF_KEYUP = 2; public static void KeyDown(Keys vKey) { keybd_event((byte)vKey, 0, KEYEVENTF_EXTENDEDKEY, 0); } public static void KeyUp(Keys vKey) { keybd_event((byte)vKey, 0, KEYEVENTF_EXTENDEDKEY | KEYEVENTF_KEYUP, 0); } } }# 163 = ctrl key# 161 = shift key# 66 = b key如果我嘗試除了 win + e 之外的其他組合來打開資源管理器,它就可以正常工作。但是,如果我想輸入 win + ctrl + shift + b ,它什么也不做,并且會自行關閉,并且不會顯示錯誤消息。我錯過了什么嗎?
- 1 回答
- 0 關注
- 164 瀏覽
添加回答
舉報
0/150
提交
取消