Microsoft MVP성태의 닷넷 이야기
글쓴 사람
정성태 (techsharer at outlook.com)
홈페이지
첨부 파일
 

Msvm_ImageManagementService WMI 객체를 사용할 때 오류 상황 정리

VHD/VHDX 제어 관련해서 인터넷 검색을 해보면 Msvm_ImageManagementService WMI 객체를 사용하는 예제가 많이 나옵니다. 실제로 다음과 같이 코딩을 하게 되는데요.

ManagementScope scope = new ManagementScope(@"root\virtualization", null);

using (ManagementObject imageService = Utility.GetServiceObject(scope, "Msvm_ImageManagementService"))
{
    // ... VHD/VHDX 제어
}

이를 실행해 보면 환경에 따라 다음과 같은 예외가 발생할 수 있습니다.

System.Management.ManagementException: Not found
   at System.Management.ManagementException.ThrowWithExtendedInfo(ManagementStatus errorCode)
   at System.Management.ManagementObject.Initialize(Boolean getObject)
   at System.Management.ManagementBaseObject.get_ClassName()
   at System.Management.ManagementClass.GetInstances(EnumerationOptions options)
   at System.Management.ManagementClass.GetInstances()
...[생략]...

이유는 다음의 글에 나온 데로,

Error 'Get-WmiObject : Invalid class “Msvm_ImageManagementService”'
; http://stackoverflow.com/questions/19201375/error-get-wmiobject-invalid-class-msvm-imagemanagementservice

Windows 8.1부터 네임스페이스가 변경되었기 때문입니다.

The v2 WMI namespace in Hyper-V on Windows 8
; https://docs.microsoft.com/en-us/archive/blogs/virtual_pc_guy/the-v2-wmi-namespace-in-hyper-v-on-windows-8

따라서, 다음과 같이 Scope을 변경해야 합니다.

ManagementScope scope = new ManagementScope(@"root\virtualization\v2", null);

using (ManagementObject imageService = Utility.GetServiceObject(scope, "Msvm_ImageManagementService"))
{
    // ... VHD/VHDX 제어
}




그런데, 이렇게 변경했는데도 예외가 발생할 수 있습니다.

System.Management.ManagementException: This method is not implemented in any class
   at System.Management.ManagementException.ThrowWithExtendedInfo(ManagementStatus errorCode)
   at System.Management.ManagementObject.GetMethodParameters(String methodName, ManagementBaseObject& inParameters, IWbemClassObjectFreeThreaded& inParametersClass, IWbemClassObjectFreeThreaded& outParametersClass)
   at System.Management.ManagementObject.GetMethodParameters(String methodName)
...[생략]...

이유는, v2로 네임스페이스만 변경된 것 뿐만 아니라 메서드의 구현까지 모두 변경되었기 때문입니다. 따라서, v2에 대한 문서를 보고 구현을 해야 합니다.

Msvm_ImageManagementService class
; https://docs.microsoft.com/en-us/windows/win32/hyperv_v2/msvm-imagemanagementservice

CreateVirtualHardDisk method of the Msvm_ImageManagementService class
; https://docs.microsoft.com/en-us/windows/win32/hyperv_v2/createvirtualharddisk-msvm-imagemanagementservice

이제부터 잘 동작할 것입니다. ^^




그런데, 몇몇 컴퓨터에서 그래도 다음과 같은 예외가 발생할 수 있습니다.

System.Management.ManagementException: Invalid namespace
   at System.Management.ManagementException.ThrowWithExtendedInfo(ManagementStatus errorCode)
   at System.Management.ManagementScope.InitializeGuts(Object o)
   at System.Management.ManagementScope.Initialize()
   at System.Management.ManagementScope.Connect()
...[생략]...

환경은 Hyper-V가 설치되지 않은 Windows 10이었기 때문입니다. "root\virtualization\v2" 계열의 WMI 객체들에 대한 MSDN 문서를 보면 "Minimum supported client"로 "Windows?8 [desktop apps only]"라고만 되어 있지만 기본적으로 Hyper-V가 설치되어 있어야만 하는 것입니다.




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







