사용자가 제작한 확장자 파일을 클릭한 경우 설치한 프로그램에 연결하고자 할 때 인스톨쉴드의 스크립트 부분에 다음 함수를 구현한다.

1. 스크립트 맨 위쪽에 구현할 함수를 선언한다.
prototype NUMBER MakeAssociation(STRING, STRING, STRING); //선언부분

.

.

.

.

////////////////////////////////////////////////////////////////////////
//                                                                    //
//  Function:   MakeAssociation                                       //
//                                                                    //
//  Purpose:    Creates a file association in the Registry.  Use      //
//            this function for Explorer shell only, as it will       //
//            not create the extra application identification keys,   //
//            which are necessary for Program Mananger shell.         //
//            For Program Manager shell, you can use the script-      //
//            based function MakeAssociationEx.                       //
//                                                                    //
//  Parameters:                                                       //
//      szApp:    String with full path to the executable to be       //
//                associated with the file extension.                 //
//                                                                    //
//      szExtension:  String with the extension to be associated      //
//                with an application.  Must include the preceding    //
//                period (for example:  ".txt")                       //
//                                                                    //
//      szIcon :   String with full path to the executable to be      //
//                associated with the file Icon                       //
//                                                                    //
////////////////////////////////////////////////////////////////////////

 

//구현 부분
2. 선언한 함수의 내용을 구현한다.

  function MakeAssociation(szApp, szExtension, szIcon)
  BOOL      bResult;
  NUMBER    nResult;
  STRING szOpen;

  begin

    RegDBSetDefaultRoot ( HKEY_CLASSES_ROOT );

    bResult = RegDBKeyExist(szExtension);
    if (bResult = TRUE) then
      nResult = AskYesNo ("Warning the extension " + szExtension + " is already registered. Overwrite?", YES);
      if (nResult = NO) then
         return -1;
      endif;
    endif;

    LongPathToShortPath (szApp);
    szApp = szApp + " \"%1\"";
    szOpen = "open" + " \"%1\"";
    RegDBCreateKeyEx (szExtension, "");
   
    RegDBCreateKeyEx (szExtension + "\\DefaultIcon", "");
    RegDBSetKeyValueEx (szExtension + "\\DefaultIcon","", REGDB_STRING, szIcon, -1);

    RegDBCreateKeyEx (szExtension + "\\shell", "");
    RegDBCreateKeyEx (szExtension + "\\shell\\open", "");
    RegDBCreateKeyEx (szExtension + "\\shell\\open\\command", "");
    RegDBSetKeyValueEx (szExtension + "\\shell\\open\\command", "", REGDB_STRING, szApp, -1);
   
    //RegDBCreateKeyEx (szExtension + "\\shell\\open\\ddeexec", "");//추가
    //RegDBSetKeyValueEx (szExtension + "\\shell\\open\\ddeexec", "", REGDB_STRING, szOpen, -1);//추가
   
    return 0;
  end;

 

//호출부분
3. 위의 함수를 구현하고, 함수를 호출하고자 하는 부분에 다음 부분을 입력한다.

STRING szExtension, szAppPath, szIcon;//변수 선언 부분

szExtension = ".txt"; //연결할 사용자확장자
szAppPath = INSTALLDIR^"Program.exe";//실행파일 경로 및 실행파일 명
szIcon = INSTALLDIR^"Program.exe,0"; //아이콘 변환
MakeAssociation(szAppPath, szExtension, szIcon);//함수 호출

이렇게 입력하고 설치파일을 만들고 PC에 설치하면 레지스트리에 해당 값들이 입력되며 사용자 확장자를 클릭하면 해당 프로그램이 실행된다.

Posted by 쿵캉켕