var info = new ProcessStartInfo(@"C:\Windows\System32\cmd.exe") {
UseShellExecute = true, // 必須為 true 才能使用 Verb
Verb = "runas", // 請求 UAC 提權
Arguments = "/c attrib -s \"C:\\path\\to\\file\"", // /c 執行命令後退出
WindowStyle = ProcessWindowStyle.Hidden // 可選:隱藏窗口
};
Process.Start(info);
UseShellExecute = true 是使用 Verb 的前提(默認 false 時需重定向流,無法提權)。Verb = "runas" 觸發 UAC 彈窗(或自動提權若策略允許)。/c 執行完畢退出,/k 保留窗口調試。Arguments = $"/c attrib -s \"{path}\""; // 字符串插值,注意轉義
若需無感提權(無 UAC 彈窗),需將程序清單設置 requireAdministrator 或編寫 Windows 服務。