vc添加应用程序快捷方式

来源:互联网 发布:淘宝客url解密 编辑:程序博客网 时间:2024/05/22 00:50

BOOL CSharpViewClientDlg::FileLink(const CString strPathObj,const CString strPathLink)
{
 
 BOOL bRet = FALSE;
 IShellLink* psl;
 
 if (SUCCEEDED( CoCreateInstance(CLSID_ShellLink,
  NULL,
  CLSCTX_INPROC_SERVER,
  IID_IShellLink,
  (LPVOID*) &psl))
  )
 {
  IPersistFile* ppf;
  
  psl->SetPath(strPathObj);
  
  if (SUCCEEDED(psl->QueryInterface( IID_IPersistFile, (LPVOID *) &ppf)))
  {
   
   WORD wsz[MAX_PATH];
   MultiByteToWideChar(CP_ACP,
    MB_PRECOMPOSED,
    strPathLink,
    -1,
    wsz,
    MAX_PATH);
   
   if ( SUCCEEDED ( ppf->Save(wsz, TRUE) ) )
    bRet = TRUE;
   
   ppf->Release();
  }
  psl->Release();
 }
 return bRet;
}
void CSharpViewClientDlg::MainDialg_load()
{
// CString sSysinfor=m_SystemIfo.GetEventLoginfor();
  //TRACE(sSysinfor);
  CString sAutoPath=m_sCurrenDir+"//SharpViewClient.exe";
/* SetAutoRun(sAutoPath);//设置开机自动启动*/
 char crEnVar[MAX_PATH];
 ::GetEnvironmentVariable("ALLUSERSPROFILE", crEnVar, MAX_PATH);
 if (strlen(crEnVar) > 0)
 {
  CString destPath = CString(crEnVar);
  destPath += "//「开始」菜单//程序//启动//";
  destPath += "锐视网络行为规范";
  destPath += ".lnk";
  
  FileLink(sAutoPath, destPath);
 }
 else
 {
  ::AfxMessageBox("can'n get Evironment-Variable",MB_OK);
  gLog.WriteLog("can'n get Evironment-Variable");
 }

原创粉丝点击