InnoSetup [Code] 부분에 이대로 추가하면 된다
설치할때 추가하고 삭제할때 제거된다
검색해서 나오는 자료들은 죄다 예전 소스들이라 힘들었음 ㄱ-
[Code]
const
NET_FW_SCOPE_ALL = 0;
NET_FW_IP_VERSION_ANY = 2;
NET_FW_ACTION_ALLOW = 1;
procedure SetFirewallExceptionXP(AppName,FileName:string);
var
FirewallObject: Variant;
FirewallManager: Variant;
FirewallProfile: Variant;
begin
try
FirewallObject := CreateOleObject('HNetCfg.FwAuthorizedApplication');
FirewallObject.ProcessImageFileName := FileName;
FirewallObject.Name := AppName;
FirewallObject.Scope := NET_FW_SCOPE_ALL;
FirewallObject.IpVersion := NET_FW_IP_VERSION_ANY;
FirewallObject.Enabled := True;
FirewallManager := CreateOleObject('HNetCfg.FwMgr');
FirewallProfile := FirewallManager.LocalPolicy.CurrentProfile;
FirewallProfile.AuthorizedApplications.Add(FirewallObject);
except
end;
end;
procedure SetFirewallExceptionVista(AppName,FileName:string);
var
firewallRule: Variant;
firewallPolicy: Variant;
begin
try
firewallRule := CreateOleObject('HNetCfg.FWRule');
firewallRule.Action := NET_FW_ACTION_ALLOW;
firewallRule.Description := AppName;
firewallRule.ApplicationName := FileName;
firewallRule.Enabled := True;
firewallRule.InterfaceTypes := 'All';
firewallRule.Name := AppName;
firewallPolicy := CreateOleObject('HNetCfg.FwPolicy2');
firewallPolicy.Rules.Add(firewallRule);
except
end;
end;
procedure SetFirewallException(AppName,FileName:string);
var
WindVer: TWindowsVersion;
begin
try
GetWindowsVersionEx(WindVer);
if WindVer.NTPlatform and (WindVer.Major >= 6) then
SetFirewallExceptionVista(AppName,FileName)
else
SetFirewallExceptionXP(AppName,FileName);
except
end;
end;
procedure RemoveFirewallException(AppName,FileName:string);
var
FirewallManager: Variant;
FirewallProfile: Variant;
WindVer: TWindowsVersion;
firewallPolicy: Variant;
begin
try
GetWindowsVersionEx(WindVer);
if WindVer.NTPlatform and (WindVer.Major >= 6) then
begin
firewallPolicy := CreateOleObject('HNetCfg.FwPolicy2');
firewallPolicy.Rules.Remove(AppName);
end
else
begin
FirewallManager := CreateOleObject('HNetCfg.FwMgr');
FirewallProfile := FirewallManager.LocalPolicy.CurrentProfile;
FireWallProfile.AuthorizedApplications.Remove(FileName);
end
except
end;
end;
procedure CurStepChanged(CurStep: TSetupStep);
begin
if CurStep=ssPostInstall then
begin
SetFirewallException('AppName넣기', ExpandConstant('{app}')+'\실행파일명.exe');
end;
end;
procedure CurUninstallStepChanged(CurUninstallStep: TUninstallStep);
begin
if CurUninstallStep=usPostUninstall then
begin
RemoveFirewallException('AppName넣기', ExpandConstant('{app}')+'\실행파일명.exe');
end;
end;
'삽질 > Delphi' 카테고리의 다른 글
[Delphi] InnoSetup : 설치 전, 설치 후 함수 호출하기 (0) | 2013.08.07 |
---|---|
[Delphi] InnoSetup : event 함수들 (0) | 2013.08.07 |
[Delphi] InnoSetup : 설치/제거 할 때 프로그램 종료하기 (0) | 2013.08.07 |
[Delphi] 윈도우 높은 권한에서 낮은 권한 메시지 받기 (0) | 2013.08.02 |
[Delphi] 작업표시줄 시계부분 위치찾기 (0) | 2013.07.30 |
댓글