본문 바로가기

Programming/MFC

레지스트리에 등록된 프로그램을 실행 시키기

// 레지스트리에 등록된 프로세스의 실행 경로를 검색하고

// 해당 프로세스 아이디를 가지고 실행 시킬수 있다.

// 밑에 함수는 VLC의 실행과 종료에 관련된 함수이다.

 

//==================================================================================================================
BOOL CErSender::VLCStart()
{
 //==================================================================================================================

 HKEY  nKey = NULL ;
 DWORD dwType = NULL ;
 DWORD nSize = NULL ;

 char strPath[256] ;
 memset( strPath, _T('\0'), 256 ) ; 

 // 레지스트리에 등록된 키값을 찾는다.
 if ( RegOpenKeyEx( HKEY_LOCAL_MACHINE, _T("SOFTWARE\\VideoLAN\\VLC"), 0, KEY_READ, &nKey ) == ERROR_SUCCESS )
 {   
  // 우선 레지스트리에서 얻고자하는 서브키값의 데이터 타입과 길이를 얻어온다.
  if ( RegQueryValueEx( nKey, _T("InstallDir"), 0, &dwType, NULL, &nSize ) == ERROR_SUCCESS )
  {
   // 실제 데이터 값을 가져온다.
   RegQueryValueEx( nKey, _T("InstallDir"), 0, &dwType, (LPBYTE)strPath, &nSize ) ;
  }
  else
  {
   AfxMessageBox(_T("Error RegQueryValueEx()")) ;
   return FALSE ;
  }
 } 
 else 
 {
  AfxMessageBox(_T("You Must Install VideoLAN")) ;
  return FALSE ;
 }


 RegCloseKey( nKey) ;

 //==================================================================================================================\
 
 m_stSI.cb = sizeof(STARTUPINFO) ;
 m_stSI.lpReserved = NULL ;
 m_stSI.lpReserved2 = NULL ;
 m_stSI.cbReserved2 = 0 ;
 m_stSI.lpDesktop = NULL ;
 m_stSI.lpTitle = NULL ;
 m_stSI.dwFlags = STARTF_USESHOWWINDOW ;
 m_stSI.dwX = 0 ;
 m_stSI.dwY = 0 ;
 m_stSI.dwFillAttribute = 0 ;
 m_stSI.wShowWindow = SW_SHOW ;

 CString strVLCPath ;
 strVLCPath = strPath ;

 

 if ( m_strSDPPath.GetLength() <= 0 )
 {
  AfxMessageBox( _T("Need to SDP File Path")) ;
  return FALSE ;
 }

 char strVLCPullPath[1024] ;
 memset( strVLCPullPath, _T('\0'), 1024 ) ;
 strcpy( strVLCPullPath, strPath ) ;
 strcat( strVLCPullPath, _T("\\vlc.exe")) ;
 strcat( strVLCPullPath, m_strSDPPath ) ;
 
 
 // Process 생성 & Play
 if ( CreateProcess( NULL, strVLCPullPath, NULL, NULL, FALSE, 0, NULL, NULL, &m_stSI, &m_stPI ) == FALSE )
 {
  AfxMessageBox( _T("Error CreateProcess(VLC)")) ;
  return FALSE ;
 }

 return TRUE ;
}

 

 

 

void CErSender::VLCStop()
{
 // 종료
 ::TerminateProcess( m_stPI.hProcess, NULL ) ;

 // Close 
 CloseHandle( m_stPI.hProcess ) ;
 CloseHandle( m_stPI.hThread ) ;
}

'Programming > MFC' 카테고리의 다른 글

Thread 강제 종료  (0) 2006.09.27
TextProgress 사용하기  (0) 2006.09.27
System Error Codes  (0) 2006.09.05
하나의 프로그램만 실행시키고 싶다면..  (0) 2006.09.01
윈도우 클래스 이름을 얻어주는 Spy++  (0) 2006.08.31