{"id":4253,"date":"2013-05-27T07:00:00","date_gmt":"2013-05-27T07:00:00","guid":{"rendered":"https:\/\/blogs.msdn.microsoft.com\/oldnewthing\/2013\/05\/27\/how-do-i-customize-the-console-properties-for-a-shortcut-to-a-console-application\/"},"modified":"2013-05-27T07:00:00","modified_gmt":"2013-05-27T07:00:00","slug":"how-do-i-customize-the-console-properties-for-a-shortcut-to-a-console-application","status":"publish","type":"post","link":"https:\/\/devblogs.microsoft.com\/oldnewthing\/20130527-00\/?p=4253","title":{"rendered":"How do I customize the console properties for a shortcut to a console application?"},"content":{"rendered":"<p><P>\nYou already know how to create a shortcut:\n<\/P>\n<PRE>\n#include &lt;windows.h&gt;\n#include &lt;tchar.h&gt;\n#include &lt;shlobj.h&gt;\n#include &lt;atlbase.h&gt;<\/p>\n<p>\/\/ <A HREF=\"http:\/\/blogs.msdn.com\/b\/oldnewthing\/archive\/2004\/05\/20\/135841.aspx\">class CCoInitialize<\/A> incorporated here by reference<\/p>\n<p>int __cdecl _tmain(int argc, TCHAR **argv)\n{\n \/\/ error checking elided for expository purposes\n CCoInitialize init;\n CComPtr&lt;IShellLink&gt; spsl;\n spsl.CoCreateInstance(CLSID_ShellLink);\n spsl-&gt;SetPath(TEXT(&#8220;C:\\\\Windows\\\\system32\\\\cmd.exe&#8221;));\n CComQIPtr&lt;IPersistFile&gt;(spsl)-&gt;Save(L&#8221;Here.lnk&#8221;, TRUE);\n return 0;\n}\n<\/PRE>\n<P>\nIf you double-click the resulting shortcut from Explorer,\nit will run the command processor in a default console window.\n<\/P>\n<P>\nToday&#8217;s Little Program\ncustomizes the other console properties,\nso you can control settings like the\nconsole buffer size and whether\n<A HREF=\"http:\/\/blogs.msdn.com\/b\/oldnewthing\/archive\/2007\/09\/13\/4886108.aspx\">\nQuickEdit<\/A>\nis enabled by default.\n<\/P>\n<P>\nWe use the <CODE>IShell&shy;Data&shy;List<\/CODE> interface to attach\n&#8220;bonus data&#8221; to the shell link.\nThe data we are interested in here is the\n<CODE>NT_CONSOLE_PROPS<\/CODE>.\nRemember, Little Programs perform little to no error checking,\nuse hard-coded paths,\nand all that other stuff that make them\nunsuitable for shipping-quality code.\n<\/P>\n<PRE>\nint __cdecl _tmain(int argc, TCHAR **argv)\n{\n CCoInitialize init;\n CComPtr&lt;IShellLink&gt; spsl;\n spsl.CoCreateInstance(CLSID_ShellLink);\n spsl-&gt;SetPath(TEXT(&#8220;C:\\\\Windows\\\\system32\\\\cmd.exe&#8221;));<\/p>\n<p> <FONT COLOR=\"blue\">NT_CONSOLE_PROPS props;\n ZeroMemory(&amp;props, sizeof(props));\n props.dbh.cbSize = sizeof(props);\n props.dbh.dwSignature = NT_CONSOLE_PROPS_SIG;\n props.wFillAttribute = FOREGROUND_BLUE | FOREGROUND_GREEN |\n                        FOREGROUND_RED; \/\/ white on black\n props.wPopupFillAttribute = BACKGROUND_BLUE | BACKGROUND_GREEN |\n                             BACKGROUND_RED | BACKGROUND_INTENSITY |\n                             FOREGROUND_BLUE | FOREGROUND_RED;\n                             \/\/ purple on white\n props.dwWindowSize.X = 132; \/\/ 132 columns wide\n props.dwWindowSize.Y = 50; \/\/ 50 lines tall\n props.dwScreenBufferSize.X = 132; \/\/ 132 columns wide\n props.dwScreenBufferSize.Y = 1000; \/\/ large scrollback\n props.uCursorSize = 25; \/\/ small cursor\n props.bQuickEdit = TRUE; \/\/ turn QuickEdit on\n props.bAutoPosition = TRUE;\n props.uHistoryBufferSize = 25;\n props.uNumberOfHistoryBuffers = 4;\n props.ColorTable[ 0] = RGB(0x00, 0x00, 0x00);\n props.ColorTable[ 1] = RGB(0x00, 0x00, 0x80);\n props.ColorTable[ 2] = RGB(0x00, 0x80, 0x00);\n props.ColorTable[ 3] = RGB(0x00, 0x80, 0x80);\n props.ColorTable[ 4] = RGB(0x80, 0x00, 0x00);\n props.ColorTable[ 5] = RGB(0x80, 0x00, 0x80);\n props.ColorTable[ 6] = RGB(0x80, 0x80, 0x00);\n props.ColorTable[ 7] = RGB(0xC0, 0xC0, 0xC0);\n props.ColorTable[ 8] = RGB(0x80, 0x80, 0x80);\n props.ColorTable[ 9] = RGB(0x00, 0x00, 0xFF);\n props.ColorTable[10] = RGB(0x00, 0xFF, 0x00);\n props.ColorTable[11] = RGB(0x00, 0xFF, 0xFF);\n props.ColorTable[12] = RGB(0xFF, 0x00, 0x00);\n props.ColorTable[13] = RGB(0xFF, 0x00, 0xFF);\n props.ColorTable[14] = RGB(0xFF, 0xFF, 0x00);\n props.ColorTable[15] = RGB(0xFF, 0xFF, 0xFF);\n CComQIPtr&lt;IShellLinkDataList&gt;(spsl)-&gt;AddDataBlock(&amp;props);<\/FONT><\/p>\n<p> CComQIPtr&lt;IPersistFile&gt;(spsl)-&gt;Save(L&#8221;Here.lnk&#8221;, TRUE);\n return 0;\n}\n<\/PRE><\/p>\n","protected":false},"excerpt":{"rendered":"<p>You already know how to create a shortcut: #include &lt;windows.h&gt; #include &lt;tchar.h&gt; #include &lt;shlobj.h&gt; #include &lt;atlbase.h&gt; \/\/ class CCoInitialize incorporated here by reference int __cdecl _tmain(int argc, TCHAR **argv) { \/\/ error checking elided for expository purposes CCoInitialize init; CComPtr&lt;IShellLink&gt; spsl; spsl.CoCreateInstance(CLSID_ShellLink); spsl-&gt;SetPath(TEXT(&#8220;C:\\\\Windows\\\\system32\\\\cmd.exe&#8221;)); CComQIPtr&lt;IPersistFile&gt;(spsl)-&gt;Save(L&#8221;Here.lnk&#8221;, TRUE); return 0; } If you double-click the resulting shortcut from [&hellip;]<\/p>\n","protected":false},"author":1069,"featured_media":111744,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[1],"tags":[25],"class_list":["post-4253","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-oldnewthing","tag-code"],"acf":[],"blog_post_summary":"<p>You already know how to create a shortcut: #include &lt;windows.h&gt; #include &lt;tchar.h&gt; #include &lt;shlobj.h&gt; #include &lt;atlbase.h&gt; \/\/ class CCoInitialize incorporated here by reference int __cdecl _tmain(int argc, TCHAR **argv) { \/\/ error checking elided for expository purposes CCoInitialize init; CComPtr&lt;IShellLink&gt; spsl; spsl.CoCreateInstance(CLSID_ShellLink); spsl-&gt;SetPath(TEXT(&#8220;C:\\\\Windows\\\\system32\\\\cmd.exe&#8221;)); CComQIPtr&lt;IPersistFile&gt;(spsl)-&gt;Save(L&#8221;Here.lnk&#8221;, TRUE); return 0; } If you double-click the resulting shortcut from [&hellip;]<\/p>\n","_links":{"self":[{"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/posts\/4253","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/users\/1069"}],"replies":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/comments?post=4253"}],"version-history":[{"count":0,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/posts\/4253\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/media\/111744"}],"wp:attachment":[{"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/media?parent=4253"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/categories?post=4253"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/tags?post=4253"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}