Results 1 to 20 of 25

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

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Mar 2014
    Location
    USA
    Posts
    85
    Thanks
    17
    Thanked 2 Times in 2 Posts
    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
    309
    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
    85
    Thanks
    17
    Thanked 2 Times in 2 Posts
    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,536
    Thanked 284 Times in 279 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
    85
    Thanks
    17
    Thanked 2 Times in 2 Posts
    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.

  6. #6
    Join Date
    Mar 2014
    Location
    USA
    Posts
    85
    Thanks
    17
    Thanked 2 Times in 2 Posts
    Qt products
    Qt5
    Platforms
    Windows

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

    I had a command line server program written, and I thought it would just be a matter of adding/changing a few lines of code to make it a QtService. Didn't work. I tried making a blank one from scratch in Visual Studio 2013. Started out I made a command line (QCoreApplication) project. Then I tried to create an empty service using add class. Named the class MyService (I had to call it something) made the base class QCoreApplication, left constructor signature blank. Once created, I put all the appropriate values in the constructor. I then added "qtservice.h" and added the code to make it a QtService<QCoreApplication>.
    Then I added all the virtual functions. I left them as empty functions. What it looks like when the compile fails is that QtService<QCoreApplication> is not inheriting QObject. A while back I made a gui service but you can't do that anymore so it got scrapped but I still have the code. On that one I used QtWidgets/QApplication to make an application and then changed the .h and .cpp files to match a QtService, included the .h file, and added the necessary functions (start, stop, etc.) and it compiled fine. I checked the project settings and they are all set to include qtservice. I also tried it with and without Q_OBJECT* at the beginning of the class. What am I doing wrong? added this after post. I'm getting error C2039 staticMetaObject is not a member of QtService<QCoreApplication>. When I looked it up online it said in several places that it's not inheriting QObject.
    Last edited by TonyInSoMD; 20th September 2018 at 15:04.

  7. #7
    Join Date
    Mar 2008
    Location
    Kraków, Poland
    Posts
    1,536
    Thanked 284 Times in 279 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

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

    We are not fairies. What does "compilation fails" mean?

  8. #8
    Join Date
    Jan 2019
    Posts
    3
    Qt products
    Qt4
    Platforms
    Android

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

    Quote Originally Posted by TonyInSoMD View Post
    I had a command line server program written, and I thought it would just be a matter of adding/changing a few lines of code to make it a QtService. Didn't work. I tried making a blank one from scratch in Visual Studio 2013. Started out I made a command line (QCoreApplication) project. Then I tried to create an empty service using add class. Named the class MyService (I had to call it something) made the base class QCoreApplication, left constructor signature blank. Once created, I put all the appropriate values in the constructor. I then added "qtservice.h" and added the code to make it a QtService<QCoreApplication>.
    Then I added all the virtual functions. I left them as empty functions. What it looks like when the compile fails is that QtService<QCoreApplication> is not inheriting QObject. A while back I made a gui service but you can't do that anymore so it got scrapped but I still have the code. On that one I used QtWidgets/QApplication to make an application and then changed the .h and .cpp files to match a QtService, included the .h file, and added the necessary functions (start, stop, etc.) and it compiled fine. I checked the project settings and they are all set to include qtservice. I also tried it with and without Q_OBJECT* at the beginning of the class. What am I doing wrong? added this after post. I'm getting error C2039 staticMetaObject is not a member of QtService<QCoreApplication>. When I looked it up online it said in several places that it's not inheriting QObject.
    but what exactly was the C2039 error?
    because I have always found this error

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.