Advertisement
Combreal

dumpInstallUBWSL01.iss

Jun 2nd, 2020 (edited)
718
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Pascal 3.92 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 "\\ad\NAS\WSL_Ubuntu\Installer"
  7. #define MyAppDefaultDir "C:\Users\{code:GetLoggedUsername}\UbuntuWSL"
  8.  
  9. [Setup]
  10. AppId={{E23B0E7F-9F5F-4A6F-AC70-3C4316397126}
  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={#MyAppInstallPath}\distrib\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: "{userstartmenu}\Ubuntu"; Filename: "{tmp}\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 (FileExists('C:\Windows\System32\bash.exe')) then
  87.    begin
  88.      NeedRestartFlag := False
  89.      Exec('schtasks.exe', ExpandConstant('/create /sc ONLOGON /tn InstallUbuntuWSL /F /ru AD\{code:GetLoggedUsername} /tr {app}\install\installUbuntu.bat'), '', SW_HIDE, ewWaitUntilTerminated, ResultCode)
  90.      Exec('schtasks.exe', '/run /tn InstallUbuntuWSL', '', SW_SHOW, ewWaitUntilTerminated, ResultCode)
  91.    end
  92.    else
  93.    begin
  94.       NeedRestartFlag := True
  95.       Exec(ExpandConstant('dism.exe'), '/quiet /NoRestart /online /Enable-Feature /featurename:Microsoft-Windows-Subsystem-Linux', '', SW_HIDE, ewNoWait, ResultCode);
  96.       Sleep(850)
  97.     end;
  98.   end;
  99.   if CurStep = ssPostInstall then
  100.   begin
  101.     FileCopy(ExpandConstant('{app}\ubuntu1804.exe'), ExpandConstant('{userstartmenu}\UbuntuWSL'), False);
  102.   end;
  103.  end;
  104.  
  105. function NeedRestart(): Boolean;
  106. begin
  107.   if NeedRestartFlag then
  108.   begin
  109.     Log('Need restart');
  110.     Result := True;
  111.   end
  112.     else
  113.   begin
  114.     Log('Do not need restart');
  115.     Result := False;
  116.   end;
  117. end;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement