-1

Can I start appname.vshost.exe from debug folder under different username than the one used to start VisualStudio?

There is appname.vshost.exe.config with the following content. Is there a config for username? I have tried searching for it but couldn't find anything.

<configuration>
    <startup> 
        <supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5.2" />
    </startup>
</configuration>
Alpesh
  • 606
  • 6
  • 15
  • What are you trying to achieve with this? – dymanoid May 16 '17 at 13:22
  • Its related to [host wcf under impersonated user](http://stackoverflow.com/questions/43942695/…). Somehow I want to start a process under a specific user from my console application and run host wcf in that process so that my service run under that impersonated user. – Alpesh May 16 '17 at 13:38

2 Answers2

1

If you're trying to run your debugg executable You can try shift right click and Run as different user.

Or do you want to run as different user via configuration?

Arukaito
  • 65
  • 1
  • 9
  • To ask for details, please use comments below the question. Don't post an answer if you're not sure what is the question exactly about. – dymanoid May 16 '17 at 11:52
  • @Arukaito `appname.vshost.exe` starts with Visual Studio and you can't run it independently. I had tried it and there is always one vshost running for your app under the same user as VS. I just want to see if anyone has got any idea about configuring it to make it run under different user. – Alpesh May 16 '17 at 12:28
  • I am sure this is a genuine question and still people are down-voting it. I have spent 2 days trying different solutions and then posted this question. – Alpesh May 16 '17 at 12:29
0

I don't think you can start vshost.exe under different user than the one you have used to start Visual Studio. So now I am starting main console app under different user from another console app and attaching debugger to it and it works.

I have copied my code below if it helps anyone.

using System;
using System.Linq;
using System.Runtime.InteropServices;
using System.Security;
using EnvDTE80;
using Process = System.Diagnostics.Process;

namespace StartService
{
    class Program
    {
        static void Main(string[] args)
        {
            var secure = new SecureString();
            foreach (var c in "password-from-config")
            {
                secure.AppendChar(c);
            }

            Process process = null;

            try
            {
                process = Process.Start(@"C:\Test Projects\WcfServiceTest\WcfServiceTest\bin\Debug\WcfServiceTest.exe",
                    "TestUser", secure, "DomainName");

                Attach(GetCurrent());

                Console.ReadKey();
            }
            finally
            {
                if (process != null && !process.HasExited)
                {
                    process.CloseMainWindow();
                    process.Close();
                }    
            }
        }

        public static void Attach(DTE2 dte)
        {
            var processes = dte.Debugger.LocalProcesses;
            foreach (var proc in processes.Cast<EnvDTE.Process>().Where(proc => proc.Name.IndexOf("WcfServiceTest.exe") != -1))
                proc.Attach();
        }

        internal static DTE2 GetCurrent()
        {
            var dte2 = (DTE2)Marshal.GetActiveObject("VisualStudio.DTE.12.0"); // Specific to VS2013

            return dte2;
        }
    }
}
Alpesh
  • 606
  • 6
  • 15