Using the EnvDTE assembly
See the question and my original answer on StackOverflowEnvDTE only works from within Visual Studio, if that's what you mean.
However, you can control Visual Studio programmatically (using COM monikers you can access to a given Visual Studio instance remotely). Check these blog posts here: How to start Visual Studio programmatically and How to get DTE from Visual Studio process ID?