Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #define MyAppName "InstallubuntuWSL"
- #define MyAppVersion "1.2"
- #define MyAppPublisher "Dbs"
- #define MyAppURL "https://dbs.fr"
- #define MyAppExeName "InstallUbuntuWSL"
- #define MyAppInstallPath "\\ad\NAS\WSL_Ubuntu\Installer"
- #define MyAppDefaultDir "C:\Users\{code:GetLoggedUsername}\UbuntuWSL"
- [Setup]
- AppId={{E23B0E7F-9F5F-4A6F-AC70-3C4316397126}
- 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={#MyAppInstallPath}\distrib\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: "{userstartmenu}\Ubuntu"; Filename: "{tmp}\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 (FileExists('C:\Windows\System32\bash.exe')) then
- begin
- NeedRestartFlag := False
- 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)
- end
- else
- begin
- NeedRestartFlag := True
- Exec(ExpandConstant('dism.exe'), '/quiet /NoRestart /online /Enable-Feature /featurename:Microsoft-Windows-Subsystem-Linux', '', SW_HIDE, ewNoWait, ResultCode);
- Sleep(850)
- end;
- end;
- if CurStep = ssPostInstall then
- begin
- FileCopy(ExpandConstant('{app}\ubuntu1804.exe'), ExpandConstant('{userstartmenu}\UbuntuWSL'), False);
- 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;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement