1

Тема: VBS: Путь к %windir% при отправке файла на e-mail

Доброго времени суток! Есть скрипт отправки файла на e-mail. При прописывании пути: iMsg.AddAttachment " C:\WINDOWS\TEST.TXT" - файл отсылается. Хотелось-бы прописать:iMsg.AddAttachment "  %windir%\TEST.txt

Код:

set FSO = CreateObject("Scripting.FileSystemObject")
Set WSHshell = WScript.CreateObject("WScript.Shell")
Set sDir = WSHshell.Environment("Process") ' - находим путь к папке Windows
'=================================================    ==================================================    ============
set FSO=createobject("scripting.filesystemobject")
Call SendPost("smtp.mail.ru","*********77@mail.ru","**********ez@mail.ru","Инфо","**********")
Function SendPost(strSMTP_Server,strTo,strFrom,strSubject,strBody)
Set iMsg=CreateObject("CDO.Message")
Set iConf=CreateObject("CDO.Configuration")
Set Flds=iConf.Fields
Flds.Item("http://schemas.microsoft.com/cdo/configuration/sendusing")=2
Flds.Item("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate")=1
Flds.Item("http://schemas.microsoft.com/cdo/configuration/sendusername")="*********ez@mail.ru"
Flds.Item("http://schemas.microsoft.com/cdo/configuration/sendpassword")="*********"
Flds.Item("http://schemas.microsoft.com/cdo/configuration/smtpserver")="smtp.mail.ru"
Flds.Item("http://schemas.microsoft.com/cdo/configuration/smtpserverport")=25
Flds.Update
iMsg.Configuration=iConf
iMsg.To=strTo
iMsg.From=strFrom
iMsg.Subject=strSubject
iMsg.TextBody=strBody
iMsg.AddAttachment " "windir"\TEST.TXT"
iMsg.Send
End Function
Set iMsg=Nothing
Set iConf=Nothing
Set Flds=Nothing

Происходит ошибка:
Строка: 24
Символ: 23
Ошибка: Предполагается наличие окончания инструкций
код: 80A0401

P.S. Гуглил,читал, экспериментировал - но победить не смог(в языках программирования полный ноль)

2

Re: VBS: Путь к %windir% при отправке файла на e-mail

Set WSHShell = WScript.CreateObject("WScript.Shell")
Const str = "http://schemas.microsoft.com/cdo/configuration/"
With WScript.CreateObject("CDO.Message")
.From = "xxx@mail.ru"
.To = "xxx@mail.ru"
.Subject = "xxx"
.Textbody = "xxxxx"
.AddAttachment WSHShell.ExpandEnvironmentStrings("%windir%\TEST.txt ")
With .Configuration.Fields
.Item(str & "smtpserver") = "smtp.mail.ru"
.Item(str & "sendusing") = 2
.Item(str & "smtpserverport") = 2525
.Item(str & "smtpauthenticate") = 1
.Item(str & "sendusername") = "xxx@mail.ru"
.Item(str & "sendpassword") = "pss" 
.Update
End With  
.Send
End With

3

Re: VBS: Путь к %windir% при отправке файла на e-mail

КИРПИЧ, код на форуме оформляется тэгом «code».

Смотрите, например, здесь: 3.1. ExpandEnvironmentStrings.

4

Re: VBS: Путь к %windir% при отправке файла на e-mail

Спасибо огромное armenxxx1! Код работает!!!
Спасибо alexii за ссылку(буду изучать),замечание - учту!