问题
In another post on Stack Overflow a user named James L. presented a useful script for adding 7-Zip to the Send to Options in Windows. I was wondering how hard it would be to take that same principle one more step by sending the results on to be attached to an email? Most of the zips I create are done in order to email them and this would cut that down to one click. The only obstacle being that it could not create a self-extracting ".exe" file to be attached.
回答1:
Here are three scripts you can stich together.
CreateBlankZip.vbs Zipname passed as a parameter, use quotes if spaces in name.
Set Ag=Wscript.Arguments
Set fso = CreateObject("Scripting.FileSystemObject")
Set ts = fso.OpenTextFile(Ag(0), 8, vbtrue)
BlankZip = "PK" & Chr(5) & Chr(6)
For x = 0 to 17
BlankZip = BlankZip & Chr(0)
Next
ts.Write BlankZip
Add folder to zip. DestinationZip SourceFolder
Set objShell = CreateObject("Shell.Application")
Set Ag=Wscript.Arguments
set WshShell = WScript.CreateObject("WScript.Shell")
Set SrcFldr=objShell.NameSpace(Ag(1))
Set DestFldr=objShell.NameSpace(Ag(0))
Set FldrItems=SrcFldr.Items
DestFldr.CopyHere FldrItems, &H214
Msgbox "Finished"
Send mail and attach file.
Set emailObj = CreateObject("CDO.Message")
emailObj.From = "dc@gmail.com"
emailObj.To = "dc@gmail.com"
emailObj.Subject = "Test CDO"
emailObj.TextBody = "Test CDO"
emailObj.AddAttachment "c:\windows\win.ini"
Set emailConfig = emailObj.Configuration
emailConfig.Fields("http://schemas.microsoft.com/cdo/configuration/smtpserver") = "smtp.gmail.com"
emailConfig.Fields("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = 465
emailConfig.Fields("http://schemas.microsoft.com/cdo/configuration/sendusing") = 2
emailConfig.Fields("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate") = 1
emailConfig.Fields("http://schemas.microsoft.com/cdo/configuration/smtpusessl") = true
emailConfig.Fields("http://schemas.microsoft.com/cdo/configuration/sendusername") = "MyName"
emailConfig.Fields("http://schemas.microsoft.com/cdo/configuration/sendpassword") = "Ppassword1"
emailConfig.Fields.Update
emailObj.Send
If err.number = 0 then Msgbox "Done"
来源:https://stackoverflow.com/questions/35108798/using-windows-send-to-for-creating-a-one-step-send-tozipto-email