none
Windows service control from Access VBA RRS feed

  • Question

  • Hi Guys

    I have written an app for my client with Access that uses Bartender to print barcode labels and such like.

    Bartender has 3 or 4 windows services that I monitor within the Access app. and that works fine. However, I would like to be able to start or restart the services with a command button in the Access app to save the users having to learn how to do this externally with a Bartender app or windows services.msc app.

    Now I have VBA code to do the service monitoring which works great. However, the code to start/restart(stop/start) the service works fine in the development environment when I run Access as administrator, but when I deploy this to other clients running the Access runtime software, the monitoring code works ok, but the start/restart command buttons don't do anything.

    I assume its because they have no administrator permissions in Access Runtime.

    My questions are;

    1) Can I setup Access Runtime on the clients to run as administrator

    OR

    2) is there a way to send a service start/stop command from VBA with an elevated permission level.

    I have attached the code I use below

            For Each svc In GetObject("winmgmts:{impersonationLevel=impersonate}!\\.\root\cimv2") _
                 .ExecQuery("SELECT * FROM Win32_Service WHERE Name='" & service & "'")
                svc.StartService
                Exit For
            Next

    Many Thanks

    Jerry


    Jerry Barrett

    Thursday, December 14, 2017 11:01 AM

Answers

  • Hi,

    Did you find an answer to your question?

    I use Blackviper script to control the windows services. 

    You can make a database (or text file or whatever you want to reference to) with all the services, and then export a csv with the right switches, the script does the rest. You need some knowledge of powershell.

    In your database (or textfiles) you can create as much profiles as you need with certain services on/off/automatic/manual or automatic delayed.

    BE CAREFULL, as this needs knowledge of what services do. Don' t touch a service if you don't know what it does.

    What you can do is start with a fresh WIN10 version, record the services. Install apps, and between each install let your database figure out which service were added. As you go you can determine which services are needed, and which not.

    Just google blackviper setservices

    Hope this helps.

    regards

    Johan

    • Marked as answer by Jerry Barrett Tuesday, August 6, 2019 12:24 PM
    Tuesday, April 3, 2018 5:31 PM

All replies

  • You could just create a shortcut that is configured to run the app "as Administrator", but the main question is are the users administrators on their own machines? If not, then impersonation for a different account will be required.

    Paul ~~~~ Microsoft MVP (Visual Basic)

    Thursday, December 14, 2017 3:07 PM
  • Hi,

    Did you find an answer to your question?

    I use Blackviper script to control the windows services. 

    You can make a database (or text file or whatever you want to reference to) with all the services, and then export a csv with the right switches, the script does the rest. You need some knowledge of powershell.

    In your database (or textfiles) you can create as much profiles as you need with certain services on/off/automatic/manual or automatic delayed.

    BE CAREFULL, as this needs knowledge of what services do. Don' t touch a service if you don't know what it does.

    What you can do is start with a fresh WIN10 version, record the services. Install apps, and between each install let your database figure out which service were added. As you go you can determine which services are needed, and which not.

    Just google blackviper setservices

    Hope this helps.

    regards

    Johan

    • Marked as answer by Jerry Barrett Tuesday, August 6, 2019 12:24 PM
    Tuesday, April 3, 2018 5:31 PM