Announcement

Collapse
No announcement yet.

Low Toner Script Writing to text file

Collapse
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • Low Toner Script Writing to text file

    I have this sample script but I am having trouble to just get it to write to a file. Once I can do this I would want it to specifically write what toner is low to what printer, and not the printers where toner is not low. Attached is the script. Thanks for anyone who can help.
    Attached Files

  • #2
    Re: Low Toner Script Writing to text file

    Ok so I modified the script and I have it doing pretty much what I want except for sending an emaill through smtp. I get no errors so I don't what is wrong.

    Code:
    Set wmi = GetObject("winmgmts:\\.\root\CIMV2")
    Set col = wmi.ExecQuery("SELECT * FROM Win32_Printer")
    Set fso = CreateObject("Scripting.FileSystemObject")
    set tf = fso.CreateTextFile("c:\tonerlow.txt", True)
    Set objMessage = CreateObject("CDO.Message")
    i = 1
    For Each item In col
    tf.writeline "Printers on " & item.name & ", Printer Number: " & i
    tf.writeline "===================================="
    tf.writeline "Printer: " & item.DeviceID
    tf.writeline "Driver Name: " & item.DriverName
    tf.writeline "Printer State: " & item.PrinterState
    tf.writeline "Location: " & item.Location & vbcrlf
    i = i + 1
    Next
    tf.close
    
    objMessage.Subject = "Low Toners"
    objMessage.From = "[email protected]"
    objMessage.To = "[email protected]"
    objMessage.TextBody = "Attached is the low toners for today."
    objMessage.AddAttachment "c:\tonerlow.txt"
    objMessage.Send
    
    msgbox "Low Toner info has been logged and emailed"
    (EDIT: made code instead of quote by Tonyyeb)
    Last edited by tonyyeb; 15th July 2006, 22:24.

    Comment


    • #3
      Re: Low Toner Script Writing to text file

      OK, I tried it (with my email addresses) and got:

      Error: The transport failed to connect to the server at line 23
      Code: 80040213

      This is the ObjMessage.send line

      Some googling suggests that (in ASP at least) you need to configure the CDO.
      Try here for something

      It still doesnt work, though....


      Tom
      Tom Jones
      MCT, MCSE (2000:Security & 2003), MCSA:Security & Messaging, MCDBA, MCDST, MCITP(EA, EMA, SA, EDA, ES, CS), MCTS, MCP, Sec+
      PhD, MSc, FIAP, MIITT
      IT Trainer / Consultant
      Ossian Ltd
      Scotland

      ** Remember to give credit where credit is due and leave reputation points where appropriate **

      Comment


      • #4
        Re: Low Toner Script Writing to text file

        also seeing this?
        http://www.petri.com/send_mail_from_script.htm
        Marcel
        Technical Consultant
        Netherlands
        http://www.phetios.com
        http://blog.nessus.nl

        MCITP(EA, SA), MCSA/E 2003:Security, CCNA, SNAF, DCUCI, CCSA/E/E+ (R60), VCP4/5, NCDA, NCIE - SAN, NCIE - BR, EMCPE
        "No matter how secure, there is always the human factor."

        "Enjoy life today, tomorrow may never come."
        "If you're going through hell, keep going. ~Winston Churchill"

        Comment


        • #5
          Re: Low Toner Script Writing to text file

          Hey I actually just figured out the cause of the problem, it was looking for a server that wasn't there, so once that was fixed it when through. For the error message you guys were getting, not so sure, you night now have CDO installed in you computer.

          Comment


          • #6
            Re: Low Toner Script Writing to text file

            It depends on the server OS i think. Plus you may need the SMTP virtual server installed in IIS and set the smart host to another exchange server / mail server. Or you can specify it in the script using:

            Code:
            objEmail.Configuration.Fields.Item _
                ("http://schemas.microsoft.com/cdo/configuration/sendusing") = 2
            objEmail.Configuration.Fields.Item _
                ("http://schemas.microsoft.com/cdo/configuration/smtpserver") = _
                    "smarthost" 
            objEmail.Configuration.Fields.Item _
                ("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = 25
            objEmail.Configuration.Fields.Update
            Replace smarthost with the name of an SMTP server.

            Hope this helps

            (Code from: http://www.microsoft.com/technet/scr....mspx?mfr=true)
            Server 2000 MCP
            Development: ASP, ASP.Net, PHP, VB, VB.Net, MySQL, MSSQL - Check out my blog http://tonyyeb.blogspot.com

            ** Remember to give credit where credit is due and leave reputation points sigpic where appropriate **

            Comment


            • #7
              Re: Low Toner Script Writing to text file

              Yeh I had to install ISS with SMTP on my machine at home for the email to be sent out. Does anyone know how to have it pick only specific printer states....so it will give back a number for printer states, and a certain number will be the low toner, and any others are normal. Would I use an if/then statement for this? I am not too sure how to do this.

              Comment


              • #8
                Re: Low Toner Script Writing to text file

                Originally posted by ekrengel
                Yeh I had to install ISS with SMTP on my machine at home for the email to be sent out. Does anyone know how to have it pick only specific printer states....so it will give back a number for printer states, and a certain number will be the low toner, and any others are normal. Would I use an if/then statement for this? I am not too sure how to do this.
                Check out this post:

                http://forums.petri.com/showthread.php?t=8809
                Server 2000 MCP
                Development: ASP, ASP.Net, PHP, VB, VB.Net, MySQL, MSSQL - Check out my blog http://tonyyeb.blogspot.com

                ** Remember to give credit where credit is due and leave reputation points sigpic where appropriate **

                Comment


                • #9
                  Re: Low Toner Script Writing to text file

                  Thanks it looks like this will help a lot.

                  Comment

                  Working...
                  X