NetTalk Central

Author Topic: programatically restart the service  (Read 8815 times)

Richard I

  • Sr. Member
  • ****
  • Posts: 398
    • View Profile
    • Email
programatically restart the service
« on: September 24, 2019, 02:58:27 AM »
I have a clarion app with NetTalk Running as a Service
I can close it programatically, and restart by setting change in " services"

How can I programatically restart the service?

NT 11.19
Thanks
Richard

Jane

  • Sr. Member
  • ****
  • Posts: 372
  • Expert on nothing with opinions on everything.
    • View Profile
    • Email
Re: programatically restart the service
« Reply #1 on: September 24, 2019, 08:38:46 AM »
I'm not sure exactly what you're wanting to do.

From an admin command prompt, you can type
net stop MyServicename
net start MyServicename

You can find MyServiceName from services.msc.  (You have to open the properties page to find the service name.  For example, the service name for "print spooler" is actually Spooler.  You need to use that for the command, not the display name. )

What I typically do with services is to have some kind of "watchdog" app (also running as a service).

If for some reason it needs to restart a service, it uses oddjob to send the commands
net stop MyServiceName
job.KillProcess(AppName,true,true) ! in case it's hung and net stop doesn't work, get brutal
ds_sleep(2000) ! winevent
job.KillProcess(AppName,true,true) ! again.. because I can
ds_sleep(2000)
net start MyServiceName



Richard I

  • Sr. Member
  • ****
  • Posts: 398
    • View Profile
    • Email
Re: programatically restart the service
« Reply #2 on: September 24, 2019, 09:51:15 PM »
Thanks Jane,

I want the User to be able to
Stop and restart the service of selected apps for Upgrade.
I have coded the stopping ok, and when I check the Services , the app is not running
So, once the upgrade is completed,  I want the user to push a button which codes the restart of the service

I cannot expect all Users to be sufficiently competent to browse Services

Cheers

Richard

Jane

  • Sr. Member
  • ****
  • Posts: 372
  • Expert on nothing with opinions on everything.
    • View Profile
    • Email
Re: programatically restart the service
« Reply #3 on: September 25, 2019, 06:39:17 AM »
Richard,

Be aware that your user will need to be running whatever has that button "asAdministrator" in order to start the service.

If you're using SetupBuilder for your upgrade installer, that includes functionality to start and stop services.

If you're coding your own (whether launching a batch file to do "NET START MyService" or using OddJob to do the same thing), your app will need to have an asAdministrator manifest (and preferably be code-signed so as not to flash an "unknown publisher" warning).

But if you've managed to code the stopping of the service, it sounds as if you've got that stuff sorted out.

Cheers,

Jane

mriffey

  • Newbie
  • *
  • Posts: 43
    • View Profile
    • Email
Re: programatically restart the service
« Reply #4 on: September 25, 2019, 06:47:57 AM »
I'd suggest creating another service, accessible via browser, whose only job is to provide admin functions remotely without their having to know much of anything. Give them a browser button to stop the service, start the service, and restart the service. The NTWS service can easily run cmd /c net start and cmd /c net stop, or do the same via oddjob. Then you dont have to worry about them having access to the console, cpanel, admin login, etc.

Matthew51

  • Full Member
  • ***
  • Posts: 152
    • View Profile
    • Email
Re: programatically restart the service
« Reply #5 on: September 27, 2019, 12:41:41 PM »
Their is no way for a service to start itself, something else always has to start it.

I recommend making a patch and management app. Most programs that want to be kept up to date have something like this. You can have your users run it manually, or having it start with windows, and stay down in the system tray. If you have SelfService that will make managing you service easy, see the example that's included for how to use it.

The patcher should do all the needed work from managing the service to downloading and applying the patch. It should also be able to determine that a patch is available, and notify the user.
Contractor with 10+ years of NetTalk experience looking for work.
www.linkedin.com/in/matthew-leavitt
BisWare.ca
Check out my free EasyTime Template

