Microsoft MVP성태의 닷넷 이야기
오류 유형: 60. System.Management.ManagementException - Generic failure [링크 복사], [링크+제목 복사],
조회: 20062
글쓴 사람
정성태 (techsharer at outlook.com)
홈페이지
첨부 파일
 


System.Management.ManagementException - Generic failure


문제는 간단합니다. 그동안 잘 되었던 TimeZone을 바꾸는 WMI 코드가 Vista SP1 설치 이후 "Generic failure"라는 오류를 내기 시작한 것입니다. 오류 메시지는 아래와 같이 간단합니다.

System.Management.ManagementException was caught
  Message="Generic failure "
  Source="System.Management"
  StackTrace:
       at System.Management.ManagementException.ThrowWithExtendedInfo(ManagementStatus errorCode)
       at System.Management.ManagementObject.Put(PutOptions options)
       at System.Management.ManagementObject.Put()
       at WpfApplication1.Window1.SetTimeZoneOffset(...) in D:\...\Window1.xaml.cs:line 103
       at WpfApplication1.Window1..ctor() in D:\...\Window1.xaml.cs:line 122
  InnerException: 

TimeZone을 바꾸는 WMI 소스 코드는 아래와 같습니다. (저 역시 ^^; 웹에서 떠도는 소스 코드를 사용한 것입니다.)

public static bool SetTimeZoneOffset(string machineName, string userId, string userPassword, TimeSpan utcOffset)
{
    ConnectionOptions co = new ConnectionOptions();

    if (userId != null && userId.Trim().Length != 0)
    {
        co.Username = userId;
        co.Password = userPassword;
    }

    ManagementScope ms = new ManagementScope("\\\\" + machineName + "\\root\\cimv2", co);
    ms.Connect();

    ObjectQuery query = new ObjectQuery("SELECT * FROM Win32_ComputerSystem");
    ManagementObjectSearcher searcher = new ManagementObjectSearcher(ms, query);

    using (ManagementObjectCollection resultado = searcher.Get())
    {
        foreach (ManagementObject mo in resultado)
        {
            mo.SetPropertyValue("CurrentTimeZone", utcOffset.TotalMinutes);
            mo.Put(); <======= 예외 발생
            return true;
        }
    }

    return false;
}

위의 코드가 워낙 간단해서, 별다른 정보를 찾을 수 있는 단서도 없고,,, 마냥 웹 검색을 해 봐도 별다른 해법을 찾을 수가 없었습니다. 그래도, 중요한 사실은 해당 코드가 이전에는 분명히 정상적으로 실행되었다는 사실! 아마도 그렇다면 이거저거 설정을 변경시켜 보면 되지 않을까 하는 생각에 ManagementScope에 대해 여러 가지 속성이나 메서드를 조정해 보았습니다. 결국, ^^ 알아냈지요.

다음과 같이 특권 설정을 가능하게 해줘야만 했습니다.

ManagementScope ms = new ManagementScope("\\\\" + machineName + "\\root\\cimv2");
ms.Options.EnablePrivileges = true;
ms.Connect();

잘 모르시는 분들이 많겠지만, Vista부터는 기존 Time 설정뿐만 아니라 TimeZone 관련해서도 특권(Privilege)이 별도로 추가되었습니다. 그래서 gpedit.msc를 통해서 확인해 보면, 아래와 같이 "Change the time zone" 관련해서 특권을 볼 수 있습니다.

[그림 1: Vista - Time zone 설정 특권]
change_timezone_privilege_1.png

물론, "ms.Options.EnablePrivileges = true"를 설정하는 방법 이외에, 아예 "AdjustTokenPrivileges" Win32 API를 사용해서 명시적으로 "SeTimeZonePrivilege" 특권을 지정해도 역시 시간대 설정이 정상적으로 동작합니다.

이것으로 이번에도 역시 문제 해결 끝! ^^




팁 한 가지.

이번 문제를 해결하기 위해서 웹 검색을 좀 했는데요. 간혹 WMI 관련 오류가 WMI 환경 값들이 정상적이지 않기 때문에 발생할 수 있다는데, 그런 경우 초기화를 시킬 수 있는 방법을 알게 되었습니다.

JSI Tip 5281. Windows XP reports that Windows Management Instrumentation (WMI) might be corrupted?
; http://windowsitpro.com/article/articleid/76586/jsi-tip-5281-windows-xp-reports-that-windows-management-instrumentation-wmi-might-be-corrupted.html

방법은 간단합니다. WMI 서비스를 중지시키고, "%SystemRoot%\System32\Wbem\Repository" 폴더의 파일들을 모두 지운 후 시스템을 재시작하면 된다고 하는군요. 실제로 따라서 해봤는데, 삭제되었던 Repository 폴더의 파일들이 그대로 안전하게 복원되었습니다.



