Results 1 to 5 of 5

Thread: Creating a service, Windows 10, Qt 5.4.1,

  1. #1
    Join Date
    Mar 2014
    Location
    USA
    Posts
    68
    Thanks
    14
    Thanked 1 Time in 1 Post
    Qt products
    Qt5
    Platforms
    Windows

    Default Creating a service, Windows 10, Qt 5.4.1,

    Qt used to have a way to create a service, but they deprecated it with Windows Vista. I did some searching around for a couple of days, worded my search right, and found a method to create a service step-by-step with code on the Microsoft site. There's 4 parts to it, the first step is to create a definitions dll. No problem. You do it command line without opening visual studio. You then create a c++ empty project. Then you add the Svc file, add the definitions library to the project, and you're done as far as creating and starting an empty service. There are other programs form configuration, etc. but as far as installing the service, they are not needed though you will need to run svcconfig delete SvcName to take the service back out. If you going to "play" with it, this is the address of the Microsoft site. https://docs.microsoft.com/en-us/win...service-sample. If I open Visual Studio, create an empty project, add the Svc.cpp file and the sample.dll, compile it, it works fine. So that a could add a Qt class to do the work, I made a Qt console application, copied in the Svc.cpp file and the sample.dll and removed the Qt main. I didn't add any other code to it or anything, it's the same project only with Qt's VisualStudio addin. When I run it to try to install the service, (Svc.exe install), I get the error code ERROR_ACCESS_DENIED when I try to open the ServiceManager "OpenSCManager(NULL,NULL,SC_MANAGER_ALL_ACCESS )". I tried doing the empty project and then adding all the paths, etc and include (but not use) the class, it says I can't do it because I didn't use the Visual Studio add in. I really need this to run as a service so that SysAdmin can control access and so that it will run in the background even in screen-lock mode. I've tried to give enough information, I hope somebody can help me. I attached a copy of the 3 programs written from an empty project that work, the Svc.cpp code, and the sample.dll . The dll is just a set of error definitions, it doesn't really do anything. I didn't know qtcentre wouldn't allow you to upload dll or exe, but it makes sense. I attached all files to create the programs so that you can see what they look like without having to hunt around and without making this post a mile long. The only one I'm having problems with is the Svc.cpp program. The others don't have to be compiled in a Qt environment.
    Attached Files Attached Files

  2. #2
    Join Date
    Jan 2009
    Location
    Russia
    Posts
    307
    Thanks
    2
    Thanked 43 Times in 42 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Creating a service, Windows 10, Qt 5.4.1,


  3. #3
    Join Date
    Mar 2014
    Location
    USA
    Posts
    68
    Thanks
    14
    Thanked 1 Time in 1 Post
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: Creating a service, Windows 10, Qt 5.4.1,

    Yes. The part that actually make it as a service in the background doesn't work starting with Windows Vista

  4. #4
    Join Date
    Mar 2008
    Location
    Kraków, Poland
    Posts
    1,408
    Thanked 256 Times in 251 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Creating a service, Windows 10, Qt 5.4.1,

    Are you sure ? I use this for Windows 7/8/10 and WS 2003/2012 without any problems.

  5. #5
    Join Date
    Mar 2014
    Location
    USA
    Posts
    68
    Thanks
    14
    Thanked 1 Time in 1 Post
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: Creating a service, Windows 10, Qt 5.4.1,

    When I tried it before, I was trying to make a GUI run as a thread. That's the part that was deprecated. Call this a learning lesson. I've already made a command line version, and on reading the documentation again, it says that you should separate the service and the GUI into two separate programs. I've already done this, now all I have to do is get the command line to run as a service. Here we go trying to figure out how to make a service using qt-solutions. I'll let you know how it goes.

Similar Threads

  1. How do I create a Windows Service in Qt?
    By ayanda83 in forum Qt Programming
    Replies: 1
    Last Post: 11th September 2017, 12:16
  2. How to install a service in windows with automatic startup?
    By josecarlosmissias in forum Qt Programming
    Replies: 0
    Last Post: 11th December 2009, 17:01
  3. Start Qt application as Windows Service
    By ^NyAw^ in forum Qt Programming
    Replies: 12
    Last Post: 10th May 2008, 17:23
  4. Creating QDS service
    By bowser in forum Qt for Embedded and Mobile
    Replies: 1
    Last Post: 29th October 2007, 11:12
  5. Windows Service
    By TheGrimace in forum Qt Programming
    Replies: 3
    Last Post: 5th October 2007, 19:46

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.