×

注意!页面内容来自https://bbs.csdn.net/topics/392187632,本站不储存任何内容,为了更好的阅读体验进行在线解析,若有广告出现,请及时反馈。若您觉得侵犯了您的利益,请通知我们进行删除,然后访问 原网页

LNK2019 无法解析的外部符号 WinMain,该符号在函数 "int __cdecl __scrt_common_main_seh(void)"

huaxiasky 2017-07-03 04:43:12
#define INITGUID
#include <windows.h>
#include <GPEdit.h>
#include <winnt.h>

using namespace std;
HRESULT ModifyUserPolicyForPreventAccessToCmdPrompt(BSTR bGPOPathint iModeDWORD lData)
{
HRESULT hr = S_OK;
//
// Use IGroupPolicyObject to retrieve and modify the registry settings.
// for the GPO represented by the gpoInfo.lpDsPath
//
IGroupPolicyObject* p = NULL;
hr = CoCreateInstance(CLSID_GroupPolicyObject,NULL,
CLSCTX_INPROC_SERVER,
IID_IGroupPolicyObject,
(LPVOID*)&p);
if (SUCCEEDED(hr))
{
//
// The GPO value we want to modify is the
//
// User Configuration
// +> Policies
// +>Administrative Templates
// +->System
// +->Prevent access to the command prompt
//
DWORD dwSection = GPO_SECTION_USER;
HKEY hGPOSectionKey = NULL;
DWORD dwData;
HKEY hSettingKey;
LSTATUS rStatus;
hr = 0;
//
//Open the GPO and load its registy values for both: Machine and user
//
hr = p->OpenDSGPO(bGPOPathGPO_OPEN_LOAD_REGISTRY);
//
// Request the user Registy hive for the GPO
//
hr = p->GetRegistryKey(dwSection&hGPOSectionKey);
//
// Determine if you want to set it to Not Congigure,
// Enabled or Disabled for the GPO itself.
//
// The second callRequestSetting will provide the "Yes" or "No"
// value for setting
// the policy as shown by the GPO Editor
//
// iMode
// 0=Not Configured1=Enabled2=Disabled
//
switch (iMode)
{
case 0:
//
// We do not want to configure the GPObut we don't want to
// affect other GPOs on the same key,
// so just delete values associated with this
// particular GPO setting.
//
rStatus = RegDeleteValue(hGPOSectionKey,
L"Software\\Policies\\Microsoft\\Windows\\System\\DisableCMD"
);
rStatus = RegDeleteValue(hGPOSectionKey,
L"Software\\Policies\\Microsoft\\Windows\\System\\**del.DisableCMD"
);
break;
case 1:
{
//
// To enable the policythe DisableCMD value must
// exist and the **del.DisableCMD value must not.
//
// lData:
//
// Check to see if the key for this policy exists.
// If if it doesretrieve a handle
// If notcreate it.
//
if (RegOpenKeyEx(hGPOSectionKey,
L"Software\\Policies\\Microsoft\\Windows\\System"0,
KEY_WRITE&hSettingKey) != ERROR_SUCCESS)
{
rStatus = RegCreateKeyEx(
hGPOSectionKey,
L"Software\\Policies\\Microsoft\\Windows\\System",
0,
NULL,
REG_OPTION_NON_VOLATILE,
KEY_WRITE,
NULL,
&hSettingKey,
NULL);
}
//
// Set the value DisableCMD and allowdisallow
// script launching of CMD
//
rStatus = RegSetValueEx(hSettingKeyL"DisableCMD",
NULLREG_DWORD(BYTE *)(&lData),
sizeof(DWORD));
//
// Remove the not configured value indicator from the hive.
// It may not existso the RegDeleteValue may return
// and errorthis can be ignored.
//
rStatus = RegDeleteValue(hGPOSectionKey,
L"Software\\Policies\\Microsoft\\Windows\\System\\**del.DisableCMD"
);
rStatus = RegCloseKey(hSettingKey);
break;
}
case 2:
{
//
// Disable the policy.
// must remove the DisableCMD value and add the
// **del.DisableCMD value.
//
// Same stesp as beforecheck to see if the key for this
// policy exists,
// if notcreate it.
//
BOOL bCreate = FALSE;
if (RegOpenKeyEx(hGPOSectionKeyL"Software\\Policies\\Microsoft\\Windows\\System"0KEY_WRITE&hSettingKey) != ERROR_SUCCESS)
{
rStatus = RegCreateKeyEx(
hGPOSectionKey,
L"Software\\Policies\\Microsoft\\Windows\\System",
0,
NULL,
REG_OPTION_NON_VOLATILE,
KEY_WRITE,
NULL,
&hSettingKey,
NULL);
bCreate = TRUE;
}
DWORD dwType = 0;
DWORD cbType = sizeof(dwData);
if (!bCreate)
{
//
// If we did not create the keythen our value
// *may* exist.
// try to read it. If we succeedwrite that value back
// to **del.DisableCMD
// if notthen set **del.DisableCMD to 0
//
rStatus = RegGetValue(hGPOSectionKey,
L"Software\\Policies\\Microsoft\\Windows\\System"L"DisableCMD"RRF_RT_ANY&dwType(BYTE *)(&dwData)&cbType);
if (rStatus != ERROR_SUCCESS) dwData = 0;
else RegDeleteValue(hSettingKeyL"DisableCMD");
rStatus = RegSetValueEx(hSettingKeyL"**del.DisableCMD"NULLREG_DWORD(BYTE *)(&dwData)sizeof(DWORD));
}
else
{
//
// The key was createdjust set the **del.DisableCMD
// value to 0
//
dwData = 0;
rStatus = RegSetValueEx(hSettingKeyL"**del.DisableCMD"NULLREG_DWORD(BYTE *)(&dwData)sizeof(DWORD));
}
rStatus = RegCloseKey(hSettingKey);
}
}

GUID RegistryId = REGISTRY_EXTENSION_GUID;
GUID ThisAdminToolGuid =
/*{ CLSID_PolicySnapinUser/* */
{
0x0F6B957E,
0x509E,
0x11D1,
{ 0xA70xCC0x000x000xF80x750x710xE3 }
};
rStatus = RegCloseKey(hGPOSectionKey);
//
// Write the GPO back to the directory
//
hr = p->Save(
FALSE,
TRUE,
®istryId,
&ThisAdminToolGuid);

hr = p->Release();
}
return hr;
}