[이 토픽에 대해서 여러분들과 의견을 공유하고 싶습니다. 틀리거나 미흡한 부분 또는 의문 사항이 있으시면 언제든 댓글 남겨주십시오.]







[최초 등록일: ]
[최종 수정일: 10/26/2023]

Creative Commons License
이 저작물은 크리에이티브 커먼즈 코리아 저작자표시-비영리-변경금지 2.0 대한민국 라이센스에 따라 이용하실 수 있습니다.
by SeongTae Jeong, mailto:techsharer at outlook.com

비밀번호

댓글 작성자
 



2008-10-18 11시50분
참고로, TimeZone 관련 레지스트리 : HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Time Zones
kevin25

1  2  3  4  5  [6]  7  8  9  10  11  12  13  14  15  ...
NoWriterDateCnt.TitleFile(s)
13489정성태12/19/20232178개발 환경 구성: 697. GoLand에서 ldflags 지정 방법
13488정성태12/18/20232113오류 유형: 884. HTTP 500.0 - 명령행에서 실행한 ASP.NET Core 응용 프로그램을 실행하는 방법
13487정성태12/16/20232416개발 환경 구성: 696. C# - 리눅스용 AOT 빌드를 docker에서 수행 [1]
13486정성태12/15/20232231개발 환경 구성: 695. Nuget config 파일에 값 설정/삭제 방법
13485정성태12/15/20232121오류 유형: 883. dotnet build/restore - error : Root element is missing
13484정성태12/14/20232201개발 환경 구성: 694. Windows 디렉터리 경로를 WSL의 /mnt 포맷으로 구하는 방법
13483정성태12/14/20232335닷넷: 2184. C# - 하나의 resource 파일을 여러 프로그램에서 (AOT 시에도) 사용하는 방법파일 다운로드1
13482정성태12/13/20233007닷넷: 2183. C# - eFriend Expert OCX 예제를 .NET Core/5+ Console App에서 사용하는 방법 [2]파일 다운로드1
13481정성태12/13/20232312개발 환경 구성: 693. msbuild - .NET Core/5+ 프로젝트에서 resgen을 이용한 리소스 파일 생성 방법파일 다운로드1
13480정성태12/12/20232707개발 환경 구성: 692. Windows WSL 2 + Chrome 웹 브라우저 설치
13479정성태12/11/20232374개발 환경 구성: 691. WSL 2 (Ubuntu) + nginx 환경 설정
13477정성태12/8/20232626닷넷: 2182. C# - .NET 7부터 추가된 Int128, UInt128 [1]파일 다운로드1
13476정성태12/8/20232316닷넷: 2181. C# - .NET 8 JsonStringEnumConverter의 AOT를 위한 개선파일 다운로드1
13475정성태12/7/20232413닷넷: 2180. .NET 8 - 함수 포인터에 대한 Reflection 정보 조회파일 다운로드1
13474정성태12/6/20232228개발 환경 구성: 690. 닷넷 코어/5+ 버전의 ilasm/ildasm 실행 파일 구하는 방법 - 두 번째 이야기
13473정성태12/5/20232504닷넷: 2179. C# - 값 형식(Blittable)을 메모리 복사를 이용해 바이트 배열로 직렬화/역직렬화파일 다운로드1
13472정성태12/4/20232251C/C++: 164. Visual C++ - InterlockedCompareExchange128 사용 방법
13471정성태12/4/20232356Copilot - To enable GitHub Copilot, authorize this extension using GitHub's device flow
13470정성태12/2/20232684닷넷: 2178. C# - .NET 8부터 COM Interop에 대한 자동 소스 코드 생성 도입파일 다운로드1
13469정성태12/1/20232446닷넷: 2177. C# - (Interop DLL 없이) CoClass를 이용한 COM 개체 생성 방법파일 다운로드1
13468정성태12/1/20232339닷넷: 2176. C# - .NET Core/5+부터 달라진 RCW(Runtime Callable Wrapper) 대응 방식파일 다운로드1
13467정성태11/30/20232441오류 유형: 882. C# - Unhandled exception. System.Runtime.InteropServices.COMException (0x800080A5)파일 다운로드1
13466정성태11/29/20232614닷넷: 2175. C# - DllImport 메서드의 AOT 지원을 위한 LibraryImport 옵션
13465정성태11/28/20232356개발 환경 구성: 689. MSBuild - CopyToOutputDirectory가 "dotnet publish" 시에는 적용되지 않는 문제파일 다운로드1
13464정성태11/28/20232493닷넷: 2174. C# - .NET 7부터 UnmanagedCallersOnly 함수 export 기능을 AOT 빌드에 통합파일 다운로드1
13463정성태11/27/20232402오류 유형: 881. Visual Studio - NU1605: Warning As Error: Detected package downgrade
1  2  3  4  5  [6]  7  8  9  10  11  12  13  14  15  ...