Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. Visual Basic
  4. how to do this in windows service

how to do this in windows service

Scheduled Pinned Locked Moved Visual Basic
sysadminhelptutorialquestioncareer
1 Posts 1 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • M Offline
    M Offline
    MagicGirL83
    wrote on last edited by
    #1

    i have this code and i want this as a windows service. i like this to execute every 20 secs Dim olapp As New Outlook.Application Dim olNs As Outlook.NameSpace Dim myrecipient, myfolder Dim myitems As Outlook.Items Dim mymail As Outlook.MailItem Dim myitem As Object Dim myConnection As SqlConnection Dim myCommand As SqlDataAdapter Dim cmd As New SqlCommand olapp = CreateObject("Outlook.application") olNs = olapp.GetNamespace("MAPI") myrecipient = olNs.CreateRecipient("someusername") myrecipient.resolve() If myrecipient.resolved Then myfolder = olNs.GetSharedDefaultFolder(myrecipient, Outlook.OlDefaultFolders.olFolderInbox).Items End If myitems = myfolder myConnection = New SqlConnection("Data Source=.....") myCommand = New SqlDataAdapter myitems = myitems.Restrict("[Unread] = true") myConnection.Open() For Each myitem In myitems On Error Resume Next cmd = New SqlCommand("Insert into NewMessages (EntryID,SenderName,Subject,ReceivedTime,Body,UnRead) values(@EntryID ,@SenderName,@Subject,@ReceivedTime,@Body,@UnRead)", myConnection) cmd.Parameters.Add(New SqlParameter("@EntryID", SqlDbType.Variant)) cmd.Parameters("@EntryID").Value = myitem.entryid cmd.Parameters.Add(New SqlParameter("@SenderName", SqlDbType.NVarChar, 100)) cmd.Parameters("@SenderName").Value = myitem.sendername cmd.Parameters.Add(New SqlParameter("@Subject", SqlDbType.NVarChar, 1000)) cmd.Parameters("@Subject").Value = myitem.subject cmd.Parameters.Add(New SqlParameter("@ReceivedTime", SqlDbType.DateTime)) cmd.Parameters("@ReceivedTime").Value = myitem.ReceivedTime cmd.Parameters.Add(New SqlParameter("@Body", SqlDbType.Variant))cmd.Parameters("@Body").Value = myitem.Body cmd.Parameters.Add(New SqlParameter("@UnRead", SqlDbType.NChar, 5))cmd.Parameters("@UnRead").Value = myitem.UnRead cmd.ExecuteNonQuery() Next myitem myConnection.Close() olapp = Nothing olNs = Nothing myrecipient = Nothing myfolder = Nothing myitem = Nothing myitems = Nothing myrecipient = Nothing i've already created a service for this one but, on its first start, it extracts unread mails, but when new mails come, it does not extract anything and when i checked on the application log it says, Microsoft Office 11 - Rejected safe mode action - Microsoft Outlook. on the system log: DCOM - The server {0006F03A-0000-0000-C000-000000000046} did not register with DCOM within the required timeout. I already uninstalled and killed the service but i'm still getting this errors on the eventlog. why is this so? i think i

    1 Reply Last reply
    0
    Reply
    • Reply as topic
    Log in to reply
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes


    • Login

    • Don't have an account? Register

    • Login or register to search.
    • First post
      Last post
    0
    • Categories
    • Recent
    • Tags
    • Popular
    • World
    • Users
    • Groups