Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

SMTP VIRTUAL SERVER

Status
Not open for further replies.

BeginnerProgrammer

Technical User
Aug 2, 2002
33
0
0
US
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.
 
Not sure if this is what you're looking for...

I have a routine that starts/stops services on several servers. I stripped code I didn't think you needed here, so no gurantee that this works. But, if it doesn't it should be close to starting/stopping services.
Code:
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
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top