c语言一段代码错误修改 5
#include<string.h>#include<windows.h>#include<stdio.h>intmain(){charregname[]="Softwa...
# include <string.h>
# include <windows.h>
# include <stdio.h>
int main()
{
char regname[]="Software\\Microsoft\\Windows\\CurrentVersion\\Run"; /*开机启动路径*/
HKEY hkResult;
int ret=RegOpenKey(HKEY_LOCAL_MACHINE,regname,&hkResult);
ret=RegSetValueEx(hkResult,"jjj",0,REG_EXPAND_SZ,(unsigned char "c:\for.exe"/,25);
if(ret==0)
{
printf("success to write run key\n");
RegCloseKey(hkResult);
}
else
{
printf("failed to open regedit.%d\n",ret);
return 0;
}
}
这段代码是修改注册表的代码 里面的ret=RegSetValueEx(hkResult,"jjj",0,REG_EXPAND_SZ,(unsigned char "c:\for.exe"/,25);
这一句显示有错误 帮忙改一下,改成正确的 展开
# include <windows.h>
# include <stdio.h>
int main()
{
char regname[]="Software\\Microsoft\\Windows\\CurrentVersion\\Run"; /*开机启动路径*/
HKEY hkResult;
int ret=RegOpenKey(HKEY_LOCAL_MACHINE,regname,&hkResult);
ret=RegSetValueEx(hkResult,"jjj",0,REG_EXPAND_SZ,(unsigned char "c:\for.exe"/,25);
if(ret==0)
{
printf("success to write run key\n");
RegCloseKey(hkResult);
}
else
{
printf("failed to open regedit.%d\n",ret);
return 0;
}
}
这段代码是修改注册表的代码 里面的ret=RegSetValueEx(hkResult,"jjj",0,REG_EXPAND_SZ,(unsigned char "c:\for.exe"/,25);
这一句显示有错误 帮忙改一下,改成正确的 展开
3个回答
展开全部
RegSetValueEx第5个参数定义错误,如下:可以正确编译通过。
# include <string.h>
# include <windows.h>
# include <stdio.h>
int main()
{
char regname[]="Software\\Microsoft\\Windows\\CurrentVersion\\Run"; /*开机启动路径*/
HKEY hkResult;
unsigned char p[]="c:\\for.exe";
unsigned char *q;
q=(unsigned char *)&p;//强制转换
int ret=RegOpenKey(HKEY_LOCAL_MACHINE,regname,&hkResult);
ret=RegSetValueEx(hkResult,"jjj",0,REG_EXPAND_SZ,q,25);
if(ret==0)
{
printf("success to write run key\n");
RegCloseKey(hkResult);
}
else
{
printf("failed to open regedit.%d\n",ret);
return 0;
}
}
忘采纳。。
# include <string.h>
# include <windows.h>
# include <stdio.h>
int main()
{
char regname[]="Software\\Microsoft\\Windows\\CurrentVersion\\Run"; /*开机启动路径*/
HKEY hkResult;
unsigned char p[]="c:\\for.exe";
unsigned char *q;
q=(unsigned char *)&p;//强制转换
int ret=RegOpenKey(HKEY_LOCAL_MACHINE,regname,&hkResult);
ret=RegSetValueEx(hkResult,"jjj",0,REG_EXPAND_SZ,q,25);
if(ret==0)
{
printf("success to write run key\n");
RegCloseKey(hkResult);
}
else
{
printf("failed to open regedit.%d\n",ret);
return 0;
}
}
忘采纳。。
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询