Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8341091
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T05:21:56+00:00 2026-06-09T05:21:56+00:00

I am developing a C# application. I need to create and pass variables to

  • 0

I am developing a C# application.

I need to create and pass variables to a new process and I am doing it using ProcessStartInfo.EnvironmentVariables.

The new process must run elevated so I am using Verb = “runas”

var startInfo =  new ProcessStartInfo(command)
{
    UseShellExecute = true,
    CreateNoWindow = true,
    Verb = "runas"
};
foreach (DictionaryEntry entry in enviromentVariables)
{
    startInfo.EnvironmentVariables.Add(entry.Key.ToString(), entry.Value.ToString());
}

The problem is that according to the msdn documentation:

You must set the UseShellExecute property to false to start the process after changing the EnvironmentVariables property. If UseShellExecute is true, an InvalidOperationException is thrown when the Start method is called.

but the runas variable requires UseShellExecute=true

Is there a way to do both: run process as elevated and also set the environment variables?

EDIT

I will try to rephrase my question…

Is there a way to pass arguments securly to another process so only the other process will be able to read the arguments.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-09T05:21:58+00:00Added an answer on June 9, 2026 at 5:21 am

    It works but on the downside is that it also shows a second command prompt, the enviroment vars are only set in the context of the started process so the settings are not propagating to the whole box.

        static void Main(string[] args)
        {
            var command = "cmd.exe";
            var environmentVariables = new System.Collections.Hashtable();
            environmentVariables.Add("some", "value");
            environmentVariables.Add("someother", "value");
    
            var filename = Path.GetTempFileName() + ".cmd";
            StreamWriter sw = new StreamWriter(filename);
            sw.WriteLine("@echo off");
            foreach (DictionaryEntry entry in environmentVariables)
            {
                sw.WriteLine("set {0}={1}", entry.Key, entry.Value);
            } 
            sw.WriteLine("start /w {0}", command);
            sw.Close();
            var psi = new ProcessStartInfo(filename) {
                UseShellExecute = true, 
                Verb="runas"
            };
            var ps =  Process.Start(psi);
            ps.WaitForExit();
            File.Delete(filename);
        }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Hello i am new in developing Android applications, I need to create an application
Iam developing one application.In that iam using the uilabels.And my problem is i need
I am developing a simple game part of application where i need to create
I'm developing a windows application in C# using VS2005. Consider i need to call
I'm developing a simple Facebook application, and now I need to create a page
I am developing a Java desktop application. I have a need to create HTML
I'm developing on WinXP Pro 32bit using VS2008 Pro. Do I need to create
I'm developing an application where i need to create pdf file based on user
I am developing a web application and I need to create an EverNote notebook
I'm developing an iPhone app. I need to create a Quiz application that has

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.