Wednesday, January 29, 2014

CSharp C# Stack output of method that called your method

CSharp C# Stack output of method that called your method

This is a simple example of using the StackFrame to determine the name of the method that called the current method.


Also consider:
Console.Writeline("Method:{0} was called by:{1}", new StackTrace().GetFrame(1).GetMethod().Name, new StackFrame(1, true).GetMethod().Name);

using System;
using System.Diagnostics;

namespace GetCallingMethod
{
    class Program
    {
        static void Main(string[] args)
        {
            FirstCaller();
            Console.WriteLine();
            Console.ReadLine();
        }

        private static void FirstCaller()
        {
            CalledNow();
        }

        private static void CalledNow()
        {
            Console.WriteLine("Called by:{0}", new StackFrame(1, true).GetMethod().Name);
        }
    }
}



Friday, January 24, 2014

WMIC - How to get the command line of a process call

WMIC - How to get the command line of a process call

Situation:
I would like to know the following about the launch of MyProgram.exe on my remote server, MyTargetServer:
1.       Is it running?
2.       What was the command line call?

Call:

wmic /node:"WA-BLDSRV1-DEV" process get commandline | findstr MyProgram

Result:

C:\Windows\system32>wmic /node:"MyTargetServer" process get commandline | findstr TestSeriesManager
cmd  /c MyProgram.exe QA_BVT_Only_20140124.3


MyProgram.exe  QA_BVT_Only_20140124.3



C:\Windows\system32>


I now know that MyProgram.exe is running and that the parameter, QA_BVTOnly_20140124.3, was passed to it in the call.