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

Need an expert's eye 1

Status
Not open for further replies.
Apr 27, 2011
4
US
I am a noob in VB and am trying to write a Windows Form Application. My problem is I am trying to make it when you click the email button, it will open an Outlook email, include all of the required information etc. My problem is that when you click the button, it generates (2) email messages. I cannot figure it out!

Code:
  Private Sub Button4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button4.Click
        Dim myHost As String = System.Net.Dns.GetHostName
        Dim myIPs As System.Net.IPHostEntry = System.Net.Dns.GetHostEntry(myHost)
        Dim osVersion = My.Computer.Info.OSVersion
        Dim osPlatform = My.Computer.Info.OSFullName
        Dim totalPhysicalMemmory = My.Computer.Info.TotalPhysicalMemory
        Dim drive = My.Computer.FileSystem.GetDriveInfo("C:\")
        Dim space = drive.AvailableFreeSpace
        Dim space2 = drive.TotalSize
        Dim height = My.Computer.Screen.Bounds.Height
        Dim width = My.Computer.Screen.Bounds.Width
        Dim objWMIService, colInstalledPrinters
        Dim megabytes As String
        Dim memorybytes As String
        Dim megabytes2 As String
        Dim MBytes As Double
        Dim MBytes2 As Double
        Dim MMBytes As Double
        Dim objPrinter
        objPrinter = Nothing
        objWMIService = GetObject("winmgmts:" & "{impersonationLevel=impersonate}!\\" & myHost & "\root\cimv2")
        colInstalledPrinters = objWMIService.ExecQuery("Select * from Win32_Printer where Default = 'True'")
        For Each objPrinter In colInstalledPrinters
        Next
        Dim strComputer
        Dim colSettings
        strComputer = "."
        objWMIService = GetObject("winmgmts:" _
            & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
        colSettings = objWMIService.ExecQuery("Select * from Win32_OperatingSystem")
        For Each objOperatingSystem In colSettings
        Next
        '******************************************************************
        MBytes = (space \ 1024) \ 1024 \ 1024
        MBytes2 = (space2 \ 1024) \ 1024 \ 1024
        megabytes = Format(MBytes, "###.###") & " GB"
        megabytes2 = Format(MBytes2, "###.###") & " GB"
        MMBytes = (totalPhysicalMemmory \ 1024) \ 1024 \ 1024
        memorybytes = Format(MMBytes, "###.###") & " GB"
        '******************************************************************
        For Each myIP As System.Net.IPAddress In myIPs.AddressList
            '******************************************************************
            colSettings = objWMIService.ExecQuery("Select * from Win32_ComputerSystem")
            For Each objComputer In colSettings
                Dim colItems
                objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
                colItems = objWMIService.ExecQuery("Select * from Win32_Processor")
                For Each objItem In colItems
                    Dim officepath, fso, returnstring
                    officepath = "C:\Program Files (x86)\Imprivata\OneSign Agent\"
                    fso = CreateObject("scripting.filesystemobject")
                    returnstring = fso.getfileversion(officepath & "ISXAgent.exe")
                    Dim citrixPath, returnVersion
                    citrixPath = "C:\Program Files (x86)\Citrix\ICA Client\"
                    fso = CreateObject("scripting.filesystemobject")
                    returnVersion = fso.getfileversion(citrixPath & "wfica32.exe")
                    Dim IEPath, IEVersion
                    IEPath = "C:\Program Files (x86)\Internet Explorer\"
                    fso = CreateObject("scripting.filesystemobject")
                    IEVersion = fso.getfileversion(IEPath & "iexplore.exe")
                    '******************************************************************
                    Dim objOutlk, objMail, strMsg
                    Const olMailItem = 0
                    objOutlk = CreateObject("Outlook.Application")
                    objMail = objOutlk.createitem(olMailItem)
                    objMail.To = "xxxx.xxxx@myname.com"
                    objMail.subject = "Info for:: " & myIPs.HostName & " :: " & CStr(Month(Now)) & "/" & CStr(Year(Now))
                    strMsg = "Please paste this information into Footprints ticket" & vbCrLf
                    strMsg = strMsg & ("*************************************************") & vbCrLf
                    strMsg = strMsg & (objComputer.Manufacturer) & vbCrLf
                    strMsg = strMsg & (objComputer.Model) & vbCrLf
                    strMsg = strMsg & ("*************************************************") & vbCrLf
                    strMsg = strMsg & ("User Name: " & SystemInformation.UserDomainName & "\" & SystemInformation.UserName) & vbCrLf
                    strMsg = strMsg & ("Your Computer Name: " & myIPs.HostName) & vbCrLf
                    strMsg = strMsg & ("Your IP Address: " & myIP.ToString) & vbCrLf
                    strMsg = strMsg & ("Default Printer: " & objPrinter.Name) & vbCrLf
                    strMsg = strMsg & ("*************************************************") & vbCrLf
                    strMsg = strMsg & (osPlatform & " v" & osVersion) & vbCrLf
                    strMsg = strMsg & ("Citrix Version: " & returnVersion) & vbCrLf
                    strMsg = strMsg & ("Imprivata SSO Version: " & returnstring) & vbCrLf
                    strMsg = strMsg & ("Internet Explorer Version: " & IEVersion) & vbCrLf
                    strMsg = strMsg & ("*************************************************") & vbCrLf
                    strMsg = strMsg & (objItem.Manufacturer & " - " & objItem.Name) & vbCrLf
                    strMsg = strMsg & ("Memory: " & memorybytes) & vbCrLf
                    strMsg = strMsg & ("HDD Size:  " & megabytes2) & vbCrLf
                    strMsg = strMsg & ("Available HDD Space: " & megabytes) & vbCrLf
                    strMsg = strMsg & ("Display: " & width & (" X ") & height) & vbCrLf
                    
                    objMail.body = strMsg
                    objMail.display() 
                    'objMail.Send()
                    'Clean up
                    objMail = Nothing
                    objOutlk = Nothing
                Next
            Next
        Next
    End Sub
 
Is this code being run on a dual core (or dual processor) machine by chance?
 
...
objOutlk = Nothing
[!]Exit For[/!]
Next
...

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
Yes it is on a dual core currently, but it's not going to run explicitly on them. most will be p3/p4 boxes.
 
Your code sends an email for each processor, thus the double emails. Since Processor Manufacturer and Name should be the same for each processor, PHV's code will only send one email, and exit the loop before it's repeated.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top