How to start/stop windows service using Qt? - qt

Lets imagine situation: I have running windows service named "Test". Now I want to stop or start (if it's stopped) this service using Qt app.
How can I do it?
Note:
I don't want to call cmd and use "net start" and "net stop" commands!

You could use the corresponding Qt Solution https://github.com/qtproject/qt-solutions/tree/master/qtservice
Then you can do something like:
QtServiceController controller("Test");
controller.stop();
controller.start();

Unfortunately, Qt does not provide such kind on API.
You need to look into WinAPI solution.
There is an example on MSDN how to stop a service. Im sure you could figure how to use same approach to start it.
Additionally, you could also check a much smaller example how to both start and stop a service.

You can just use the sc command (this page has some usage info or just type sc on the command prompt).
sc stop Test
sc start Test
So:
QProcess::execute("sc", { "stop", "Test" });
QProcess::execute("sc", { "start", "Test" });
Note that you need to be running in an elevated context to control most services.
You could also use net instead of sc if you prefer, same syntax for starting and stopping.
The parameter needs to be the service key name, not the display name; so if you only have the display name you can run sc query or sc GetKeyName "Display Name" and parse the output.

Related

Control-m - Job´s in the line command

Is there any way to see Control-M Job´s in the line command ?
Eveyday I use the Control-M Enterprise Manager GUI, but I´m looking for any way to see all jobs in the line command.
Query the DB of Control-M Server:
Select * From Cms_Jobdef Where Tasktype = 'C '
If you have access to the API you will get the response in JSON format:
ctm run jobs:status
If you go to the "planning" or "monitoring" tools and then select "View" and then "List" (instead of "Map") then it will list all job in non-graphical mode - so you can see all the commands listed (where applicable).
If you have access to the Control-M Server machine itself then this query on the DB will list all commands (where the command line contains text) -
select SCHEDTAB, JOBNAME, CMDLINE from CMS_JOBDEF where CMDLINE IS NOT NULL;
Assuming that you are not using version 8 or higher, you can use CTRL+L on EM GUI to view the jobs as a list.
On the header of the list, right click and use the column chooser to choose to display the commands of the jobs.

Short Webspeed Broker Query

I am trying to create a script that informs the user about the status of the website, which uses WebSpeed. I can use wtbman to output the status of the transaction server, not a problem. But I want something that just tells us the status of the transaction server.
Is there a command that I can use to achieve that, instead of writing a program to parse the returned string for wtbman?
There's no built in approach like for instance Virtual System Tables.
Parsing the output of
wtbman -name <broker> -query
is your best bet. The output isn't very hard to decipher so you should be able to do it quite quick!
Two other commands to check are:
wtbman -name <broker> -agentdetail <pid>
This will go more into detail of a specific agent.
wtbman -name <broker> -listallprops
Lists all settings for the broker.

I want to install an Agent and a USM component in a empty computer whithout installing an application, how can i do this?

I have a scenario that I want to use the Agent and USM component to implement the customer command to control a computer, but I donot want to install an application or a service,
how can i reach this goal?
thank you very much!
Steve
You can install an empty service, one that does not actually run anything. This is often called a 'recipe about nothing'. It should look something like this:
service {
name "empty"
type "WEB_SERVER"
lifecycle {
locator {
NO_PROCESS_LOCATORS
}
}
}
Add your custom commands here and you can run them from the Cloudify CLI/REST API as usual.
Note the use of the NO_PROCESS_LOCATORS directive - this tells the USM not to perform any process liveness scans.

cloudmonkey with crontab?

i have a Cloudstack 4.2.1 here and would like my VMs to boot from time and shutdown at a scheduled time.
Hence i was thinking if i could integrate Cloudmonkey with CronTab together.
Firstly by creating a Cloudmonkey Script or API call then using crontab to run it at a specific time.
However i have problems creating a Cloudmonkey script/API call...
i haved googled and found this link
http://dlafferty.blogspot.sg/2013/07/using-cloudmonkey-to-automate.html
and had a result of
apiresult=cloudmonkey api stop virtualmachine id="'e10bdf21-2d5c-4277-9d8d-791b82b9e3be'"
unfortunately when i entered this command, nothing happened. If anyone could have an alternative suggestion or rather my API call command is wrong, please correct me and help
Thank you.
CloudMonkey requires some setup before it works (e.g. setting your API key).
Check [1] for the documentation for CloudMoney and follow through the Usage section to setup your environment.
Once your setup is complete and you can interact with CloudStack via CloudMonkey, you should take into account that the VM ids might change, so before you issue a command for a VM, you should first find the correct id, by listing the VMs and picking the right one.
Also, if you run into trouble, post the relevant log from CLoudStack management server (typically in /var/log/cloudstack/management/management-server.log).
[1] - https://cwiki.apache.org/confluence/display/CLOUDSTACK/CloudStack+cloudmonkey+CLI
Edit: If you have a working connection via CloudMonkey to CloudStack, you need to configure CloudMonkey in the same way in your shell script. For instance when you configured CloudMonkey you probably set a host, a port and your api and secret keys. So for your scrip to work you need to provide the same configuration to CloudMonkey prior to issuing the commands. My best guess is to use the -c option and provide a config file to set all the relevant parameters (e.g. api an secret key). cloudmonkey -c CONFIG_FILE ....
Edit2: You don't actually need to re-configure cloudmonkey in your script because it will remember your config from the interactive session. I would still advise you to do it, because your script gets more reliable. I've just made an example script like this:
#! /bin/bash
result=$(cloudmonkey list users)
echo $result
Result:
> ./tmp.sh
count = 1 user: id = 678e3a24-082c-11e4-86de-acbdb2423647 account = admin accountid = 678dffe6-082c-11e4-86de-acbdb2423647 accounttype = 1 apikey = T6sDBIpytyJ4_PMgNXYi8YgjMtwTiiDjijbXNB1J78EAZq2foKhCoGKjgJnej5tMaHM0LUvejgTddkhVU63wdw created = 2014-07-10T16:19:13+0200 domain = ROOT domainid = 678dd7b4-082c-11e4-86de-acbdb2423647 email = admin#mailprovider.com firstname = Admin iscallerchilddomain = False isdefault = True lastname = User secretkey = dzOPRecI5vvEVK7Vie2D0tDsQGXunUnpIAczbXnPI3sfMwQ-upWL_bPOisEYg4C-nXi-ldQno2KVZbVR-5NmVw state = enabled username = admin
Maybe you forgot to echothe result?

How can I get the adapter name in hubot script?

Hubot can support different adapter like Shell/IRC/XMPP.
If the adapter is set in environment variable HUBOT_ADAPTER, then process.env.HUBOT_ADAPTER can be checked.
if process.env.HUBOT_ADAPTER is "shell"
msg.send "This is Shell adapater"
But it also support to use options --adapter, and how can I detect this in the hubot script.
I want to write different logic based on adapter like chat-room, userid.
Otherwise I need to prepare separate scripts for different adapater.
Got the two suggestions from github issues https://github.com/github/hubot/issues/647
[update] this issue is fixed in source code robot.coffee by adding adapterName, so you can check robot.adapterName since version 2.7.2, see changes
sniff, It could be checked with special information in adapter, and possible checks below for my environment on shell,xmpp,irc
robot.respond /adapter$/i, (msg) ->
#console.log "adapter", robot.adapter
if robot.adapter.client?
if robot.adapter.client.preferredSaslMechanism?
msg.send "this is xmpp adapter"
if robot.adapter.bot?
if robot.adapter.bot.opt?
msg.send "this is irc adapter"
#if robot.adapter.bot?
# msg.send "this is campfire ?"
if robot.adapter.repl?
if robot.adapter.repl.terminal?
msg.send "this is shell adapter"
add extra parameter in robot.coffee, it needs a patch for this, it is inside code see update above
I choose sniff so far

Resources