Example #1
0
//----------------------------------------------------------------------------
//                                                             DoSelectFolders
//----------------------------------------------------------------------------
        private void DoSelectFolders()
        {
            string strAppend;

// Set up form
            btnInstall.Enabled = true;
// Load deployment configuration
            moDeployIni = new CLibIniFile(mstrWorking, "Deployment.ini");
            mstrManufac = moDeployIni.GetString(EnumSections.Target, EnumKeys.Manufacturer);
            mstrProduct = moDeployIni.GetString(EnumSections.Target, EnumKeys.Product);
            mstrVersion = moDeployIni.GetString(EnumSections.Target, EnumKeys.Version);
            mstrIni     = moDeployIni.GetString(EnumSections.Target, EnumKeys.Ini);
            mstrDeploy  = moDeployIni.GetString(EnumSections.Target, EnumKeys.DeployUsing);
// Append manufacturer and product
            strAppend     = $"\\{mstrManufac}\\{mstrProduct}";
            mstrCommon   += strAppend;
            mstrPrivate  += strAppend;
            mstrSoftware += strAppend;
// Assign software product details to visible controls
            tbTitle.Text   = "Install " + moDeployIni.GetString(EnumSections.Target, EnumKeys.Title);
            tbVersion.Text = "Version " + mstrVersion;
// Display OS environment
            DisplayFolders();
        }
Example #2
0
//----------------------------------------------------------------------------
//                                                              InstallDrivers
//----------------------------------------------------------------------------
        private Boolean InstallDrivers()
        {
            Boolean bfProcInfo;
            Boolean bfRedirect;
            Boolean bfSuccess;
            Boolean bfWow64;
            string  strArgs;
            string  strPnPUtil;
            string  strDriverPath;
            string  strFilename;
            WORD    wDriverNum;

            IntPtr hProcess;
            IntPtr hRestore;

            Process          process;
            ProcessStartInfo startinfo;

// Init
            bfSuccess  = false;
            wDriverNum = 0;
            meErrCause = Series.Cause.None;
// Get a handle to this current process
            hProcess = Process.GetCurrentProcess().Handle;
            hRestore = IntPtr.Zero;
// Check if it is running on a 64-bit processor
            bfProcInfo = NativeMethods.IsWow64Process(hProcess, out bfWow64);
            if (!bfProcInfo)
            {
                meErrCause = Series.Cause.IsWow64Process;
                goto exit_method;
            }
// Disable file system redirection for this thread
            if (bfWow64)
            {
                bfRedirect = NativeMethods.Wow64DisableWow64FsRedirection(out hRestore);
                if (!bfRedirect)
                {
                    meErrCause = Series.Cause.Wow64Disable;
                    goto exit_method;
                }
            }
// Enumerate all file names in the specified section of the Deployment.ini
            while (true)
            {
                // Fetch next file listed in specified section
                wDriverNum++;
                // Get driver's INF file name from deployment.ini [DeviceDrivers] 1='' (Can be more than one in the future)
                strFilename = moDeployIni.GetString(EnumSections.DeviceDrivers, wDriverNum.ToString(CProgram.CultureInfo));
                // Stop if next filename was not found
                if (string.IsNullOrEmpty(strFilename))
                {
                    break;
                }
                // Construct fully pathed INF file spec
                strDriverPath = $"{mstrWorking}\\{strFilename}";
                // Get location of "Windows\\System32\\InfDefaultInstall.exe"
                strPnPUtil = $"{mstrSystem}\\pnputil.exe";
                // Construct parameters for driver installer
                strArgs = $"/add-driver {strDriverPath}";
                // Invoke device driver installation
                process   = new Process();
                startinfo = new ProcessStartInfo();
                startinfo.UseShellExecute = false;
                startinfo.CreateNoWindow  = true;
                startinfo.FileName        = strPnPUtil;
                startinfo.Arguments       = strArgs;

                process.StartInfo = startinfo;

                try
                {
                    process.Start();
                }
                catch (InvalidOperationException)      { meErrException = Series.Exception.InvalidOp; }
                catch (Win32Exception)                 { meErrException = Series.Exception.Win32; }    // System.ComponentModel
                catch (PlatformNotSupportedException)  { meErrException = Series.Exception.NotSupported; }
                // Intercept caught exceptions
                if (meErrException == Series.Exception.None)
                {
                    process.WaitForExit();
                }

                process.Dispose();

                // Stop without success
                if (meErrCause != Series.Cause.None)
                {
                    meErrCause |= Series.Cause.PnPUtil;
                    goto exit_method;
                }
            }
// Success
            bfSuccess = true;

exit_method:

// Restore file system redirection for this thread
            if (bfWow64)
            {
                NativeMethods.Wow64RevertWow64FsRedirection(hRestore);
            }

            return(bfSuccess);
        }