private void Form1_Load(object sender, EventArgs e)
        {
#if !DISABLE_ADMIN_RIGHTS
            if (!OsProxy.CurrentUserIsAdministrator())
            {
                MessageBox.Show("To continue installing, please run this program as Administrator",
                                "Installation failed..", MessageBoxButtons.OK, MessageBoxIcon.Error);
                Close();

                return;
            }
#endif
            FormStatus status = (DriverInstaller.Installed()) ?
                                FormStatus.Uninstall : FormStatus.Install;

            UpdateForm(status);
        }
Beispiel #2
0
        private void Form1_Load(object sender, EventArgs e)
        {
            if (!OsProxy.CurrentUserIsAdministrator())
            {
                MessageBox.Show("To continue installing, please run this program as Administrator",
                                "Installation failed..", MessageBoxButtons.OK, MessageBoxIcon.Error);
                Close();
            }

            string errMsg = string.Empty;

            if (DriverInstaller.DriverAlreadyExits(ref errMsg))
            {
                UpdateForm(FormStatus.Uninstall);
            }

            if (errMsg != string.Empty)
            {
                MessageBox.Show(errMsg,
                                "Installation failed..", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
Beispiel #3
0
        static public bool InstallDriver(ref string errorMsg, DriverType driverType)
        {
            Dictionary <string, string> srcDriverPathDict = new Dictionary <string, string>();

            string dstDriverPath = Environment.ExpandEnvironmentVariables("%windir%\\system32\\drivers");

            srcDriverPathDict.Add("driverDir", Path.Combine(
                                      Path.GetDirectoryName(Process.GetCurrentProcess().MainModule.FileName), "drivers"));

            string srcDriverPath = string.Empty;

            if (driverType == DriverType.WFP)
            {
                srcDriverPathDict.Add("driverVersion", "wfp");
                string osVersion = OsProxy.GetOsVersion();
                if (osVersion == string.Empty)
                {
                    errorMsg = "Couldn't get OS version";
                    return(false);
                }

                srcDriverPathDict.Add("osVersion", osVersion);
            }
            else
            {
                srcDriverPathDict.Add("driverVersion", "tdi");
            }

            srcDriverPathDict.Add("bitCapasity", (!Environment.Is64BitOperatingSystem) ? "i386" : "amd64");
            srcDriverPathDict.Add("driverName", driverName);

            string[] srcDriverPathArr = new string[srcDriverPathDict.Count];
            srcDriverPathDict.Values.CopyTo(srcDriverPathArr, 0);

            srcDriverPath = Path.Combine(srcDriverPathArr);
            dstDriverPath = Path.Combine(dstDriverPath, srcDriverPathDict["driverName"]);

            try
            {
                IntPtr oldValue = IntPtr.Zero;
                if (Wow64DisableWow64FsRedirection(ref oldValue))
                {
                    File.Copy(srcDriverPath, dstDriverPath, true);
                    if (Wow64RevertWow64FsRedirection(oldValue) == false)
                    {
                        errorMsg = "Couldn't revert Wow64 redirection";
                        return(false);
                    }
                }
                else
                {
                    errorMsg = "Couldn't disable Wow64 redirection";
                    return(false);
                }
            }
            catch (FileNotFoundException)
            {
                errorMsg = "driver not found";
                return(false);
            }
            catch (IOException)
            {
                errorMsg = "driver already exists";
                return(false);
            }
            catch (Exception e)
            {
                errorMsg = string.Format("exception {0} {1}", e.GetType(), e.Message);
                return(false);
            }

            //Register driver here..
            RunRegUtil(RegAction.Register);
            SetInstalledKey();

            return(true);
        }