Correct way to execute Command line Commands when calling Exec...

1,442 views
Skip to first unread message

Dominique Louis

unread,
Apr 6, 2021, 7:16:29 AM4/6/21
to innosetup
Hi all,
  Just wondering if any has an example of how to call a multi-line command using the Exec?

I essentially have several steps that are each Exec command eg, if I was doing this from a batch file it would be 
Step 1.  
REG ADD "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\AppModelUnlock" /t REG_DWORD /f /v "AllowDevelopmentWithoutDevLicense" /d "1"

Step 2.
FOR /F "delims=" %%i IN ('DISM /Online /Get-CapabilityInfo /CapabilityName:Tools.DeveloperMode.Core~~~~0.0.1.0') DO (
if "%%i"=="State : Not Present" (
DISM /Online /Add-Capability /CapabilityName:Tools.DeveloperMode.Core~~~~0.0.1.0
)
)

What is the correct way for this to work on 64bit Windows 10 installations. 

I'm basically trying to get Inno Setup to sideload UWP apps.

If there is already and example of having custom steps in an example, please let me know.

Thanks,


Dominique.

Eivind Bakkestuen

unread,
Apr 6, 2021, 8:09:02 AM4/6/21
to inno...@googlegroups.com
Write to a .bat file, then exec the newly written batch file?

--
You received this message because you are subscribed to the Google Groups "innosetup" group.
To unsubscribe from this group and stop receiving emails from it, send an email to innosetup+...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/innosetup/d793a235-704b-4881-8356-09bcedb421d0n%40googlegroups.com.

Dominique Louis

unread,
Apr 6, 2021, 9:01:17 AM4/6/21
to inno...@googlegroups.com
Hi Eivind,
  Thanks for the reply. 
I have a batch file solution which works, but doesn't seem ideal in 2021 :). Downloaded batch files are flagged as suspicious by Windows 10 so customers (from itch.io for example) are reluctant to download and click them. But don't seem as reluctant with .exe files (Yes ironic). So that is why I was hoping to move that logic into an inno setup.
I suppose if the main batch file is inside the setup, then that would get around the flagged download part, or will Windows complain, once it's extracted to the file system?



D.


You received this message because you are subscribed to a topic in the Google Groups "innosetup" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/innosetup/66V4VuyjQgU/unsubscribe.
To unsubscribe from this group and all its topics, send an email to innosetup+...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/innosetup/CAH4EOO4P46bvYg7NWGKO%2B5s9hhV7WKmr8QjCJ6GXJBPpSzfxYg%40mail.gmail.com.


--
Regards,


D.

Eivind Bakkestuen

unread,
Apr 7, 2021, 1:03:59 AM4/7/21
to inno...@googlegroups.com
I'm not aware of anything very suspicious about batch files as compared to other files (of course almost any file can contain things that may be detrimental to the target system).

In my installers, I create batch files on the fly and execute them. Not doing anything malicious, and have not heard of that being flagged yet.

CHB Wien

unread,
Apr 7, 2021, 7:26:42 AM4/7/21
to innosetup
The question is: Do you just want to replace a batch file with Inno? It sounds like a big thing for a single batch file, but it depends on what you really want to achieve. 
E.g., many tasks can be implemented very fast using PowerShell and to make the handling easier you can transform the PowerShell into an exe (e.g. ps2exe or Powershell Studio). So the powershell would be a direct equivalent to batch files. Some examples I have created can be found e.g. here (sapien: CleanTeams, ps2exe: ChangeWSUS)
If you are creating installers, use Inno, because this will do many things for you in the right way.

So it depends....

Dominique Louis

unread,
Apr 7, 2021, 8:19:13 AM4/7/21
to inno...@googlegroups.com
Hi CHB Wien, 
What I'm basically trying to do is to automate the installation of UWP apps. For example I offer my game on itch.io. So for customers to install this UWP app on their Windows 10 machine, I believe they need to side load the app. Now some customers aren't technical enough to do that. So my batch files enables Side loading, downloads the required files to allow the game to install, registers the game correctly, creates a desktop shortcut and asked them if they want to launch it. I could stick to my batch files, because I've got that working, but apart from the Windows defender flagging downloaded batch files, I don't think a command line UI gives the best installer experience. Launching a PowerShell would of course do the same thing, but again I'm not sure that is a nice UX. Hence why I'm looking at switching to Inno Setup or similar.  

I hope the above makes sense.


D.



--
Regards,


D.

Bill Stewart

unread,
Apr 7, 2021, 10:25:57 AM4/7/21
to innosetup
On Tuesday, April 6, 2021 at 5:16:29 AM UTC-6 savages...@gmail.com wrote:

  Just wondering if any has an example of how to call a multi-line command using the Exec?

I essentially have several steps that are each Exec command eg, if I was doing this from a batch file it would be 
Step 1.  
REG ADD "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\AppModelUnlock" /t REG_DWORD /f /v "AllowDevelopmentWithoutDevLicense" /d "1"

Step 2.
FOR /F "delims=" %%i IN ('DISM /Online /Get-CapabilityInfo /CapabilityName:Tools.DeveloperMode.Core~~~~0.0.1.0') DO (
if "%%i"=="State : Not Present" (
DISM /Online /Add-Capability /CapabilityName:Tools.DeveloperMode.Core~~~~0.0.1.0
)
)

From an API perspective, there's really no such thing as a multi-line command.

My advice, rather than using a batch file, would be to implement the registry value in your [Registry] section and the Windows capability part in the [Code] section.

For the registry part:

[Registry]
Root: HKLM; Subkey: "SOFTWARE\Microsoft\Windows\CurrentVersion\AppModelUnlock"; ValueType: dword; ValueName: "AllowDevelopmentWithoutDevLicense"; ValueData: 1

For the Windows capability part, I would recommend using Get-WindowsCapability/Add-WindowsCapability in PowerShell.

You probably want to run the PowerShell code during the ssInstall event of the CurStepChanged event procedure; e.g.:

procedure CurStepChanged(CurStep: TSetupSetup);
var
  ResultCode: integer;
begin
  if CurStep = ssInstall then
    begin
      Exec(ExpandConstant('{sys}\WindowsPowerShell\v1.0\powershell.exe'), '-Command "if ( (Get-WindowsCapability -Online -Name ''Tools.DeveloperMode.Core~~~~0.0.1.0'').State -eq ''NotPresent'' ) { Add-WindowsCapability -Online -Name ''Tools.DeveloperMode.Core~~~~0.0.1.0'' }"', '', 0, true, ResultCode);
    end;
end;

[See https://jrsoftware.org/ishelp/index.php?topic=isxfunc_exec for the detail on the parameters for the Exec() function.]

Bill

Bill Stewart

unread,
Apr 7, 2021, 10:36:16 AM4/7/21
to innosetup
On Wednesday, April 7, 2021 at 8:25:57 AM UTC-6 Bill Stewart wrote:

procedure CurStepChanged(CurStep: TSetupSetup);
var
  ResultCode: integer;
begin
  if CurStep = ssInstall then
    begin
      Exec(ExpandConstant('{sys}\WindowsPowerShell\v1.0\powershell.exe'), '-Command "if ( (Get-WindowsCapability -Online -Name ''Tools.DeveloperMode.Core~~~~0.0.1.0'').State -eq ''NotPresent'' ) { Add-WindowsCapability -Online -Name ''Tools.DeveloperMode.Core~~~~0.0.1.0'' }"', '', 0, true, ResultCode);
    end;
end;

Correction: The second-to-last (5th) parameter of the Exec call above should be ewWaitUntilTerminated rather than true.

(Note that I have not tested the above; it should be close, though)

Bill
Reply all
Reply to author
Forward
0 new messages