How to create a openvpn installer with all certificates and setting already built in

1 – Download and install Inno Setup: https://jrsoftware.org/isinfo.php

2 – Create a Folder on your PC for the input and output dates:

Create this folder: C:\MyOpenVPNInstaller\Input

├── openvpn.msi (OpenVPN executable - download the version needed and place here withi this name)
├── config
│   └── myvpn.ovpn
├── certs (Optional - if needed for certificates)
└── other files (Optional - if needed for certificates)

create this folder: C:\MyOpenVPNInstaller\Output

3 – Colar o script no Inno Setup

; Script generated by the Inno Setup Script Wizard.
; SEE THE DOCUMENTATION FOR DETAILS ON CREATING INNO SETUP SCRIPT FILES!

#define MyAppName "OpenVPN"
#define MyAppVersion "2.0"
#define MyAppPublisher "Company"
#define MyAppURL "https://www.company.com.br/"
#define MyAppExeName "company.exe"
#define MyAppAssocName MyAppName + " File"

[Setup]
; NOTE: The value of AppId uniquely identifies this application. Do not use the same AppId value in installers for other applications.
; (To generate a new GUID, click Tools | Generate GUID inside the IDE.)
AppId={{5F717633-6F6B-4164-8A77-023E862DED16}
AppName={#MyAppName}
AppVersion={#MyAppVersion}
;AppVerName={#MyAppName} {#MyAppVersion}
AppPublisher={#MyAppPublisher}
AppPublisherURL={#MyAppURL}
AppSupportURL={#MyAppURL}
AppUpdatesURL={#MyAppURL}
DefaultDirName={autopf}\{#MyAppName}
DisableDirPage=yes
; "ArchitecturesAllowed=x64compatible" specifies that Setup cannot run
; on anything but x64 and Windows 11 on Arm.
ArchitecturesAllowed=x64compatible
; "ArchitecturesInstallIn64BitMode=x64compatible" requests that the
; install be done in "64-bit mode" on x64 or Windows 11 on Arm,
; meaning it should use the native 64-bit Program Files directory and
; the 64-bit view of the registry.
ArchitecturesInstallIn64BitMode=x64compatible
ChangesAssociations=yes
DisableProgramGroupPage=yes
; Uncomment the following line to run in non administrative install mode (install for current user only.)
;PrivilegesRequired=lowest
OutputDir=C:\MyOpenVPNInstaller\Output
OutputBaseFilename=OpenVPNInstaller
Compression=lzma
SolidCompression=yes
WizardStyle=modern
Uninstallable=yes
PrivilegesRequired=admin
AllowNoIcons=yes

[Languages]
Name: "english"; MessagesFile: "compiler:Default.isl"

[Tasks]
Name: "desktopicon"; Description: "{cm:CreateDesktopIcon}"; GroupDescription: "{cm:AdditionalIcons}"; Flags: unchecked

[Files]
; Include the OpenVPN MSI installer
Source: "C:\MyOpenVPNInstaller\Input\openvpn.msi"; DestDir: "{tmp}"; Flags: deleteafterinstall
; Include your custom .ovpn file
Source: "C:\MyOpenVPNInstaller\Input\config\*"; DestDir: "{app}\config"; Flags: ignoreversion

[Run]
; Run the OpenVPN MSI installer in 64-bit mode
Filename: "msiexec.exe"; Parameters: "/i {tmp}\openvpn.msi /quiet"; WorkingDir: "{tmp}"; Flags: waituntilterminated

[Icons]
; Create shortcuts to OpenVPN GUI (without specifying run-as-admin flag here)
Name: "{group}\OpenVPN GUI"; Filename: "{pf}\OpenVPN\bin\openvpn-gui.exe"; WorkingDir: "{pf}\OpenVPN\bin"; IconFilename: "{pf}\OpenVPN\bin\openvpn-gui.exe"; IconIndex: 0
Name: "{commondesktop}\OpenVPN GUI"; Filename: "{pf}\OpenVPN\bin\openvpn-gui.exe"; WorkingDir: "{pf}\OpenVPN\bin"; IconFilename: "{pf}\OpenVPN\bin\openvpn-gui.exe"; IconIndex: 0

[UninstallDelete]
; Remove the custom .ovpn file and other custom files during uninstall
Type: files; Name: "{app}\config"

[UninstallRun]
; Uninstall OpenVPN using the MSI uninstaller
Filename: "msiexec.exe"; Parameters: "/x {tmp}\openvpn.msi /quiet"; Flags: waituntilterminated

[Code]
procedure CurStepChanged(CurStep: TSetupStep);
begin
if CurStep = ssPostInstall then
begin
// This is where you might need to add custom logic to modify shortcut properties.
// For example, you could use a tool like 'NirCmd' or similar to modify the shortcut.
// Unfortunately, Inno Setup does not have built-in support for setting run-as-admin properties directly.
end;
end;

4 – Compitale with CTRL + F9 and check for errors.

5 – Install the installer created: C:\MyOpenVPNInstaller\Output\OpenVPNInstaller.exe

==================================================================

Updated Script

; Script generated by the Inno Setup Script Wizard.
; SEE THE DOCUMENTATION FOR DETAILS ON CREATING INNO SETUP SCRIPT FILES!

#define MyAppName "OpenVPN"
#define MyAppVersion "2.0"
#define MyAppPublisher "ESB"
#define MyAppURL ""
#define MyAppExeName "ESB Office VPN.exe"
#define MyAppAssocName MyAppName + " File"

[Setup]
; NOTE: The value of AppId uniquely identifies this application. Do not use the same AppId value in installers for other applications.
; (To generate a new GUID, click Tools | Generate GUID inside the IDE.)
AppId={{5F717633-6F6B-4164-8A77-023E862DED16}
AppName={#MyAppName}
AppVersion={#MyAppVersion}
;AppVerName={#MyAppName} {#MyAppVersion}
AppPublisher={#MyAppPublisher}
AppPublisherURL={#MyAppURL}
AppSupportURL={#MyAppURL}
AppUpdatesURL={#MyAppURL}
DefaultDirName={autopf}\{#MyAppName}
DisableDirPage=yes
; "ArchitecturesAllowed=x64compatible" specifies that Setup cannot run
; on anything but x64 and Windows 11 on Arm.
ArchitecturesAllowed=x64compatible
; "ArchitecturesInstallIn64BitMode=x64compatible" requests that the
; install be done in "64-bit mode" on x64 or Windows 11 on Arm,
; meaning it should use the native 64-bit Program Files directory and
; the 64-bit view of the registry.
ArchitecturesInstallIn64BitMode=x64compatible
ChangesAssociations=yes
DisableProgramGroupPage=yes
; Uncomment the following line to run in non administrative install mode (install for current user only.)
;PrivilegesRequired=lowest
OutputDir=C:\Users\Owner\Desktop\sedim\Output
OutputBaseFilename=OpenVPNInstaller-ESB
Compression=lzma
SolidCompression=yes
WizardStyle=modern
Uninstallable=yes
PrivilegesRequired=admin
AllowNoIcons=yes

[Languages]
Name: "english"; MessagesFile: "compiler:Default.isl"

[Tasks]
Name: "desktopicon"; Description: "{cm:CreateDesktopIcon}"; GroupDescription: "{cm:AdditionalIcons}"; Flags: unchecked

[Files]
; Include the OpenVPN MSI installer
Source: "C:\Users\Owner\Desktop\sedim\Input\openvpn.msi"; DestDir: "{tmp}"; Flags: deleteafterinstall
; Include your custom .ovpn file
Source: "C:\Users\Owner\Desktop\sedim\Input\config\*"; DestDir: "{app}\config"; Flags: ignoreversion

[Run]
; Run the OpenVPN MSI installer in 64-bit mode
Filename: "msiexec.exe"; Parameters: "/i {tmp}\openvpn.msi /quiet"; WorkingDir: "{tmp}"; Flags: waituntilterminated

[Icons]
; Create shortcuts to OpenVPN GUI (without specifying run-as-admin flag here)
Name: "{group}\OpenVPN GUI"; Filename: "{pf}\OpenVPN\bin\openvpn-gui.exe"; WorkingDir: "{pf}\OpenVPN\bin"; IconFilename: "{pf}\OpenVPN\bin\openvpn-gui.exe"; IconIndex: 0
Name: "{commondesktop}\OpenVPN GUI"; Filename: "{pf}\OpenVPN\bin\openvpn-gui.exe"; WorkingDir: "{pf}\OpenVPN\bin"; IconFilename: "{pf}\OpenVPN\bin\openvpn-gui.exe"; IconIndex: 0

[UninstallDelete]
; Remove the custom .ovpn file and other custom files during uninstall
Type: files; Name: "{app}\config"

[UninstallRun]
; Uninstall OpenVPN using the MSI uninstaller
Filename: "msiexec.exe"; Parameters: "/x {tmp}\openvpn.msi /quiet"; Flags: waituntilterminated

[Code]
procedure CurStepChanged(CurStep: TSetupStep);
begin
if CurStep = ssPostInstall then
begin
// This is where you might need to add custom logic to modify shortcut properties.
// For example, you could use a tool like 'NirCmd' or similar to modify the shortcut.
// Unfortunately, Inno Setup does not have built-in support for setting run-as-admin properties directly.
end;
end;

Deixe um comentário