Share via


사용자 지정 작업의 오류 처리

Windows Installer는 배포 시에 대부분의 오류 처리를 관리하지만, 사용자 지정 작업의 오류로 인해 설치 관리자가 중단될 수 있습니다. 모든 사용자 지정 작업에는 코드가 들어 있으며, 모든 코드에서 오류 처리는 프로세스의 중요한 일부분입니다. 예를 들어, 사용자 지정 작업에 파일을 여는 코드가 포함되었으나 이 파일이 존재하지 않는 경우, 설치를 취소할 수 있도록 Windows Installer에 오류를 보고하는 오류 처리기가 필요합니다.

참고

JScript나 VBScript를 사용하여 작성된 사용자 지정 작업의 경우에는 오류가 Windows Installer에 반환되지 않으므로 설치를 취소할 수 없지만 사용자에게는 오류 대화 상자가 표시됩니다. 설치에 중요한 사용자 지정 작업의 경우에 오류를 Windows Installer에 전달하려면 Visual Basic, Visual C# 또는 Visual C++로 작업을 작성해야 합니다.

오류 포착

사용자 지정 작업에서 발생하는 오류를 처리하려면, 오류를 포착하고 정보를 Windows Installer에 전달하는 코드를 추가해야 합니다. 다음 예제에서는 Visual Basic, Visual C#, Visual C++, JScript 및 VBScript 코드에서 오류를 처리하는 방법을 보여 줍니다.

' Uses System.IO and System.Configuration.Install
Dim Info As New FileInfo("MyFile.txt")
If Not Info.Exists Then
    Throw New InstallException("File does not exist")
End If
// Uses System.IO and System.Configuration.Install
FileInfo Info = new FileInfo("MyFile.txt");
if (Info.Exists == false)
   throw new InstallException("File does not exist");
'VBScript
msiMessageTypeError = &H01000000 
Set fso = CreateObject("Scripting.FileSystemObject")
If Not fso.FileExists("c:\MyFile.txt") Then
   Set record = Session.Installer.CreateRecord(0)
   record.StringData(0) = "File not found."
   Session.Message msiMessageTypeError, record
End If
var msiMessageTypeError = 0x01000000;
var fso = new ActiveXObject("Scripting.FileSystemObject");
if (!fso.FileExists("c:\\MyFile.txt"))
{
   var record = Session.Installer.CreateRecord(0);
   record.StringData(0) = "File not found.";
   Session.Message(msiMessageTypeError, record);
}
#pragma comment(lib, "msi.lib")

#include <windows.h>
#include <msiquery.h>

BOOL APIENTRY DllMain(HINSTANCE hInstance, DWORD fdwREason, LPVOID lpReserved)
{
   return TRUE;
}

extern "C" __declspec(dllexport) __stdcall Install(MSIHANDLE hInstall)
{
   if (GetFileAttributes(TEXT("c:\\MyFile.txt")) == -1)
   {
      PMSIHANDLE hRecord = MsiCreateRecord(0);
      MsiRecordSetString(hRecord, 0, TEXT("File does not exist."));
      MsiProcessMessage(hInstall, INSTALLMESSAGE(INSTALLMESSAGE_ERROR + MB_OK), hRecord);
      return ERROR_INSTALL_USEREXIT;
   }
   
   return ERROR_SUCCESS;
}

참고 항목

기타 리소스

배포 시 사용자 지정 작업 관리