본문 바로가기
삽질/Delphi

[Delphi] InnoSetup : 방화벽 추가

by 푸딩s 2013. 8. 7.
728x90
반응형



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;







728x90
반응형

댓글