举例:
要自动运行"D:\Myprog\MyProgram.exe", 修改注册表,在
HKEY_LOCAL_MACHINE\Software\Microsoft\Windows\CurrentVersion\Run
中加一项:
RunMyProg="D:\Myprog\MyProgram.exe"
#include <windows.h>
static char subkey[] = "Software\\Microsoft\\Windows\\CurrentVersion\\Run"
static char vname[] = "RunMyProg"
static char exefile[] = "D:\\Myprog\\MyProgram.exe"
ULONG dType = REG_SZ, len = 0
HKEY hKey
RegOpenKeyEx(HKEY_LOCAL_MACHINE,subkey,0,KEY_SET_VALUE|KEY_QUERY_VALUE,&hKey)//打开。
if (RegQueryValueEx(hKey, vname, 0, &dType, NULL, &len)) { //如果没有RunMyProg,
RegSetValueEx(hKey, vname, 0, REG_SZ, exefile, strlen(exefile)+1)//就加上。
}
RegCloseKey(hKey)//关闭。
需要准备的材料分别有:电脑、C语言编译器。
1、首先,打开C语言编译器,新建一个初始.cpp文件,例如:test.cpp。
2、在test.cpp文件中,输入C语言代码:int fun(){return 1}。
3、编译器运行test.cpp文件,此时成功调用fun()函数输出了内容。