Access VBA中的Windows服务控件 [英] Windows service control from Access VBA
问题描述
Hi Guys
我为我的客户编写了一个使用Access的应用程序,使用Bartender打印条形码标签等。
I have written an app for my client with Access that uses Bartender to print barcode labels and such like.
Bartender有3个或4个Windows服务,我在Access应用程序中监控。这很好。但是,我希望能够使用Access应用程序中的命令按钮启动或重新启动服务,以保存用户必须使用Bartender应用程序或Windows services.msc应用程序来学习如何使用外部
执行此操作。
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.
现在我有VBA代码来进行服务监控,效果很好。但是,当我以管理员身份运行Access时,启动/重启(停止/启动)服务的代码在开发环境中正常工作,但是当我将其部署到运行
Access运行时软件的其他客户端时,监控代码可以正常工作好的,但是启动/重启命令按钮没有做任何事情。
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.
我认为它是因为它们在Access Runtime中没有管理员权限。
I assume its because they have no administrator permissions in Access Runtime.
我的问题是;
1)我可以在客户端上设置Access Runtime来运行管理员
1) Can I setup Access Runtime on the clients to run as administrator
或
2)有没有办法从提升权限级别的VBA发送服务启动/停止命令。
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
      对于每个svc In GetObject("winmgmts:{impersonationLevel = impersonate}!\\\\\root \ cimv2")_
       .ExecQuery(" SELECT * FROM Win32_Service WHERE Name ='"& service&"'")
    svc.StartService
退出为
下一步
For Each svc In GetObject("winmgmts:{impersonationLevel=impersonate}!\\.\root\cimv2") _
.ExecQuery("SELECT * FROM Win32_Service WHERE Name='" & service & "'")
svc.StartService
Exit For
Next
非常感谢
Jerry
Jerry Barrett
Jerry Barrett
推荐答案
您可以创建一个配置为以"管理员"身份运行应用程序的快捷方式,但主要是问题是用户管理员在他们自己的机器上?如果没有,则需要模拟其他帐户。
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.
这篇关于Access VBA中的Windows服务控件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!