Beispiel #1
0
        public static DomainUser GetDomainUser(string processName, bool ignoreSystemUsers)
        {
            SelectQuery selectQuery = new SelectQuery("select * from Win32_Process where name='" + processName + "'");

            using (ManagementObjectSearcher searcher = new ManagementObjectSearcher(selectQuery)) {
                using (ManagementObjectCollection processes = searcher.Get()) {
                    foreach (ManagementObject process in processes)
                    {
                        using (process) {
                            //out argument to return user and domain
                            string[] s = new String[2];
                            //Invoke the GetOwner method and populate the array with the user name and domain
                            process.InvokeMethod("GetOwner", (object[])s);
                            DomainUser du = new DomainUser(s[1], s[0]);
                            if (ignoreSystemUsers && DomainUser.IsSystemAccount(du))
                            {
                                // keep looking
                            }
                            else
                            {
                                return(du);
                            }
                        }
                    }
                }
            }
            return(null);
        }
Beispiel #2
0
        void launchWizard(string targetFolder)
        {
//            MessageBox.Show("Installer committed.  Getting pid for installer....");

            try {
                // launch the wizard exe as a new process, passing the PID of the current process.
                // the wizard exe is coded to wait for the pid to finish executing, if given a pid.
                // we do this because one MSI cannot launch another MSI.  Since the wizard exe launches
                // the individual MSI's for each app/component, we need to wait until this one completes.
                int pid = Process.GetCurrentProcess().Id;

//                string args = "/pid " + pid;

                string targetFileName = (targetFolder + @"\GrinGlobal.ConfigurationWizard.exe").Replace(@"\\", @"\");

//                MessageBox.Show("Launching wizard at '" + targetFileName + "'...");


                DomainUser du = DomainUser.Current;

                //                MessageBox.Show("Current user: "******"ConfigurationWizard") + @"\gguac.exe").Replace(@"\\", @"\"), @" """ + targetFileName + @""" /pid " + pid);
                        //Process p = Process.Start(psi);


                        DomainUser du2 = DomainUser.CurrentLoggedIn;
                        //MessageBox.Show("Going to run new instance of config wizard as: " + du2);
                        if (Toolkit.IsWindowsVistaOrLater)
                        {
                            Toolkit.LaunchProcess((Utility.GetTargetDirectory(this.Context, null, "ConfigurationWizard") + @"\gguac.exe").Replace(@"\\", @"\"), @" """ + targetFileName + @""" /pid " + pid, du2, false, false);
                        }
                        else
                        {
                            Toolkit.LaunchProcess(targetFileName, " /pid " + pid, du2, false, false);
                        }

                        return;
                    } catch (Exception exUser) {
                        MessageBox.Show("Error launching config wizard: " + exUser.Message);
                        return;
                    } finally {
                        fi.Close();
                    }
                }

                //ProcessStartInfo psi = new ProcessStartInfo(targetFileName, args);
                //psi.WorkingDirectory = targetFolder;
                //psi.UseShellExecute = false;
                //Process.Start(psi);

                // note we do not want to wait for it to end.
                // the wizard's exe knows to monitor the given pid and not start processing until the pid is gone.
            } catch (Exception ex) {
                Context.LogMessage("Exception launching wizard: " + ex.Message);
            }
        }