Advertisement
Combreal

InstallWSLUbuntu.iss

Jun 2nd, 2020 (edited)
714
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Pascal 4.09 KB | None | 0 0
  1. #define MyAppName "InstallubuntuWSL"
  2. #define MyAppVersion "1.2"
  3. #define MyAppPublisher "DBS"
  4. #define MyAppURL "https://dbs.fr"
  5. #define MyAppExeName "InstallUbuntuWSL"
  6. #define MyAppInstallPath "\\NAS\WSL_Ubuntu\Installer"
  7. #define MyAppDefaultDir "C:\Users\{code:GetLoggedUsername}\UbuntuWSL"
  8.  
  9. [Setup]
  10. AppId={{PPPPPPP-PPPP-PPPP-PPPP-PPPPPPP}
  11. AppName={#MyAppName}
  12. AppVersion={#MyAppVersion}
  13. VersionInfoVersion=1.1.6
  14. AppPublisher={#MyAppPublisher}                                                                                                            
  15. AppPublisherURL={#MyAppURL}
  16. AppSupportURL={#MyAppURL}
  17. AppUpdatesURL={#MyAppURL}
  18. UsePreviousAppDir=no
  19. DefaultDirName={#MyAppDefaultDir}
  20. DefaultGroupName={#MyAppName}
  21. AllowNoIcons=yes
  22. LicenseFile={#MyAppInstallPath}\distrib\gpl
  23. OutputDir=C:\temp
  24. OutputBaseFilename=Install_WSL_Ubuntu_Setup
  25. SetupIconFile={#MyAppInstallPath}\distrib\setup.ico
  26. Compression=lzma
  27. SolidCompression=yes
  28. WizardSmallImageFile={#MyAppInstallPath}\distrib\dbs.bmp
  29. AlwaysRestart=no
  30. DisableProgramGroupPage=yes
  31. DisableDirPage=yes
  32. ShowLanguageDialog=auto
  33. UninstallDisplayIcon={#MyAppDefaultDir}\install\ubuntu.ico
  34.  
  35. [Languages]
  36. Name: "en"; MessagesFile: "compiler:Default.isl"
  37. Name: "fr"; MessagesFile: "compiler:Languages\French.isl"
  38.  
  39. [Files]
  40. Source: "{#MyAppInstallPath}\distrib\*"; DestDir: {tmp}
  41. Source: "{#MyAppInstallPath}\package\*"; DestDir: "{app}\install"; Flags: ignoreversion recursesubdirs createallsubdirs
  42. Source: "{#MyAppInstallPath}\package\installUbuntu.bat"; DestDir: "C:\Users\{code:GetLoggedUsername}\AppData\Roaming\Microsoft\Windows\Start Menu\Programs\Startup"; Flags: ignoreversion recursesubdirs createallsubdirs
  43.  
  44. [Icons]
  45. Name: "C:\Users\{code:GetLoggedUsername}\AppData\Roaming\Microsoft\Windows\Start Menu\Ubuntu"; Filename: "{app}\install\ubuntu1804.exe"
  46.  
  47. [Run]
  48. Filename: "{tmp}\7za.exe"; Parameters: "x {tmp}\ubuntu.zip -o{app}"; Flags: runhidden; StatusMsg: Extracting Ubuntu
  49.  
  50. [UninstallDelete]
  51. Type: filesandordirs; Name: "C:\Users\{code:GetLoggedUsername}\UbuntuWSL"
  52. Type: filesandordirs; Name: "C:\Users\{code:GetLoggedUsername}\Desktop\ubuntu1804.exe"
  53.  
  54. [Code]
  55. var
  56.   NeedRestartFlag: Boolean;
  57.  
  58. function GetLoggedUsername(Param: string): string;
  59. var
  60.   TmpFileName, ExecStdout: AnsiString;
  61.   ResultCode: integer;
  62. begin
  63.     TmpFileName := ExpandConstant('{tmp}\loggedusername.txt');
  64.     ExtractTemporaryFile('getLoggedUsername.bat');
  65.     ExtractTemporaryFile('query.exe');
  66.     Exec(ExpandConstant('{tmp}\getLoggedUsername.bat'), ExpandConstant('{tmp}'), '', SW_HIDE, ewWaitUntilTerminated, ResultCode);
  67.     if LoadStringFromFile(TmpFileName, ExecStdout) then
  68.     begin
  69.     SetLength(ExecStdout,LENGTH(ExecStdout)-3)
  70.     Result := ExecStdout;
  71.     end
  72.     else
  73.     begin
  74.     Result := ''
  75.     end;
  76.     DeleteFile(TmpFileName)
  77. end;
  78.  
  79. procedure CurStepChanged(CurStep: TSetupStep);
  80. var
  81.   ResultCode: Integer;
  82.  begin
  83.   if CurStep = ssInstall then
  84.   begin
  85.    EnableFsRedirection(False);
  86.    if not (FileExists('C:\Windows\System32\bash.exe')) then
  87.    begin
  88.       NeedRestartFlag := True
  89.       Exec(ExpandConstant('dism.exe'), '/quiet /NoRestart /online /Enable-Feature /featurename:Microsoft-Windows-Subsystem-Linux', '', SW_HIDE, ewNoWait, ResultCode);
  90.       Sleep(850)
  91.    end
  92.    else
  93.    begin
  94.       NeedRestartFlag := False
  95.     end;
  96.   end;
  97.   if CurStep = ssPostInstall then
  98.   begin
  99.    EnableFsRedirection(False);
  100.    if (FileExists('C:\Windows\System32\bash.exe')) then
  101.    begin
  102.      Exec('schtasks.exe', ExpandConstant('/create /sc ONLOGON /tn InstallUbuntuWSL /F /ru AD\{code:GetLoggedUsername} /tr {app}\install\installUbuntu.bat'), '', SW_HIDE, ewWaitUntilTerminated, ResultCode)
  103.      Exec('schtasks.exe', '/run /tn InstallUbuntuWSL', '', SW_SHOW, ewWaitUntilTerminated, ResultCode)
  104.      Exec('schtasks.exe', '/delete /tn InstallUbuntuWSL /f', '', SW_SHOW, ewWaitUntilTerminated, ResultCode)
  105.    end
  106.   end;
  107.  end;
  108.  
  109. function NeedRestart(): Boolean;
  110. begin
  111.   if NeedRestartFlag then
  112.   begin
  113.     Log('Need restart');
  114.     Result := True;
  115.   end
  116.     else
  117.   begin
  118.     Log('Do not need restart');
  119.     Result := False;
  120.   end;
  121. end;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement