Inno Setup : execute command/batch file after install process is complete - windows

Friends, I'm writing a script which does a lot of stuff - install my application + other opensource software, set up s/w as service, execute batch files to do some stuff etc.
I set some environment variables at the start. They of course do not take effect till the Inno script finishes execution (i.e the installation finishes).
The environment variables are needed to install a service.
The commands to install, configure and start the service are in a batch file which I need to execute after installation is complete. I need to execute this batch file just once.
How do I execute this batch file after installation is complete, using Inno? It can be immediately after user finishes the install process or run once at system restart. Is it achievable through Inno script?
Or is there a way for my environment variables to take effect so that my batch file can run ?
I know there are installation programs that do part of installation after user has finished install process and system has restarted. Does Inno support that kind of functionality?
I'm not sure if CurStepChanged + ssPostInstall method will work here as it will essentially be the same environment that Inno began with and my variables are not yet in effect.
If this cannot be achieved through Inno script, I will place the batch file at system startup - in that case I will need to check if the service is already installed/running and take appropriate action. But that would be crude.
Please help with any pointers/suggestions.
Thanks.

To schedule a batch file to be run on the next Windows start/logon, add a value to HKCU\Software\Microsoft\Windows\CurrentVersion\RunOnce key:
[Registry]
Root: HKCU; Subkey: "Software\Microsoft\Windows\CurrentVersion\RunOnce"; \
ValueType: string; ValueName: "MyProg"; ValueData: """{app}\MyBatch.bat"""
A value in RunOnce key is automatically deleted by Windows, when the program/batch is run.
Read about Run and RunOnce Registry Keys:
By default, the value of a RunOnce key is deleted before the command line is run. You can prefix a RunOnce value name with an exclamation point (!) to defer deletion of the value until after the command runs. Without the exclamation point prefix, if the RunOnce operation fails the associated program will not be asked to run the next time you start the computer.
Execution order:
If more than one program is registered under any particular key, the order in which those programs run is indeterminate.
Actually the programs run in parallel. Some of the entries can easily be an application that runs until the end of the Windows session. So Windows cannot wait for the program to finish before starting another.
If you need to run the batch files in a particular order, create just one entry pointing to a master batch file that runs the other batch files in the order you need.

Related

Can UiPath process be converted into binary executable?

I have a process in UiPath to automate PyCharm, a really simple one like just running a Python script and copying the run message into a text file. Now I want to convert it into a binary file to be executed on a windows machine.
I came to know that UiPath did have an option for exporting projects into executable files but sadly it was also removed.
I also reviewed the orchestrator for UiPath but that does seem meaningful to me. I didn't understand why a company would remove such a crucial feature (conversion to executable) and provide a messy solution like this. May be I'm missing something.
My question is....
Is there any workaround, any third party trick that can convert an UiPath project into windows executable file.
UiPath does not want users to be able to run executables directly. They are forcing users to use Orchestrator. So they always have the full control about the users and their licensing model. If they would still offer the executable way, someone could easily create a Task with UiPath and send this to any other PC without using a UiPath account. So this is mainly the reason they stopped offering this method. But you still have some other options to run your process so don't worry.
Those ways are:
Use Orchestrator. Run process from your Orchestrator dashboard (via Jobs manually or time triggered or even another starting trigger).
Use Orchestrator and use UiPath Robot (comes already with the UiPath installation). Now you can simply start it from tray icon.
Use UiPath Studio and start process from here.
Create a batch file that runs the start command script for your process. This line UiRobot.exe_Path /file:"Main.xaml" will run your process.
Create a Visual Studio application (exe) that runs the batch file from #4.
Use REST API to run the process.
As you can see you have several options but unfortunately the exe workaround is just a wrapper for the batch file.
I would recommend you to use Orchestrator, as it gives you so many possibilities and control on your processes and a good logging.
The simplest way to do this would be to call the UiPath Robot Command Line Interface within a batch file. I suggest that you package the process first and then refer to that package in the batch file using the UiPath.exe execute command with the --process {Package_ID} argument. You can add UiPath.exe to your PATH environment variable so you don't need to use an absolute path to the exe in your batch file. The batch file will be able to run on your Windows VM just like an executable. Alternatively, you could add a shortcut to UiPath.exe and add the arguments to the target of the shortcut in the properties menu of the shortcut.
I'm using AutoHotkey script for this purpose and thought I'd share my method,
Create a *.ahk script using below code,
#NoEnv ; Recommended for performance and compatibility with future AutoHotkey releases.
; #Warn ; Enable warnings to assist with detecting common errors.
#SingleInstance force
SendMode Input ; Recommended for new scripts due to its superior speed and reliability.
SetWorkingDir %A_ScriptDir% ; Ensures a consistent starting directory.
SetTitleMatchMode,2
DetectHiddenWindows, On
; you don't need to modify below code unless UiPath Studio changes its shortcut name
EnvGet, LocalFolder, LocalAppData ;use windows Env variable to get local appdata folder
UiPath=%LocalFolder%\UiPath
UiPath_ShrtCut=%A_Programs%\UiPath Studio.lnk
UiPath_Prcss:="UiPath.Studio.exe"
UiPath_Asstnt:="UiPath.Assistant.exe"
FileGetShortcut, %UiPath_ShrtCut%, , OutDir ;get parent directory of shortcut.lnk
;modify your_script_path\Main as per your script and its path
Script=""%OutDir%\UiRobot.exe" "-file" "your_script_path\Main.xaml"" ;script folder and script name
; you can add additional clause in here
If (FileExist(UiPath) "D")
{
Process, Exist, %UiPath_Asstnt%
if ErrorLevel = 0
{
Runwait, %UiPath_ShrtCut%
WinWait, ahk_exe %UiPath_Asstnt% ;wait for UiPath.Assistant to load
Sleep, 2500
Runwait, %comspec% /c TASKKILL /im %UiPath_Prcss% /f ,,Hide ;now kill UiPath main window
;Run, %A_AHKPath% %Rec_Script% ;run record
Run, %comspec% /c %Script%,,Hide
}
else
{
;Run, %A_AHKPath% %Rec_Script% ;run record
Run, %comspec% /c %Script%,,Hide
}
}
return
Then create a task schedule as per your desired trigger and use following in action tab,
Program/Script: "C:\Program Files\AutoHotkey\AutoHotkey.exe"
Add Arguments (optional): "Script_path\Script_name.ahk"

