Combreal icon

InstallWSLUbuntu.iss

Combreal | PRO | 01/02/24 02:10:46 PM UTC (Edited) | 0 ⭐ | 8204 👁️ | Never ⏰ | []
Pascal |

4.09 KB

|

None

|

0 👍

/

0 👎

#define MyAppName "InstallubuntuWSL"
#define MyAppVersion "1.2"
#define MyAppPublisher "DBS"
#define MyAppURL "https://dbs.fr"
#define MyAppExeName "InstallUbuntuWSL"
#define MyAppInstallPath "\\NAS\WSL_Ubuntu\Installer"
#define MyAppDefaultDir "C:\Users\{code:GetLoggedUsername}\UbuntuWSL"
 
[Setup]
AppId={{PPPPPPP-PPPP-PPPP-PPPP-PPPPPPP}
AppName={#MyAppName}
AppVersion={#MyAppVersion}
VersionInfoVersion=1.1.6
AppPublisher={#MyAppPublisher}                                                                                                            
AppPublisherURL={#MyAppURL}
AppSupportURL={#MyAppURL}
AppUpdatesURL={#MyAppURL}
UsePreviousAppDir=no
DefaultDirName={#MyAppDefaultDir}
DefaultGroupName={#MyAppName}
AllowNoIcons=yes
LicenseFile={#MyAppInstallPath}\distrib\gpl 
OutputDir=C:\temp
OutputBaseFilename=Install_WSL_Ubuntu_Setup
SetupIconFile={#MyAppInstallPath}\distrib\setup.ico
Compression=lzma
SolidCompression=yes
WizardSmallImageFile={#MyAppInstallPath}\distrib\dbs.bmp
AlwaysRestart=no
DisableProgramGroupPage=yes
DisableDirPage=yes
ShowLanguageDialog=auto
UninstallDisplayIcon={#MyAppDefaultDir}\install\ubuntu.ico
 
[Languages]
Name: "en"; MessagesFile: "compiler:Default.isl"
Name: "fr"; MessagesFile: "compiler:Languages\French.isl"
 
[Files]
Source: "{#MyAppInstallPath}\distrib\*"; DestDir: {tmp}
Source: "{#MyAppInstallPath}\package\*"; DestDir: "{app}\install"; Flags: ignoreversion recursesubdirs createallsubdirs
Source: "{#MyAppInstallPath}\package\installUbuntu.bat"; DestDir: "C:\Users\{code:GetLoggedUsername}\AppData\Roaming\Microsoft\Windows\Start Menu\Programs\Startup"; Flags: ignoreversion recursesubdirs createallsubdirs
 
[Icons]
Name: "C:\Users\{code:GetLoggedUsername}\AppData\Roaming\Microsoft\Windows\Start Menu\Ubuntu"; Filename: "{app}\install\ubuntu1804.exe"
 
[Run]
Filename: "{tmp}\7za.exe"; Parameters: "x {tmp}\ubuntu.zip -o{app}"; Flags: runhidden; StatusMsg: Extracting Ubuntu
 
[UninstallDelete]
Type: filesandordirs; Name: "C:\Users\{code:GetLoggedUsername}\UbuntuWSL"
Type: filesandordirs; Name: "C:\Users\{code:GetLoggedUsername}\Desktop\ubuntu1804.exe"
 
[Code]
var
  NeedRestartFlag: Boolean;
 
function GetLoggedUsername(Param: string): string;
var
  TmpFileName, ExecStdout: AnsiString;
  ResultCode: integer;
begin
    TmpFileName := ExpandConstant('{tmp}\loggedusername.txt');
    ExtractTemporaryFile('getLoggedUsername.bat');
    ExtractTemporaryFile('query.exe');
    Exec(ExpandConstant('{tmp}\getLoggedUsername.bat'), ExpandConstant('{tmp}'), '', SW_HIDE, ewWaitUntilTerminated, ResultCode);
    if LoadStringFromFile(TmpFileName, ExecStdout) then 
    begin
    SetLength(ExecStdout,LENGTH(ExecStdout)-3)
    Result := ExecStdout;
    end
    else
    begin
    Result := ''
    end;
    DeleteFile(TmpFileName)
end;
 
procedure CurStepChanged(CurStep: TSetupStep);
var
  ResultCode: Integer;
 begin
  if CurStep = ssInstall then
  begin
   EnableFsRedirection(False);
   if not (FileExists('C:\Windows\System32\bash.exe')) then
   begin
      NeedRestartFlag := True
      Exec(ExpandConstant('dism.exe'), '/quiet /NoRestart /online /Enable-Feature /featurename:Microsoft-Windows-Subsystem-Linux', '', SW_HIDE, ewNoWait, ResultCode);
      Sleep(850)
   end
   else
   begin
      NeedRestartFlag := False
    end;
  end;
  if CurStep = ssPostInstall then
  begin
   EnableFsRedirection(False);
   if (FileExists('C:\Windows\System32\bash.exe')) then
   begin
     Exec('schtasks.exe', ExpandConstant('/create /sc ONLOGON /tn InstallUbuntuWSL /F /ru AD\{code:GetLoggedUsername} /tr {app}\install\installUbuntu.bat'), '', SW_HIDE, ewWaitUntilTerminated, ResultCode)
     Exec('schtasks.exe', '/run /tn InstallUbuntuWSL', '', SW_SHOW, ewWaitUntilTerminated, ResultCode)
     Exec('schtasks.exe', '/delete /tn InstallUbuntuWSL /f', '', SW_SHOW, ewWaitUntilTerminated, ResultCode)
   end
  end;
 end;
 
function NeedRestart(): Boolean;
begin
  if NeedRestartFlag then
  begin
    Log('Need restart');
    Result := True;
  end
    else
  begin
    Log('Do not need restart');
    Result := False;
  end;
end;

Comments

  •  icon
    01/01/70 12:00:00 AM UTC
    Plain Text |

    0 B

    |

    👍

    /

    👎

    
        
  •  icon
    01/01/70 12:00:00 AM UTC
    Plain Text |

    0 B

    |

    👍

    /

    👎

    
        
  •  icon
    01/01/70 12:00:00 AM UTC
    Plain Text |

    0 B

    |

    👍

    /

    👎