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 Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

*.asp with VBScript in. How to run it?

Status
Not open for further replies.

jjaanus

IS-IT--Management
Dec 12, 2003
9
EE
i have a VBScript, that is in *.asp file. There is script shta should save outlook attachment automatically in to folder.
But how do i run this script? where i have to copy this file? or what should i have to do?

 
Normally an ASP script file is intended to be executed by a web server like IIS or PWS. Can you post the content of this file to see how to convert them in VBS ?
 
i have server 2000 with iis

code is here:

<SCRIPT RunAt=Server Language=VBScript>

' FILE DESCRIPTION: Saves all attachments of a new arrived message to a
' particular directory
'

Option Explicit

'------------------------------------------------------------------------------
' Global Variables
'------------------------------------------------------------------------------

Dim g_bstrDebug ' Debug String

'------------------------------------------------------------------------------
' CONSTANTS
'------------------------------------------------------------------------------

Dim g_Const_MBX
Dim g_Const_Directory

' Enter the display name of the mailbox which you want have send the report to
g_Const_MBX = &quot;Jaanus Jekimov&quot;

' Enter the directory where you want to save all attachments
g_Const_Directory = &quot;c:\&quot;

'------------------------------------------------------------------------------
' EVENT HANDLERS
'------------------------------------------------------------------------------

' DESCRIPTION: This event is fired when a new message is added to the folder
Public Sub Folder_OnMessageCreated

Dim objSession ' Session
Dim objCurrentMsg ' Current message
Dim objFolder ' Current folder
Dim objAttachment ' Attachment object
Dim objAttachments ' Attachment collection

' Initialize objects
Set objSession = Nothing
Set objCurrentMsg = Nothing
Set objFolder = Nothing
Set objAttachment = Nothing
Set objAttachments = Nothing

' Clear error buffer
Err.Clear

' Get session informationen
Set objSession = EventDetails.Session

' No errors detected ?
If Err.Number = 0 Then

' Write some logging
Call DebugAppend(objSession.CurrentUser & &quot; SendAtt - Proccessing startet&quot;, False)

' Get current folder
Set objFolder = objSession.GetFolder(EventDetails.FolderID,Null)

' No errors detected ?
If Err.Number = 0 Then

' Get current message
Set objCurrentMsg = objSession.GetMessage(EventDetails.MessageID,Null)

' Error detected ?
If Not Err.Number = 0 Then

' Error reading new message
Call DebugAppend(&quot;Error - Could not read message&quot;, True)
Else

' Set current message to read
objCurrentMsg.Unread = False

' Remember subject of arrived message
Call DebugAppend(&quot;New message with subject: <&quot; & objCurrentMsg.Subject & &quot;> arrived&quot;, False)

' Get attachment of the message
On Error Resume Next
Set objAttachments = objCurrentMsg.Attachments

' No errors detected?
If Not objAttachments Is Nothing Then

' Attachments found, write logging
Call DebugAppend(&quot;Attachments found&quot;, False)

' Extract all attachments
For Each objAttachment In objAttachments

' Check if attachment is a file or link
' Note that CDO 1.2x does not support to save OLE objects
' and embedded messages to the file system
If (objAttachment.Type = 1) Or (objAttachment.Type = 2) Then

' Save attachment to the filesystem, write logging
Call DebugAppend(&quot;Save attachments to filesystem&quot;, False)

' Write attachment to the filesystem
objAttachment.WriteToFile(g_Const_Directory & objAttachment.Name)
End If
Next

' Delete attachments
On Error Resume Next
objAttachments.Delete
End If

' Update message
On Error Resume Next
objCurrentMsg.Update

' Error detected ?
If Err.Number <> 0 then

' Could not sent message, write logging
Call DebugAppend(&quot;Error - Could not update message&quot;, True)
Else

' Message successfully sent
Call DebugAppend(&quot;Success - Message updated successfully&quot;, False)
End If
End If
Else

' Could not get current folder
Call DebugAppend(&quot;Error - Could not get current folder&quot;, True)
End If
Else

' Check for any possible sys errors
Call DebugAppend(&quot;Undefinied Error detected&quot;, True)
End If

' Write some logging, without the folder name
Call DebugAppend(&quot;SaveAtt - Processing finished&quot;, False)

' Clear objects
Set objSession = Nothing
Set objCurrentMsg = Nothing
Set objFolder = Nothing
Set objAttachment = Nothing
Set objAttachments = Nothing

' Write results to the Scripting Agent log
Script.Response = g_bstrDebug
End Sub

' DESCRIPTION: This event is fired when the timer on the folder expires
Public Sub Folder_OnTimer
'Not used
End Sub

' DESCRIPTION: This event is fired when a message in the folder is changed
Public Sub Message_OnChange
'Not used
End Sub

' DESCRIPTION: This event is fired when a message is deleted from the folder
Public Sub Folder_OnMessageDeleted
'Not used
End Sub

'-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
' PRIVATE FUNCTIONS/SUBS
'-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+

'------------------------------------------------------------------------------
' Name: DebugAppend
' Area: Debug
' Desc: Simple Debugging Function
' Parm: String Text, Bool ErrorFlag
'------------------------------------------------------------------------------

Private Sub DebugAppend(bstrParm,boolErrChkFlag)

If boolErrChkFlag = True Then
If Err.Number <> 0 Then
g_bstrDebug = g_bstrDebug & bstrParm & &quot; - &quot; & cstr(Err.Number) & &quot; &quot; & Err.Description & vbCrLf
Err.Clear
End If
Else
g_bstrDebug = g_bstrDebug & bstrParm & vbCrLf
End If

End Sub

</SCRIPT>
 
I think that you are better off using Windows Scripting Host - WSH - and turning this into a .VBS file and then running it under a scheduler.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top