如何使我的程序一开机就运行?无论是写在注册表里还是其他方法,是否能提供一些原代码?

解决方案 »

  1.   

    bool AutoRun(BOOL bAutoRun)
    {
    //*
    LONG lRc;
    HKEY hNewKey;
    DWORD dwDisposition;
    LPCTSTR lpszTransparent = _T("SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Run");
    CString strAppPath(_T(""));
    CHAR lpszAppPath[MAX_PATH*2] = {0}; lRc = RegCreateKeyEx(HKEY_LOCAL_MACHINE,
    lpszTransparent,
    0,
    NULL,
    REG_OPTION_NON_VOLATILE,
    KEY_ALL_ACCESS,
    NULL,
    &hNewKey,
    &dwDisposition); if (lRc != ERROR_SUCCESS)
    {
    TRACE(_T("Error int RegCreateKeyEx: %x \n"),lRc);
    return false;
    } strAppPath = AfxGetApp()->m_pszHelpFilePath;
    strAppPath = strAppPath.Left(strAppPath.GetLength() - 4) + _T(".exe");
    memcpy(lpszAppPath,strAppPath,strAppPath.GetLength()); if (dwDisposition == REG_CREATED_NEW_KEY)
    TRACE(_T("New Key Create!\n"));
    if (dwDisposition == REG_OPENED_EXISTING_KEY)
    TRACE(_T("Existing key opened!\n")); if (bAutoRun)
    {
    lRc = RegSetValueEx(hNewKey,
    _T("TransparentDesktop"),
    0,
    REG_SZ,
    (BYTE *)lpszAppPath,
    strAppPath.GetLength());
    if (lRc != ERROR_SUCCESS)
    {
    TRACE(_T("Error in RegSetValueEx :%x \n"),lRc);
    return false;
    }

    lRc = RegFlushKey(hNewKey);
    if (lRc != ERROR_SUCCESS)
    {
    TRACE(_T("Error in RegFlushKey :%x \n"),lRc);
    return false;
    }
    }
    else
    {
    if ( ERROR_SUCCESS != RegDeleteValue(hNewKey, _T("TransparentDesktop")))
    {
    TRACE(_T("Error in RegDeleteValue \n"));
    return false;
    }
    }
    lRc = RegCloseKey(hNewKey);
    if (lRc != ERROR_SUCCESS)
    {
    TRACE(_T("Error in RegCloseKey :%x \n"),lRc);
    return false;
    }
    //*/
    return true;
    }
    这个是将我写的自身是否开机就运行的函数!只要改一下!调用方面!
      

  2.   

    把你的.exe文件放到“启动”文件夹里去。
      

  3.   

    两种做法:
    1、做成NT服务程序2、写注册表:HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Run
      

  4.   

    HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Run
    写注册表到以上位置