How to install a Windows service with Inno Setup? - service

I wrote a batch script to execute after my installation that is made with Inno Setup. The problem is that I have the following command line for my service creation:
sc create MySQL start= auto DisplayName= MySQL binPath= "C:\MyApp\MySQL 5.5\bin\mysqld" --defaults-file="C:\MyApp\MySQL 5.5\my.ini"
The letters with accents are the problem of this code, I can't execute it if I open the bat file in cmd, but when I type the service is created normally. How can I fix that?

Rather than calling SC directly, it's cleaner (and easier to deal with any errors or service dependencies) to use the API. Note that this example assumes that you're using ANSI Inno, but it's fairly straightforward to modify this for Unicode.
Personally, though, I prefer to build install/start/stop/uninstall commands into the service executable itself, making it self-registering. Obviously this isn't possible to do yourself for a third-party service, but you could check to see if it already supports something like this.
One final point is that you must not hard-code the path to a C: folder. You should be using {app} instead.

You could try to add this command to [RUN] section (as TLama suggested) or create AfterInstall function in [CODE] section.
[Run]
Filename: "{cmd}"; Parameters: "sc create MySQL start= auto DisplayName= MySQL
binPath= ""C:\MyApp\MySQL 5.5\bin\mysqld""
--defaults-file=""C:\MyApp\MySQL 5.5\my.ini""";
Flags: runhidden

Related

WildFly CLI run script against embedded server

I have some scripts that I run using jboss-cli -c --controller=... --file=myscript.cli.
The -c and --controller options are great, because my script does not know which server it should be run against and can be reused for multiple servers.
I now want to use the offline-cli feature to avoid port conflicts and prevent servers from beeing reachable through the network while they are beeing set up.
My issue is now that in order to start an embedded server I have to use the CLI-command embed-server, but I don't want to add that command to my scripts, because the scripts are not supposed to know the name of the server config xml file.
Unfortunately I can't use both --command="embed-server --server-config=my-standalone.xml" and --file=myscript.cli at the same time, because the CLI complains with:
Only one of '--file', '--commands' or '--command' can appear as the argument at a time.
Another thing I tried was: --commands="embed-server --server-config=my-standalone.xml,run-batch --file=\"myscript.cli\" but this does not work either, because my scripts contain some if-else logic, for instance:
if (outcome == success) of /subsystem=iiop-openjdk:read-resource()
/subsystem=iiop-openjdk:remove()
end-if
And unfortunately conditional logic is not supported in batch mode (see https://bugzilla.redhat.com/show_bug.cgi?id=1083176).
the simple way is to start your embedded server in your script :
embed-server --std-out=echo --server-config=standalone-full.xml
/subsystem=messaging-activemq/server=default/jms-queue=inQueue:add(durable=true, entries=["/queue/inQueue","java:jboss/exported/queue/inQueue"])
/subsystem=messaging-activemq/server=default/jms-queue=outQueue:add(durable=true, entries=["/queue/outQueue","java:jboss/exported/queue/outQueue"])
quit
Don't forget to quit at the end of your cli script :)
If you are using a Unix system you may try something like this:
(echo embed-server --std-out=echo --server-config=my-standalone.xml; cat myscript.cli) | jboss-cli.sh

How can I make a SSH tunnel command into a service on Windows 10?

I have a very simple command in powershell to start SSH tunnels:
ssh -N -L 28777:localhost:28778 myapp-db
What's the simplest way to make this a service, so I can run:
start-service db-tunnel
etc on Windows 10? I've read an old article on doing this and it involves using C#, which seems way too complex for such a simple task.
PowerShell is not necessary. Here's one way:
Install the Windows Server 2003 Resource Kit Tools package somewhere and get the files instsrv.exe and srvany.exe.
Use srvany.exe to create the service using the ssh.exe program and its parameters using the information in Microsoft help article 137890.
For example:
instsrv "SSH Server" "C:\Program Files (x86)\Resource Kit Tools\srvany.exe"
Of course, specify whatever service name you want and the path and filename of srvany.exe.
Next, use the registry editor to go to HKLM\SYSTEM\CurrentControlSet\Services\SSH Tunnel (or whatever you named the service) in the registry and create a Parameters subkey. In the Parameters subkey create an Application value (REG_SZ type):
C:\Program Files (x86)\ssh\ssh.exe
(or whatever - the path and filename to your ssh executable).
You can also create the values AppDirectory (REG_SZ) to specify the starting directory for the executable, and AppParameters (REG_SZ) to specify the parameters to the executable; e.g.:
-N -L 28777:localhost:28778 myapp-db
You can substitute the use of the NSSM tool mentioned by BenH in his comment if you prefer that tool and are allowed to use third-party software.
To make something into a service, you would need to compile your script into an executable. This can be done via PS2EXE.
What may work just as well for you is making a function in powershell, Start-DbTunnel, and making that import into your powershell session on start. You can do this by loading functions in the foloowing path:
$PSprofilePath\Microsoft.PowerShell_profile.ps1
or for the ISE
$PSprofilePath\Microsoft.PowerShellISE_profile.ps1
Inside those files, I have
$PSprofilePath = "C:\Users\cknutson\Documents\WindowsPowershell"
$items = Get-ChildItem "$PSprofilePath\functions"
#Set-Location "$PSprofilePath\functions"
$items | ForEach-Object {
. $_.FullName
}
Set-Location C:\
Any scripts containing functions, or otherwise will be run each time you open a powershell host.

How to run Powershell file (having extension .ps1) using jmeter?

I want to execute .ps1 file in jmeter. I have pass the parameter as in image,but in output facing errors.The filename, directory name, or volume label syntax is incorrect.
Though the filename, directory name are correct.
Here is your problem:
Remove that quotation mark and everything should start working as expected
In general, you are making things overcomplicated.
Why do you need these cmd /c? Why just don't call powershell directly?
Normally powershell is in Windows PATH, there is no need to provide full path to it
So configure your OS Process Sampler as:
Command: powershell
Parameter: D:\Software\apache=jmeter-3.0\apache-jmeter-3.0\bin\TIP.ps1
See How to Run External Commands and Programs Locally and Remotely from JMeter article for more information on invoking 3rd-party processes from your JMeter test.
I know this is an old thread but since the response was not correct for me I found the solution to be this:
Using the OS Process Sampler you need to add as command powershell.exe and as variables exactly the following:
-executionpolicy
bypass
-file
fullpathToYourScript.ps1
This worked perfectly fine for me.

Calling External Command From Powershell Plugin

I have an application process that runs in IBM UrbanCode. The process uses a Powershell Script that uses the CloudFoundry CLI. Our application process runs on an agent on which the CloudFoundry CLI is installed and available on the Path. Strangely enough, the Powershell plugin doesn't know that the CloudFoundry CLI is on the path. Echoing out the path via the plugin itself confirms this.
Currently, our application process looks like:
Copy CloudFoundry CLI into UCD's workspace at the start of the job.
Execute various CloudFoundry commands via the following sytax: .\cf login -u foo -p bar -o baz -s bart
I want to avoid copying the client into the workspace and having to use the .\cf sytax in order to make the scripts more portable.
How can I get the Powershell plugin to respect the Agent's path?
Sounds like the user that your powershell agent is running under does not have CloudFoundry in its path. options are
1. Ensure the PATH variable is set system wide.
2. instead of copying the CloudFoundary CLI you could manually add the path to CloudFoundry before you run the script
$env:Path += ;<PATH TO CLOUDFOUNARY>
Note: this will only persist for the current session.
To test that you have CloudFoundary in the path you can use
Get-Command cf

How Can I Compile Postgresql (pl/pgsql) Functions from Sublime?

Is there a way to compile pl/psql functions from within Sublime Text 2?
Add New Build System file with this commands and save it.
{
"cmd": ["psql", "-d", "your-database name",
"-U", "postgres",
"-f", "$file"],
"word_wrap": "false"
}
I actually just released a plugin (called DB1) that allows you to do just that. You can dynamically connect to and execute queries and functions against a PostgreSQL or MySQL database (I'm in the process of adding more databases too). A cool part about it is it doesn't require you to install anything on your computer (other than Sublime Text).
All you have to do is install DB1 through Package Control, and then in a view you can run the command DB1: Connect to connect to your database. You can then execute sql in that view through one of the DB1: Execute commands.
You can also just open the PSQL function (if you have it saved in a file) and execute the whole file.
To see how it works you can check out the DB1 Website or the documentation. Let me know if you have any questions about it!
Yes you can. In order for this answer to work your network user must have access to the database. The way to do it is to create a new build system in Sublime for postgresql. You can do this by clicking Tools>Build System>New Build System.... Then replace the default build text with:
{
"path": "C:/Program Files (x86)/pgAdmin III/1.20/",
"cmd": ["psql.exe", "-f", "$file", "postgresql://db-staging-1:5432/mydbname"],
"selector": "source.postgresql",
"shell": true
}
Path: This should be the location of your psql.exe executable. Note if this path is in your environment variables path this line is unnecessary.
CMD: This is what will be run from the command line. I've included my connection information here as well. You'll need to replace it with the server path and port number for your database. Note, if you are having trouble with getting your build to run, the easiest way to debug what it's actually trying to run is to add echo on the front of this line:
"cmd": ["echo", "psql.exe", "-f", "$file", "postgresql://db-staging-1:5432/mydbname"],
Now the output of your build will be exactly what it's trying to run on the command line. If what it outputs here doesn't work on your command line then you need to change it to something that will.
Selector: This set the default build for postgresql files.
Shell: Treats the command as a shell script.
Now you can choose your build to be postgresql under Tools>Build System. After that a simple Ctrl+B will compile pl/pgsql functions to your database! Note that regular SQL can be run against your Postgresql database now as well.
If you regularly interact with more than one database at once, see this article as a good reference for setting up connections to multiple databases: How to make build system for PostgreSQL
Other Sublime text build options can be found here: http://sublimetext.info/docs/en/reference/build_systems.html