VBS Runs from Explorer but not Task Scheduler

I have a legacy VBS script that runs on a schedule via task scheduler. The script checks a folder (located in a mapped network drive) and processes the files it finds in the folder.
Recently it just stopped working. I didn't write this script, I've only inherited it. It no longer seems to find files in the folder it's looking in, even when they're there. To test we created a log file and wrote file names to it. When manually double-clicking the file and running it from explorer it writes to the log file and sees everything in the directory. If you run it from the Task Scheduler it sees no files and writes nothing to the log file. It also runs for days and never seems to exit when the scheduler runs it, even if there are no files and when I run manually it closes immediately when there are no files.
We have several other legacy scripts that are very similar in function to this one and they all work exactly as expected without issue.
This script is run as administrator (the others are as well). I set the "Start In" to it's current directory (the start in directive is not set for the other scripts and they function normally) and this did not help.
This script uses full file paths to everything (the others do as well).
It works as expected only when double clicked.

Run .exe anywhere in cmd without PATH variable

This works (Notepad++):
C:\Anywhere> start notepad++ hello.txt
And this works (SoX for removing silence in sounds):
C:\Anywhere> sox in.wav out1.wav silence 1 0.1 1%
Yet, my PATH variable includes neither (would send on request).
How can I do this with my program?
To run from everywhere.
Also, why doesn't Notepad++ work without the start command?
(I did this workaround by putting the .exe in C:\ and then simply calling C:\Anywhere> /myprogram but I'm still curious about the above.)
To get the indicated scenario where
you can start applications from anywhere using the start command (or the windows Run dialog) without including its parent folder in path variable,
but you can not start the application without the start command from any directory whithout including the full path to reach it (it is not in the path) or being located in the adecuated directory
the applications are included in the registry under the key
HKEY_CLASSES_ROOT\Applications
note: It is a "merged" view showing the combined contents of
HKEY_LOCAL_MACHINE\Software\Classes\Applications
HKEY_CURRENT_USER\Software\Classes\Applications
If you are not administrator to change the local machine configuration, you can always modify your user registry information to include the applications you need.
edited There is a second place in registry that will allow to include an application in the registry to be executed using start command, Run dialog or from anything that uses the ShellExecute or ShellExecuteEx API calls.
HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\App Paths\

Installshield - Running Powershell script from elevated command prompt

I'm using InstallShield to create an MSI that runs a .cmd file which calls a powershell script. The powershell script changes 2 registry keys. One it is removing a DENY right on a registry key for SYSTEM and the other it's changing a key's value from 0 to 1.
The script runs fine when manually executed or when I simply run the .cmd file that's used within the .MSI.
When I run the .msi, however, the cmd file runs... the powershell script executes and the value gets changed from 0 to 1... however, the DENY is not removed. The msi is running an executable custom action which I named RunCMD it is set to run in "Deferred Execution in System Context" and set to run After PublishFeatures.
I am at a loss as to why running the .cmd in this way (should be elevated) is not executing the portion of the powershell script which alters the permission on the registry key but it does allow for the value change on the other key. The script definitely runs but it partially fails when run within the .msi.
Again, if I manually run the .cmd file myself the script runs without issue so it's not a problem with the script itself.

Batch File calls VBScript which calls EXE that won't open

I have a VBS file 'migration.vbs' that runs a number of commands and then calls an AutoIt .exe file to begin the uninstall of a product. The entire script runs successfully when you call it by itself from the command line with 'cscript migration.vbs'
This script is going to be pushed out to a number of other machines where techs need to be able to double-click to run it. A lot of the machines don't execute VBS by default on a double click, so I've added a batch file to run it.
The problem is that when the batch file calls the VBS, it starts to run but never calls the exe. It just.. skips that step. I'm guessing there's an issue with nested system calls or something that I don't know about.
Anyways, any solutions? I'd rather not put the EXE call in the batch file due to logic checking the VBS does against registry keys (that'd be hard/impossible to duplicate in BAT).
Thanks again
start.bat
START /WAIT cscript .\data\migration.vbs
migration.vbs
WSHSHell.Run "uninstall.exe", 0, True
There is no nested system calls limit, I'm guessing that the path or current directory is wrong, try using a full path or monitor the filesystem calls with Process Monitor

Resources