[최초 등록일: ]
[최종 수정일: 7/13/2021]

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

비밀번호

댓글 작성자
 



2017-05-04 01시29분
Windows-classic-samples / Samples / Hyper-V / Storage / cs
; https://github.com/Microsoft/Windows-classic-samples/tree/master/Samples/Hyper-V/Storage/cs
정성태

... 61  62  63  64  65  [66]  67  68  69  70  71  72  73  74  75  ...
NoWriterDateCnt.TitleFile(s)
11977정성태7/6/201914700오류 유형: 554. git push - error: RPC failed; HTTP 413 curl 22 The requested URL returned error: 413 Request Entity Too Large
11976정성태7/4/20199067오류 유형: 553. (잘못 인증 한 후) 원격 git repo 재인증 시 "remote: HTTP Basic: Access denied" 오류 발생
11975정성태7/4/201917486개발 환경 구성: 448. Visual Studio Code에서 콘솔 응용 프로그램 개발 시 "입력"받는 방법
11974정성태7/4/201912865Linux: 22. "Visual Studio Code + Remote Development"로 윈도우 환경에서 리눅스(CentOS 7) C/C++ 개발
11973정성태7/4/201912147Linux: 21. 리눅스에서 공유 라이브러리가 로드되지 않는다면?
11972정성태7/3/201914891.NET Framework: 847. JAVA와 .NET 간의 AES 암호화 연동 [1]파일 다운로드1
11971정성태7/3/201912063개발 환경 구성: 447. Visual Studio Code에서 OpenCvSharp 개발 환경 구성
11970정성태7/2/201910457오류 유형: 552. 웹 브라우저에서 파일 다운로드 후 "Running security scan"이 끝나지 않는 문제
11969정성태7/2/201910839Math: 63. C# - 3층 구조의 신경망파일 다운로드1
11968정성태7/1/201917151오류 유형: 551. Visual Studio Code에서 Remote-SSH 연결 시 "Opening Remote..." 단계에서 진행되지 않는 문제 [1]
11967정성태7/1/201911420개발 환경 구성: 446. Synology NAS를 Windows 10에서 iSCSI로 연결하는 방법
11966정성태6/30/201910825Math: 62. 활성화 함수에 따른 뉴런의 출력을 그리드 맵으로 시각화파일 다운로드1
11965정성태6/30/201911592.NET Framework: 846. C# - 2차원 배열을 1차원 배열로 나열하는 확장 메서드파일 다운로드1
11964정성태6/30/201913089Linux: 20. C# - Linux에서의 Named Pipe를 이용한 통신
11963정성태6/29/201912808Linux: 19. C# - .NET Core Unix Domain Socket 사용 예제
11962정성태6/27/201910526Math: 61. C# - 로지스틱 회귀를 이용한 선형분리 불가능 문제의 분류파일 다운로드1
11961정성태6/27/201910067Graphics: 37. C# - PLplot - 출력 모음(Family File Output)
11960정성태6/27/201910855Graphics: 36. C# - PLplot의 16색 이상을 표현하는 방법과 subpage를 이용한 그리드 맵 표현
11959정성태6/27/201912056Graphics: 35. matplotlib와 PLplot의 한글 처리
11958정성태6/25/201916380Linux: 18. C# - .NET Core Console로 리눅스 daemon 프로그램 만드는 방법 [6]
11957정성태6/24/201915408Windows: 160. WMI 쿼리를 명령행에서 간단하게 수행하는 wmic.exe [2]
11956정성태6/24/201913387Linux: 17. CentOS 7에서 .NET Core Web App 실행 환경 구성 [1]
11955정성태6/20/201911663Math: 60. C# - 로지스틱 회귀를 이용한 분류파일 다운로드1
11954정성태6/20/201911162오류 유형: 550. scp - sudo: no tty present and no askpass program specified
11953정성태6/20/201910022오류 유형: 549. The library 'libhostpolicy.so' required to execute the application was not found in '...'
11952정성태6/20/201910802Linux: 16. 우분투, Centos의 Netbios 호스트 이름 풀이 방법
... 61  62  63  64  65  [66]  67  68  69  70  71  72  73  74  75  ...