Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Switching between Visual Studio instances
#1
Hi

I regularly have a large number of Visual Studio 2003 solutions open at the same time. I'd like to create a macro to switch to a particular solution, eg based on the name of the solution loaded. The problem I have is that the window title for Visual Studio follows the currently selected sub-project within the solution and as a result I can't get QM to activate on a specific solution's window. Any ideas?

How about this for a workaround: Is there any way of detecting the process id when a specified application (with particular startup parameters, or from a specified windows shortcut .lnk file) is launched and then activating the process main window based on process id within a macro?

I'm using QM Pro v2.2.1.5.

Many thanks

Mark
#2
Visual Studio can be automated using COM.
Import the attached file.
Call function VS_ActivateSolution from your macro.
Also there are functions to open a file/line, and to display a string in VS output.


Attached Files
.qml   Visual Studio automation.qml (Size: 2.85 KB / Downloads: 381)
#3
Great, thanks Gintaras! I'll give it a go.
#4
I'm guessing I need to get the latest version of QM as when the VS_ActivateSolution fn is executed the identifiers 'empty' and 'EnvDTE.Solution' are giving the errors 'unknown identifier'.

Do I need to upgrade?

PS I bounced QM after doing the qml import.
#5
Function 'empty' added i some newer QM version. You can replace 'empty' to '!len'.
#6
Thanks, that fixes the empty error. But I still have the error on EnvDTE.
#7
Maybe it is optional component of Visual Studio and currently not installed.
#8
Here is how to get command line and other properties of all processes.
Macro Macro1557
Code:
Copy      Help
def wbemFlagReturnImmediately 16
def wbemFlagForwardOnly 32
int IFlags = wbemFlagReturnImmediately|wbemFlagForwardOnly
IDispatch objWMIService._getfile("winmgmts:")
IDispatch colProcesses = objWMIService.ExecQuery("SELECT Name,ProcessId,ExecutablePath,CommandLine FROM Win32_Process",@,IFlags)

IDispatch objProcess
foreach objProcess colProcesses
,int pid=objProcess.ProcessId
,str name=objProcess.Name
,if(!pid or name~"System") continue
,str path=objProcess.ExecutablePath; err path=""
,str cl=PathGetArgs(objProcess.CommandLine); err cl=""
,cl.trim("''")
,out "------------[]name: %s[]path: %s[]pid:  %i[]cl:   %s" name path pid cl

This code gets only commandlines of devenv.exe processes.
Macro Macro1558
Code:
Copy      Help
def wbemFlagReturnImmediately 16
def wbemFlagForwardOnly 32
int IFlags = wbemFlagReturnImmediately|wbemFlagForwardOnly
IDispatch objWMIService._getfile("winmgmts:")
IDispatch colProcesses = objWMIService.ExecQuery("SELECT ProcessId,CommandLine FROM Win32_Process WHERE Name='devenv.exe'",@,IFlags)

IDispatch objProcess
foreach objProcess colProcesses
,int pid=objProcess.ProcessId
,str cl=PathGetArgs(objProcess.CommandLine)
,cl.trim("''")
,out cl
#9
Function VS_ActivateSolution2
Code:
Copy      Help
;\
function $solutionPath

;Activates main window of specified Visual Studio solution.

;solutionPath - solution path, like "Q:\app\app.sln".
;;;It must be command line of the solution process.


def wbemFlagReturnImmediately 16
def wbemFlagForwardOnly 32
int IFlags = wbemFlagReturnImmediately|wbemFlagForwardOnly
IDispatch objWMIService._getfile("winmgmts:")
IDispatch colProcesses = objWMIService.ExecQuery("SELECT ProcessId,CommandLine FROM Win32_Process WHERE Name='devenv.exe'",@,IFlags)

IDispatch objProcess
foreach objProcess colProcesses
,str cl=PathGetArgs(objProcess.CommandLine)
,cl.trim("''")
,if cl~solutionPath
,,int pid=objProcess.ProcessId
,,act win("Microsoft Visual" "wndclass_desked_gsk" pid)
,,break
#10
Many thanks - I've come to the conclusion I need to upgrade my QM as I don't have PathGetArgs available.

I've asked my desktop support guys to download the latest exe.

I'll return once I've upgraded.

Cheers

Mark
#11
Or insert this before.

dll shlwapi [PathGetArgsA]$PathGetArgs $pszPath
#12
Dear Gintaras,

I used Macro1558 to get the command line of a certain process, namely msimn.exe (OE) by clicking on an appropriate file (.eml) on windows explorer, successfully. Therefore I got through this command line the file path which it initiated this process. In the case that I need to open another .eml file simultaneously, is there any way to obtain its file path (not file name) as well? Many thanks.


Forum Jump:


Users browsing this thread: 2 Guest(s)