Richard I

  • Sr. Member
  • ****
  • Posts: 398
    • View Profile
    • Email
Re: programatically restart the service
« Reply #6 on: September 27, 2019, 04:21:01 PM »
Ok- Thanks to all

I havent implemented any of the suggestions yet- but I think I may have over complicated the request....

I have a netTalk app running as a service-
It needs to be closed prior to running an upgrade.
I have provided Users in a Clarion app a" shut down button" to close running apps including those running as services.
( I can confirm, if I want to, that the service has been stopped, both from a browse and by checking services)

Once the upgrade has been run I want the user  to restart the nettalk app from another button."Start Services"

my question is - how do I code this please?
Thanks
Richard
NT 11.19


Alberto

  • Hero Member
  • *****
  • Posts: 1873
    • MSN Messenger - alberto-michelis@hotmail.com
    • View Profile
    • ARMi software solutions
    • Email
Re: programatically restart the service
« Reply #7 on: September 27, 2019, 04:53:50 PM »
How do you upgrade? with SetupBuilder you can -Stop your app -Stop the service -Upgrade - Restart the server and rerun your app.
The you only have to run the SB installler from your button.
« Last Edit: September 27, 2019, 04:56:40 PM by michelis »
-----------
Regards
Alberto

DonRidley

  • Don Ridley
  • Global Moderator
  • Hero Member
  • *****
  • Posts: 729
  • donaldridley2011@gmail.com
    • View Profile
    • Email
Re: programatically restart the service
« Reply #8 on: September 30, 2019, 01:57:26 AM »
I'd suggest creating another service, accessible via browser, whose only job is to provide admin functions remotely without their having to know much of anything. Give them a browser button to stop the service, start the service, and restart the service. The NTWS service can easily run cmd /c net start and cmd /c net stop, or do the same via oddjob. Then you dont have to worry about them having access to the console, cpanel, admin login, etc.

What Mark said.  I use a service to process websocket commands sent remotely to update computers in a fleet of patrol cars.  OddJob has a nifty little method named RunAsUser.  It makes use of several Windows API's to run an application with elevated permissions.  Remember, services run with system level privileges so any app started by them ALSO have system privileges.  I run my Setup Builder updates this way.  Works great! 

From your users' interface, you could pass a "command" to execute the code that Jane mentioned.  A NetTalk UDP server is VERY easy to setup.  Send from user to service then run code.  Easy peasy.

See ya!

Don
"Eliminate the impossible, whatever remains, however unlikely, must be the truth."

NetTalk 12.55
Clarion 11

Bruce

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 11250
    • View Profile
Re: programatically restart the service
« Reply #9 on: October 09, 2019, 02:37:34 AM »
Hi Richard,

>> Once the upgrade has been run I want the user  to restart the nettalk app from another button."Start Services"

where would this button be? In a web page? On the user's desktop? On the server Desktop?
This part is unclear to me...

cheers
Bruce

Richard I

  • Sr. Member
  • ****
  • Posts: 398
    • View Profile
    • Email
Re: programatically restart the service
« Reply #10 on: October 09, 2019, 08:26:53 PM »
In a web page on a button.
Thanks Bruce

Bruce

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 11250
    • View Profile
Re: programatically restart the service
« Reply #11 on: October 09, 2019, 10:09:08 PM »
>> In a web page on a button.

How can the web page do anything if the server is no longer alive?

cheers
Bruce

Richard I

  • Sr. Member
  • ****
  • Posts: 398
    • View Profile
    • Email
Re: programatically restart the service
« Reply #12 on: October 10, 2019, 01:16:52 AM »
oops
From a clarion app running on the servers desktop
R

Bruce

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 11250
    • View Profile
Re: programatically restart the service
« Reply #13 on: October 10, 2019, 01:39:38 AM »
well from there you can just do a Net Start Myservicename as Jane pointed out earlier.