示例#1
0
        public static bool CreatePortPair(string portNameA, int timeout)
        {
            if (UacHelper.IsUacEnabled)
            {
                if (!UacHelper.IsProcessElevated)
                {
                    return(false);
                }
            }
            if (!UacHelper.IsAdministrator())
            {
                return(false);
            }

            var proc = new Process
            {
                StartInfo = new ProcessStartInfo
                {
                    WorkingDirectory = Path.GetDirectoryName(_com0comSetupc),
                    FileName         = _com0comSetupc,
                    Arguments        = portNameA == "-" ? "install - -" : "install PortName=" + portNameA + " -",
                    UseShellExecute  = true,
                    CreateNoWindow   = false,
                    Verb             = "runas"
                }
            };

            proc.Start();
            if (!proc.WaitForExit(timeout))
            {
                proc.Kill();
            }
            return(proc.ExitCode == 0);
        }
        public static bool DeletePortPair(int n)
        {
            if (UacHelper.IsUacEnabled)
            {
                if (!UacHelper.IsProcessElevated)
                {
                    return(false);
                }
            }
            if (!UacHelper.IsAdministrator())
            {
                return(false);
            }

            var proc = new Process
            {
                StartInfo = new ProcessStartInfo
                {
                    WorkingDirectory = Path.GetDirectoryName(_com0comSetupc),
                    FileName         = _com0comSetupc,
                    Arguments        = "remove " + n.ToString(),
                    UseShellExecute  = true,
                    CreateNoWindow   = false,
                    Verb             = "runas"
                }
            };

            proc.Start();
            //TODO: add a timeout here
            while (!proc.HasExited)
            {
            }
            return(proc.ExitCode == 0);
        }