public void ApplyUnattendSimple()
        {
            const string unattendXml = @"<?xml version=""1.0"" encoding=""utf-8""?>
<unattend xmlns=""urn:schemas-microsoft-com:unattend"">
<settings pass=""windowsPE"">
        <component name=""Microsoft-Windows-Setup"" processorArchitecture=""x86"" publicKeyToken=""31bf3856ad364e35"" language=""neutral"" versionScope=""nonSxS"" xmlns:wcm=""http://schemas.microsoft.com/WMIConfig/2002/State"" xmlns:xsi=""http://www.w3.org/2001/XMLSchema-instance"">
            <UserData>
                <ProductKey>
                    <WillShowUI>Never</WillShowUI>
                    <Key>XXXX-XXXX-XXXX-XXXX-XXXX</Key>
                </ProductKey>
                <FullName>Full Name</FullName>
                <Organization>Organization Name</Organization>
                <AcceptEula>true</AcceptEula>
            </UserData>
        </component>
    </settings>
                     </unattend>";

            string unattendXmlFile = Path.Combine(TestDirectory, "unattend.xml");

            File.WriteAllText(unattendXmlFile, unattendXml);

            DismApi.ApplyUnattend(Session, unattendXmlFile, singleSession: true);
        }
Beispiel #2
0
        public static void ApplyUnattend(string ospath, string unattendpath)
        {
            bool ok = false;

            while (!ok)
            {
                try
                {
                    //
                    // Initialize DISM log
                    //
                    string tempLog = Path.GetTempFileName();
                    DismApi.Initialize(DismLogLevel.LogErrorsWarningsInfo, tempLog);

                    var session = DismApi.OpenOfflineSession(ospath);

                    try
                    {
                        DismApi.ApplyUnattend(session, unattendpath, true);
                    }
                    finally //(Exception ex)
                    {
                    }

                    //
                    // Clean DISM
                    //
                    DismApi.CloseSession(session);
                    DismApi.Shutdown();
                    File.Delete(tempLog);

                    ok = true;
                }
                catch (Exception ex)
                {
                    Console.WriteLine("Failed applying unattend, retrying in one second...");
                    Console.WriteLine(ex.ToString());
                    ok = false;
                    Thread.Sleep(1000);
                }
            }
        }