Tuesday, January 31, 2012

Elevate the process to run with admin mode

http://msdn.microsoft.com/en-us/library/bb756929.aspx




Create an name.exe.manifest







level="requireAdministrator"

uiAccess="false"/>







VS Command prompt : mt.exe -manifest menu.exe.manifest -outputresource:menu.exe;#1



Post build event:

"$(DevEnvDir)\..\Tools\Bin\mt.exe" -manifest "$(ProjectDir)$(TargetName).exe.manifest" -outputresource:"$(TargetDir)$(TargetName).exe;#1"



For VS2010,

Project Properties > Configuration Properties > Linker > Manifest File

Change the 'UAC Execution Level' to the desired value.



Pasted from



Thursday, January 12, 2012

C# friendly user app

Place the cursor to the box that user want by setting tab order correctly
hit enter to do some default value by handling control key press event
use this.width, this.height to get window position

//to get active window size


[System.Runtime.InteropServices.DllImport("user32.dll")]

static extern IntPtr GetForegroundWindow();

private static IntPtr GetCurrActiveWindow()

{

IntPtr handle = IntPtr.Zero;

return GetForegroundWindow();

}



[System.Runtime.InteropServices.DllImport("user32.dll")]

[return: System.Runtime.InteropServices.MarshalAs(System.Runtime.InteropServices.UnmanagedType.Bool)]

private static extern bool GetWindowRect(IntPtr hWnd, out RECT lpRect);
[System.Runtime.InteropServices.StructLayout(System.Runtime.InteropServices.LayoutKind.Sequential)]

public struct RECT

{

public int Left;

public int Top;

public int Right;

public int Bottom;

}



public static RECT GetCurrActiveWindowSize()

{

RECT size = new RECT();

try

{

GetWindowRect(GetCurrActiveWindow(), out size);

}

catch (Exception ex)

{

TraceMessage.Write("QTMUtility.GetCurrActiveWindowSize", ex.Message, TraceMessageType.Exception);

}

return size;

}