c++创建cmd.exe的快捷方式

c++创建cmd.exe快捷方式,网上找的很多代码都是简单的使用IShellLink和IPersistFile,这样建出来的快捷方式在win10下默认是开启QuickEdit Mode的。然后运行的时候鼠标可以点击选中里面的文字,如果是对批处理文件建立快捷方式,这个时候会阻止bat往下运行,解决方法就是建立快捷方式的时候关闭QuickEdit Mode,代码如下:

#include "stdafx.h"
#include <windows.h>
#include <tchar.h>
#include <shlobj.h>
#include <atlbase.h>

int _tmain(int argc, TCHAR **argv)
{
	HRESULT hr = CoInitialize(NULL);
	if(SUCCEEDED(hr)){
			
		CComPtr<IShellLink> spsl;
		spsl.CoCreateInstance(CLSID_ShellLink);
		spsl->SetPath(TEXT("C:\\Windows\\system32\\cmd.exe"));

		NT_CONSOLE_PROPS props;
		ZeroMemory(&props, sizeof(props));
		props.dbh.cbSize = sizeof(props);
		props.dbh.dwSignature = NT_CONSOLE_PROPS_SIG;
		props.wFillAttribute = FOREGROUND_BLUE | FOREGROUND_GREEN | FOREGROUND_RED; // white on black
		props.wPopupFillAttribute = BACKGROUND_BLUE | BACKGROUND_GREEN |
									BACKGROUND_RED | BACKGROUND_INTENSITY |
									FOREGROUND_BLUE | FOREGROUND_RED;
		props.dwWindowSize.X = 80; // 132 columns wide
		props.dwWindowSize.Y = 30; // 50 lines tall
		props.dwScreenBufferSize.X = 80; // 132 columns wide
		props.dwScreenBufferSize.Y = 30; // large scrollback
		props.uCursorSize = 25; // small cursor
		props.bQuickEdit = FALSE; // turn QuickEdit off
		props.bAutoPosition = TRUE;
		props.uHistoryBufferSize = 1;
		props.uNumberOfHistoryBuffers = 1;
		props.ColorTable[ 0] = RGB(0x00, 0x00, 0x00);
		props.ColorTable[ 1] = RGB(0x00, 0x00, 0x80);
		props.ColorTable[ 2] = RGB(0x00, 0x80, 0x00);
		props.ColorTable[ 3] = RGB(0x00, 0x80, 0x80);
		props.ColorTable[ 4] = RGB(0x80, 0x00, 0x00);
		props.ColorTable[ 5] = RGB(0x80, 0x00, 0x80);
		props.ColorTable[ 6] = RGB(0x80, 0x80, 0x00);
		props.ColorTable[ 7] = RGB(0xC0, 0xC0, 0xC0);
		props.ColorTable[ 8] = RGB(0x80, 0x80, 0x80);
		props.ColorTable[ 9] = RGB(0x00, 0x00, 0xFF);
		props.ColorTable[10] = RGB(0x00, 0xFF, 0x00);
		props.ColorTable[11] = RGB(0x00, 0xFF, 0xFF);
		props.ColorTable[12] = RGB(0xFF, 0x00, 0x00);
		props.ColorTable[13] = RGB(0xFF, 0x00, 0xFF);
		props.ColorTable[14] = RGB(0xFF, 0xFF, 0x00);
		props.ColorTable[15] = RGB(0xFF, 0xFF, 0xFF);
		CComQIPtr<IShellLinkDataList>(spsl)->AddDataBlock(&props);

		CComQIPtr<IPersistFile>(spsl)->Save(L"Here.lnk", TRUE);
		CoUninitialize();
	}

	return 0;
}