views:

83

answers:

1

Through my desktop application's installer (C# code), I want to execute an external process. I do so using the following code.

            ProcessStartInfo sinfo = new ProcessStartInfo();
            sinfo.FileName = filePath;
            sinfo.WorkingDirectory = workingDir;
            sinfo.UseShellExecute = false;
            using (Process proc = Process.Start(sinfo))
            {
                proc.WaitForExit();
                int code = proc.ExitCode;
            }

My external process is basically trying to read a registry entry and process something with it (It only reads, does not write to the reg).

While I confirm that the registry entry values have already been updated by the installer (and I can manually read the reg entries through regedit), the external process is not able to read these. Its trying to read as follows:

                using (RegistryKey rk = Registry.CurrentUser.OpenSubKey(regKey))
                {
                    return (string)rk.GetValue(subKey);
                }

When I put a breakpoint at the above lines, I see that rk has no subkeys inside it. I am doing all this in Win7 env (dont know if the UAC is causing the troubles)

Now, when I directly run the external app manually (i.e double click the app's exe), I am able to read the reg entries easily. Seems like I am doing something wrong while starting the process. Anybody has any ideas what?

Thanks, Kapil

A: 

You may have a access problem.

Try to fill in the sinfo.username and sinfo.password properties and ensure that a user with administrative access rights starts the process

 ProcessStartInfo sinfo = new ProcessStartInfo();
        sinfo.FileName = filePath;
        sinfo.WorkingDirectory = workingDir;
        sinfo.UseShellExecute = false;
        sinfo.UserName = "username1";
        SecureString password = new SecureString();
        foreach (char c in "password1".ToCharArray()) {
           password.AppendChar(c);
        }
        sinfo.Password = password;
        using (Process proc = Process.Start(sinfo))
        {
            proc.WaitForExit();
            int code = proc.ExitCode;
        }
Martin
Thanks for the answer Martin. But how can I fill up the username and passwd properties. Is there any windows api to get the current user's username and password? I highly doubt so.
Kapil

related questions