2016-05-24 1 views
0

J'ai besoin d'aide pour mon premier script VBS. Fondamentalement, je veux vérifier si Outlook est ouvert, sinon je veux ouvrir le programme, si/quand il est ouvert, je veux envoyer un e-mail.Vérifiez outlook send email

set service = GetObject ("winmgmts:") 

for each Process in Service.InstancesOf ("Win32_Process") 
    If Process.Name = "outlook.exe"(
     goto "send" 
     ) else (
     goto "Open" 
     ) 
    End If 
Open: 
    Dim objShell 
    Set objShell = WScript.CreateObject("WScript.Shell") 
    objShell.Run("""C:\Program Files (x86)\Microsoft Office\Office16\OUTLOOK.EXE""") 
    Set objShell = Nothing 
    GOTO send 
send: 
    wscript.Set objMessage = CreateObject("CDO.Message") 
     objMessage.Subject = "Sign in- please reply!" 
     objMessage.Sender = "[email protected]" 
     objMessage.From = "[email protected]" 
     objMessage.To = "[email protected]" 
     objMessage.TextBody = Test Body Email 
     '==This section provides the configuration information for the remote SMTP server. 
     '==Normally you will only change the server name or IP. 
     objMessage.Configuration.Fields.Item _ 
     ("http://schemas.microsoft.com/cdo/configuration/sendusing") = 2 
     'Name or IP of Remote SMTP Server 
     objMessage.Configuration.Fields.Item _ 
     ("http://schemas.microsoft.com/cdo/configuration/smtpserver") = "smtp.gmail.com" 
     'Server port (typically 25) 
     objMessage.Configuration.Fields.Item _ 
     ("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = 25 
     objMessage.Configuration.Fields.Update 
     '==End remote SMTP server configuration section== 
     objMessage.Send 
     exit 

Je sais que ma partie e-mail fonctionne car je peux l'exécuter et envoyer mon email. J'ai des problèmes avec l'instruction "If, ELSE, THEN".

Répondre

0
If Process.Name = "outlook.exe" Then 
    send 
Else 
    open  
End If 

sera le format correct pour if..then..else, mais vbscript ne prend pas en charge GOTO. Si vous convertissez envoyer et ouvrir aux fonctions, vous serez en mesure de les appeler comme indiqué ci-dessus