BeginnerProgrammer
Technical User
Is there a way to progrmatically start and stop a localhost smtp virtual Server with code? What I want to do is have my module start the virtual server, send some emails, and then stop the virtual server.
Follow along with the video below to see how to install our site as a web app on your home screen.
Note: This feature may not be available in some browsers.
function foo()
Const wbemImpersonationLevelImpersonate = 3
'********************************
'* Declaration Specifications *
'********************************
Dim objWMIService As Object
Dim colListOfServices As Object
Dim colListOfServices_Requery As Object
Dim objService As Object
Dim objService_Requery As Object
Dim objSWBemLocator As Object
Dim objSWbemServices As Object
Dim strServerName As String
Dim strSystemName As String
Dim strServiceName As String
Dim errReturn As Long
Dim bolStart as Boolean
bolStart = True
strServerName = "NameOfServerThatServiceIsRunningOn"
strSystemName = "NameOfTheService"
strUser = "YourUserName"
strPassword = "YourPassword"
Set objSWBemLocator = CreateObject("WbemScripting.SWbemLocator")
objSWBemLocator.Security_.ImpersonationLevel = wbemImpersonationLevelImpersonate
Set objSWbemServices = objSWBemLocator.ConnectServer(strServerName, "root\cimv2", strUser, strPassword)
Set colListOfServices = objSWbemServices.ExecQuery("Select * from Win32_Service where Name = '" & strServiceName & "'")
For Each objService In colListOfServices
if (bolStart) and (objService.State = "Stopped")) then
errReturn = objService.StartService()
elseif (not bolStart) and (objService.State = "Running") then
errReturn = objService.StartService()
end if
next
'****************************************
'* Check to see if service is running *
'****************************************
10:
If (bolStart) then
Set colListOfServices_Requery = objSWbemServices.ExecQuery("Select * from Win32_Service where Name='" & strServiceName & "'")
For Each objService_Requery In colListOfServices_Requery
If (objService_Requery.State <> "Running") Then
Pause 5
GoTo 10
End If
Next
End if
end function