5 분마다 레지스트리를 업데이트해야하는 서비스가 있습니다 (gpo에 대응). 코드는 일반 응용 프로그램에서 제대로 실행되지만 Windows 서비스에 넣을 때 변경되지 않습니다. 나는 서비스를 로컬 시스템 계정을 사용하고 있으며 예외C# Windows 서비스에서 레지스트리를 변경해야합니다.
아래의 코드는 일반 콘솔 응용 프로그램에서 작동하지만 서비스에 던지는되지 않습니다
RegistryKey key = Registry.CurrentUser.OpenSubKey("Control Panel\\Desktop", true);
if (key != null)
{
key.SetValue("ScreenSaverIsSecure", "0", RegistryValueKind.String);
key.SetValue("ScreenSaveActive", "0", RegistryValueKind.String);
key.SetValue("ScreenSaveTimeOut", "0", RegistryValueKind.String);
key.SetValue("SCRNSAVE.EXE", "", RegistryValueKind.String);
}
key = Registry.CurrentUser.OpenSubKey(@"Software\Policies\Microsoft\Windows\Control Panel\Desktop", true);
if (key != null)
{
key.SetValue("ScreenSaverIsSecure", "0", RegistryValueKind.String);
key.SetValue("ScreenSaveActive", "0", RegistryValueKind.String);
key.SetValue("ScreenSaveTimeOut", "0", RegistryValueKind.String);
key.SetValue("SCRNSAVE.EXE", "", RegistryValueKind.String);
}
System.Diagnostics.Process.Start(@"c:\windows\System32\RUNDLL32.EXE", "user32.dll, UpdatePerUserSystemParameters");
어떤 아이디어를?
편집 : 답변에 대한
감사합니다. 나는 왜 "CurrentUser"가 나의 관심을 도망 갔는지 모르겠다. 그 점을 지적 해 주셔서 감사합니다.
여전히 현재 사용자에 대해 그룹 정책이 적용되고 있다는 문제가 있습니다. 지금은 시작시로드되고 활성 상태로 유지되는 앱을 만드는 것을 고려 중입니다. 다른 제안 사항도 환영합니다.
편집 : 윌의 의견에 관해서는
, 내가는 Win32 API의 UpdatePerUserSystemParameters 함수 서명을 찾을 수 없습니다입니다. 그것은 매개 변수없이 호출 될 수 있음을 의미합니까?
[System.Runtime.InteropServices.DllImport("user32.dll")]
private static extern bool UpdatePerUserSystemParameters();
실제로 로컬 시스템/로컬 서비스/네트워크 서비스 계정에 HKCU 항목이 있습니다. HK_USERS를 확인하십시오. –