Reputation: 47
In VB.net I can execute Custom commands on Windows-Services :
Desktop:
Const SmartShutdown As Integer = 12
Dim myService As New ServiceController("SampleService")
myService.ExecuteCommand(SmartShutdown)
Windows-Service:
Protected Overrides Sub OnCustomCommand(ByVal command As Integer)
Is it also possible to execute commands from VB6 to .net Windows-Service?
Upvotes: 1
Views: 1044
Reputation: 24283
You can use the ControlService API function to send any control codes. This does require that you've called OpenService with the appropriate access and that your process is running at the required level. On Vista+, this can be done using the normal manifest (process wide) or COM elevation.
Upvotes: 1
Reputation: 38474
Consider using the VB6 Shell function and the sc.exe
command line tool to control windows services, e.g:
Shell("cmd /C 'sc stop SampleService > %APPDATA%\svc.log'")
Update
To send a custom command, e.g.:
Shell("cmd /C 'sc control SampleService 128 > %APPDATA%\svc.log'")
Custom command should be in the range 128-255.
Upvotes: 1