<p>We've got an interesting case where we are trying to determine how different instances of our app were launched. Is there any way for .NET to be able to query another running instance and get the command line parameters passed to that instance? I've not been able to find any way to do it in .NET so far, so I thought I'd check here to see if anyone had done anything like this before.</p>

[{'answer_id': 44267, 'author': 'Adam Davis', 'author_id': 2915, 'author_profile': 'https://Stackoverflow.com/users/2915', 'pm_score': 2, 'selected': False, 'text': "<p>Generally those variables are stored in the program's memory space, which you should (theoretically) should not be able to access.</p>\n\n<p>You'll need to find out how to initiate interprocess communication with the other instances and trade data.  Named pipes are one good option, but you might want to start a new stackoverflow question to get good options on this.</p>\n\n<p>-Adam</p>\n"}, {'answer_id': 44310, 'author': 'Rob Walker', 'author_id': 3631, 'author_profile': 'https://Stackoverflow.com/users/3631', 'pm_score': 3, 'selected': True, 'text': '<p>You can retrieve this information through WMI.</p>\n\n<p>See the <a href="http://msdn.microsoft.com/en-us/library/aa394372.aspx" rel="nofollow noreferrer">Win32_Process</a> class, in particular its command line property.  This <a href="http://www.codeproject.com/KB/cs/EverythingInWmi02.aspx" rel="nofollow noreferrer">Code Project article</a> provides pointers on how to do this,</p>\n'}, {'answer_id': 127201, 'author': 'Noah', 'author_id': 4539, 'author_profile': 'https://Stackoverflow.com/users/4539', 'pm_score': 0, 'selected': False, 'text': '<p>For future reference, here is a code snippet from how I got it to work. This was just for a test to see how it all worked. The actual implemented code parses the command line parameters for what we need.</p>\n\n<pre><code>try\n{\n   ManagementScope connectScope = new ManagementScope();\n   connectScope.Path = new ManagementPath(@"\\\\" + Environment.MachineName + @"\\root\\CIMV2");\n\n   SelectQuery msQuery = new SelectQuery("SELECT * FROM Win32_Process Where Name = \'" + "PROGRAMNAMEHERE.exe" + "\'");\n   ManagementObjectSearcher searchProcedure = new ManagementObjectSearcher(connectScope, msQuery);\n\n   foreach (ManagementObject item in searchProcedure.Get())\n   {\n      try \n      {\n         MessageBox.Show(item["CommandLine"].ToString()); \n      }\n      catch (SystemException) \n      {}\n   }\n}\n</code></pre>\n'}]
['https://Stackoverflow.com/questions/44260', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/4539/']