【发布时间】:2016-09-22 03:03:30
【问题描述】:
我的第一个 VBS 脚本需要帮助。基本上我想检查outlook是否打开,如果没有我想打开程序,如果/当它打开时我想发送电子邮件。
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 = "test@gmail.com"
objMessage.From = "test@gmail.com"
objMessage.To = "test@gmail.com"
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
我确实知道我的电子邮件部分可以运行,因为我可以运行它并发送我的电子邮件。我在使用“If, ELSE, THEN”语句时遇到问题。
【问题讨论】:
标签: vbscript