Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9004643
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T00:56:29+00:00 2026-06-16T00:56:29+00:00

I am trying to load the Hyper-V system definition from an export on a

  • 0

I am trying to load the Hyper-V system definition from an export on a Windows 8 system using WMI. So far, I have this:

var managementScope = new ManagementScope(@"root\virtualization\v2");
var invokeMethodOptions = new InvokeMethodOptions();
invokeMethodOptions.Timeout = new TimeSpan(0, 0, 10);
using (var managementService = WmiUtilities.GetVirtualMachineManagementService(managementScope)) {
    var inParameters = managementService.GetMethodParameters(@"ImportSystemDefinition");
    inParameters["SystemDefinitionFile"] = filePath;
    inParameters["SnapshotFolder"] = snapshotPath;
    inParameters["GenerateNewSystemIdentifier"] = false;
    ManagementBaseObject outParameters = managementService.InvokeMethod(@"ImportSystemDefinition", inParameters, invokeMethodOptions);
    foreach (var value in outParameters.Properties) {
        Console.WriteLine("{0}: {1}", value.Name, value.Value);
    }
    return (ManagementBaseObject) outParameters["ImportedSystem"];
}

When I run this, the return code is 4096, indicating a job has started successfully, and I get a job value back – for example:

ImportedSystem: 
Job: \\COREI7\root\virtualization\v2:Msvm_ConcreteJob.InstanceID="B1DC90B6-14A1-42C0-924E-225660E6EC98"
ReturnValue: 4096

I have the following questions:

  1. Is it possible to execute this method synchronously? How can I tell that? The MSDN documentation at http://msdn.microsoft.com/en-us/library/hh850082(v=vs.85).aspx suggests it is possible (“If the operation completes synchronously”) but I don’t see how. My guess is this is a general WMI question about how to execute methods synchronously, which I can’t seem to find how to do.
  2. If I am force to do asynchronous, how to I watch that specific job? Everything I’m finding is on watching process events or event log events, but those both seem to be specific WQL events I’m targeting and not general job events.

I apologize if these questions are too basic – I’m just having no luck finding the answers.

Thanks!

[Edit] I’m looking into adding a ManagementOperationObserver to tell me when it’s done, although it’s not clear why I need to force it asynchronous when it seems to be doing that anyway.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-16T00:56:30+00:00Added an answer on June 16, 2026 at 12:56 am

    OK, so I worked this out, sort of.

    First, the job was completing with an error. The 4096 was telling me that it had started but hadn’t finished because it had failed. I still don’t know how to quickly get that out from that code above, but experimenting in PowerShell made it clear that’s what was happening.

    Second, I completely revamped the code. It’s possible to have Visual Studio generate strongly-typed WMI classes from Server Explorer: http://msdn.microsoft.com/en-us/library/ms257357.aspx. Doing this twice to get ROOT.virtualization.v2.Msvm_PlannedComputerSystem.cs and ROOT.virtualization.v2.Msvm_VirtualSystemManagementService.cs lets me do the following code, which is much clearer:

    var managementScope = new ManagementScope(@"root\virtualization\v2");
    using (var managementService = new VirtualSystemManagementService(WmiUtilities.GetVirtualMachineManagementService(managementScope))) {
        PlannedComputerSystem importedSystem;
        ConcreteJob job;
        var importResults = managementService.ImportSystemDefinition(
            GenerateNewSystemIdentifier: false,
            SystemDefinitionFile: filePath,
            SnapshotFolder: snapshotPath,
            ImportedSystem: out importedSystem,
            Job: out job
        );
        if (importResults != 0) {
            MessageBox.Show(String.Format("Error on import of {0}: {1}", filePath, job.ErrorDescription));
        }
    }
    

    Note that the generated code has to be changed a bit to get the nicer strongly typed objects back from the ImportSystemDefinition call:

    ImportedSystem = null;
    Job = null;
    if (outParams == null) {
        return 0;
    } else {
        if (outParams.Properties["ImportedSystem"].Value != null) {
            ImportedSystem = new PlannedComputerSystem(new ManagementObject(outParams.Properties["ImportedSystem"].Value.ToString()));
        }
        if (outParams.Properties["Job"].Value != null) {
            Job = new ConcreteJob(new ManagementObject(outParams.Properties["Job"].Value.ToString;
        }
        return Convert.ToUInt32(outParams.Properties["ReturnValue"].Value);
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Im trying to load a csv file into a datatable using oledb. This is
I am trying to load HTML via JQuery, using the .load function. This is
I am trying load content from another url using pushstate/html5... The content I am
I trying to load SFmpq.dll via this code static { Native.setProtected(true); System.setProperty(jna.library.path, new File(lib).getAbsolutePath());
Im trying to load a flash movie using swfobject which i have been successful
I'm trying to load an html page from a jsp file. like this. I
I trying to load feeds from my blog but this is resulting in the
While trying to load content from an xml file using ajax, it shows me
i m trying load UIImages from server asynchronously in UITableViewCell. My code worked fine
I have a problem with out of memory when I'm trying load a few

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.