可以编译


但是一调试就出问题



运行环境 我本机的操作系统是win7 x64


请问这个要怎么解决呢?
...全文
3350 6 打赏 收藏 转发到动态 举报
写回复
用AI写文章
6 条回复
切换为时间正序
请发表友善的回复…
发表回复
clever101 2020-11-13
  • 打赏
  • 举报
回复
我碰到的编译错误是: 1>MSVCRT.lib(exe_winmain.obj) : error LNK2019: 无法解析的外部符号 WinMain,该符号在函数 "int __cdecl __scrt_common_main_seh(void)" (?__scrt_common_main_seh@@YAHXZ) 中被引用 1>..\..\..\OutDir\Release_x64\test.exe : fatal error LNK1120: 1 个无法解析的外部命令 就是用前一个回复提到的链接解决的。
clever101 2020-11-13
  • 打赏
  • 举报
回复
Disable Unicode in Release Or add the /entry:mainCRTStartup linker flag in Release 参考: Qt project in Visual Studio 2015: “unresolved external symbol wWinMain”
clever101 2020-11-13
  • 打赏
  • 举报
回复
楼主,你建的是什么工程?
huaxiasky 2017-07-04
  • 打赏
  • 举报
回复
我改了以后还是出错啊。不过这一次是LIBCMT.lib(exe_main.obj)


战在春秋 2017-07-04
  • 打赏
  • 举报
回复
由向导重新创建工程,选择win32 project。
战在春秋 2017-07-03
  • 打赏
  • 举报
回复
工程类型不对。

右键单击项目,选择:
Properties->Linker->System->SubSytem
将 Windows (/SUBSYSTEM:WINDOWS) 修改为 Console (/SUBSYSTEM:CONSOLE)




用心回答每个问题,如果对您有帮助,请采纳答案好吗,谢谢!