dynamic_sysop
Leaders-
Posts
1044 -
Joined
-
Last visited
About dynamic_sysop
- Birthday 08/28/1970
Personal Information
-
Occupation
Senior Support Technician
-
Visual Studio .NET Version
VS 2010
-
.NET Preferred Language
C#
Recent Profile Visitors
52 profile views
dynamic_sysop's Achievements
Newbie (1/14)
0
Reputation
-
DR00ME started following dynamic_sysop
-
Phate2 started following dynamic_sysop
-
m_nathani started following dynamic_sysop
-
who told you that you can NOT Authenticate with System.Net.Mail? i put some simple code together & logged on to gmail & sent an email to another address, all you need to do is set your NetworkCredentials up. some email servers such as yahoo don't seem to work anymore with this method, but the same applies to the old mailclient ( System.Web.Mail ) this is a basic example that may point you in the right direction... [size=2][color=#0000ff]Try[/color][/size] [size=2][color=#0000ff]Dim[/color][/size][size=2] mAddress [/size][size=2][color=#0000ff]As [/color][/size][size=2][color=#0000ff]New[/color][/size][size=2] MailAddress(txtUser.Text, txtUser.Text)[/size] [size=2][color=#0000ff]Dim[/color][/size][size=2] mMessage [/size][size=2][color=#0000ff]As [/color][/size][size=2][color=#0000ff]New[/color][/size][size=2] MailMessage[/size] [size=2][color=#008000]'[/color][/size] [size=2]mMessage.To.Add(txtTo.Text)[/size] [size=2]mMessage.To.Add(txtUser.Text) [color=seagreen]'/// added my own address to the To field[/color][/size] [size=2]mMessage.From = mAddress[/size] [size=2]mMessage.Sender = mAddress[/size] [size=2]mMessage.Subject = txtSubject.Text[/size] [size=2]mMessage.IsBodyHtml = [/size][size=2][color=#0000ff]False[/color][/size] [size=2]mMessage.DeliveryNotificationOptions = DeliveryNotificationOptions.OnSuccess [/size][size=2][color=#0000ff]Or[/color][/size][size=2] DeliveryNotificationOptions.OnFailure[/size] [size=2]mMessage.Priority = MailPriority.High[/size] [size=2]mMessage.Body = rtfBody.Text[/size] [size=2][color=#0000ff]Dim[/color][/size][size=2] client [/size][size=2][color=#0000ff]As [/color][/size][size=2][color=#0000ff]New[/color][/size][size=2] SmtpClient([/size][size=2][color=#a31515]"smtp.googlemail.com"[/color][/size][size=2], 587)[/size] [size=2]client.EnableSsl = [/size][size=2][color=#0000ff]True[/color][/size] [size=2]client.UseDefaultCredentials = [/size][size=2][color=#0000ff]False[/color][/size] [size=2]client.Credentials = [/size][size=2][color=#0000ff]New[/color][/size][size=2] NetworkCredential(txtUser.Text, txtPass.Text)[/size] [size=2]client.Send(mMessage)[/size] [size=2][color=#0000ff]Catch[/color][/size][size=2] ex [/size][size=2][color=#0000ff]As[/color][/size][size=2] Mail.SmtpException[/size] [size=2]Console.WriteLine(ex.Message)[/size] [size=2][color=#0000ff]End [/color][/size][size=2][color=#0000ff]Try[/color][/size]
-
Howdo, I've been working on this for a couple of days, I did a VB.NET example of this on a forum a few years ago, but C# presented me with a new challenge & it took a while to figure out. The Idea is to get hold of an open instance of IE ( IE7 in this case ) & grab hold of it's IHTMLDocument2 Interface, giving the ability to manipulate that external Internet Explorer window / grab it's url address, it's html, make it navigate elsewhere, etc... when this code is added to a project, you must make a reference to Microsoft.mshtml using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Diagnostics; using System.Drawing; using System.Runtime.InteropServices; using System.Text; using System.Windows.Forms; using mshtml; namespace HookBrowser { public partial class Form1 : Form { public Form1() { InitializeComponent(); } #region API CALLS [DllImport("user32.dll", EntryPoint = "GetClassNameA")] public static extern int GetClassName(IntPtr hwnd, StringBuilder lpClassName, int nMaxCount); /*delegate to handle EnumChildWindows*/ public delegate int EnumProc(IntPtr hWnd, ref IntPtr lParam); [DllImport("user32.dll")] public static extern int EnumChildWindows(IntPtr hWndParent, EnumProc lpEnumFunc, ref IntPtr lParam); [DllImport("user32.dll", EntryPoint = "RegisterWindowMessageA")] public static extern int RegisterWindowMessage(string lpString); [DllImport("user32.dll", EntryPoint = "SendMessageTimeoutA")] public static extern int SendMessageTimeout(IntPtr hwnd, int msg, int wParam, int lParam, int fuFlags, int uTimeout, out int lpdwResult); [DllImport("OLEACC.dll")] public static extern int ObjectFromLresult(int lResult, ref Guid riid, int wParam, ref IHTMLDocument2 ppvObject); public const int SMTO_ABORTIFHUNG = 0x2; public Guid IID_IHTMLDocument = new Guid("626FC520-A41E-11CF-A731-00A0C9082637"); #endregion public IHTMLDocument2 document; private void button1_Click(object sender, EventArgs e) { document = documentFromDOM(); /// check that we have hold of the IHTMLDocument2... if (!(bool)(document == null)) { this.Text = document.url; } } private IHTMLDocument2 documentFromDOM() { Process[] processes = Process.GetProcessesByName("iexplore"); if (processes.Length > 0) { IntPtr hWnd = processes[0].MainWindowHandle; int lngMsg = 0; int lRes; EnumProc proc = new EnumProc(EnumWindows); EnumChildWindows(hWnd, proc, ref hWnd); if (!hWnd.Equals(IntPtr.Zero)) { lngMsg = RegisterWindowMessage("WM_HTML_GETOBJECT"); if (lngMsg != 0) { SendMessageTimeout(hWnd, lngMsg, 0, 0, SMTO_ABORTIFHUNG, 1000, out lRes); if (!(bool)(lRes == 0)) { int hr = ObjectFromLresult(lRes, ref IID_IHTMLDocument, 0, ref document); if ((bool)(document == null)) { MessageBox.Show("No IHTMLDocument Found!", "Warning"); } } } } } return document; } private int EnumWindows(IntPtr hWnd, ref IntPtr lParam) { int retVal = 1; StringBuilder classname = new StringBuilder(128); GetClassName(hWnd, classname, classname.Capacity); /// check if the instance we have found is Internet Explorer_Server if ((bool)(string.Compare(classname.ToString(), "Internet Explorer_Server") == 0)) { lParam = hWnd; retVal = 0; } return retVal; } } } :)
-
i finally dug out my VB6 disk. i put together a basic example of how this works in VB6. you must initialize the socket service first using WSAStartup before you can use GetHostName. ( note: gethostbyname returns the IP not the name ) i have comented the code as much as poss. Private Const WS_VERSION_REQD = &H101 Private Type WSADATA wVersion As Integer wHighVersion As Integer szDescription As String * 256 szSystemStatus As String * 128 iMaxSockets As Integer iMaxUdpDg As Integer lpVendorInfo As Long End Type Private Declare Function WSAStartup Lib "ws2_32.dll" (ByVal wVersionRequired As Integer, ByRef lpWSAData As WSADATA) As Long Private Declare Function WSACleanup Lib "WSOCK32.DLL" () As Long Private Declare Function gethostbyname Lib "wsock32" (ByVal szHost As String) As Long Private Declare Function gethostname Lib "ws2_32.dll" (ByVal name As String, ByVal namelen As Long) As Long Private Sub Command1_Click() Dim ws_data As WSADATA Dim lngStart As Long '/// must start up the socket service first... lngStart = WSAStartup(WS_VERSION_REQD, ws_data) '/// -1 means SocketError If lngStart <> -1 Then Dim localhost As String * 256 Dim l As Long l = gethostname(localhost, 256) If l <> -1 Then MsgBox localhost End If End If '/// clean up the socket WSACleanup End Sub hope it helps if you aint already found the answer. :)
-
you need to give your string some space ( the equivalent in .net would be using a stringbuilder ) , basically Dim localhost As String * 256 eg: [color=#b1b100]Public[/color] [color=#b1b100]Declare[/color] [color=#b1b100]Function[/color] gethostbyname Lib [color=#ff0000]"wsock32"[/color] [color=#66cc66]([/color]ByVal szHost [color=#b1b100]As[/color] [color=#b1b100]String[/color][color=#66cc66])[/color] [color=#b1b100]As[/color] [color=#b1b100]Long[/color] [color=#b1b100]Dim[/color] localhost [color=#b1b100]As[/color] [color=#b1b100]String [b]* 256[/b][/color] gethostbyname [color=#66cc66]([/color]localhost[color=#66cc66])[/color] localhost = localhost.[color=#b1b100]Trim[/color][color=#66cc66]([/color][color=#ff0000]"."[/color][color=#66cc66])[/color]
-
it may or maynot be the hotel california, but check the customer reviews ... 1 Star Hotel ;)
-
well you can use a couple of easy ways way 1: [size=2] [/size][size=2][color=#2b91af]Console[/color][/size][size=2].WriteLine([/size][size=2][color=#2b91af]DateTime[/color][/size][size=2].Compare(System.IO.[/size][size=2][color=#2b91af]File[/color][/size][size=2].GetCreationTime([/size][size=2][color=#a31515]"C:\\B156_FSM.pdf"[/color][/size][size=2]), System.IO.[/size][size=2][color=#2b91af]File[/color][/size][size=2].GetCreationTime([/size][size=2][color=#a31515]"C:\\YServer.txt"[/color][/size][size=2]))); [/size] basically you will get a return of 1 or -1 ( maybe 0 if both had identical times, but don't quote me on that ) way 2: [size=2][/size][size=2][color=#2b91af]Console[/color][/size][size=2].WriteLine( [/size][size=2][color=#2b91af]DateTime[/color][/size][size=2].Compare([/size][size=2][color=#2b91af]DateTime[/color][/size][size=2].FromFileTime(' the long filetime value here !!! '), [/size][size=2][color=#2b91af]DateTime[/color][/size][size=2].FromFileTime(' the long filetime value here !!! ')) ); [/size][size=2][color=#008000][/color][/size] hope it helps.
-
i put an example in the codebank over 2 years ago of being able to close the main form that loads without shutting the app down, the vbcode looks a bit screwed up because of messed up colour tags, but here's the link a readable code is found on an external link to vbforums here a very basic source example is included. regards.
-
you are trying to delete the path name with \*.txt attached to the end of it there, not the actuall files, also you need to delete them 1 by 1 it can be done easily like this... For Each f As String In System.IO.Directory.GetFiles(My.Application.Info.DirectoryPath, "*.txt") My.Computer.FileSystem.DeleteFile(f) Next
-
you should be using AppendText not " richtextbox.text = " if you use the following you should see it work... Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click RichTextBox1.AppendText("blabla ") RichTextBox1.AppendText("something else") End Sub Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click RichTextBox1.Undo() End Sub
-
System.IO.FileInfo and image attributes
dynamic_sysop replied to Mondeo's topic in Directory / File IO / Registry
you need to be looking at " System.Drawing.Imaging.PropertyItem " if you look at the Image class you will see that there is a field called PropertyItems, eg: Dim img As Image = Image.FromFile("E:\Image1.jpg") For Each propItem As System.Drawing.Imaging.PropertyItem In img.PropertyItems '/// here you can look at the value of each properyitem ( height , etc... ) '/// you need to determine what the value is ( string, byte, byte array, etc... by it's ID ) '/// there's a list if ID tags on msdn here ---> [url="http://msdn2.microsoft.com/en-us/library/system.drawing.imaging.propertyitem.id.aspx"]ID TAGS[/url] <--- Next look for 0x0100 PropertyTagImageWidth in the list on the link --> ID TAGS <-- for example, that should show your image width, you can see every detail of an image using PropertyItems. hope it helps :) -
there are a couple of examples on downloading files in the codebank, my example was used to download an image, i've simpley replaced the image name with an exe ( in this case windows messenger live on microsoft's site ) with it i downloaded the complete exe which you can launch. Private Sub download() Try Dim exepath As String = "[url]http://download.microsoft.com/download/1/A/4/1A4FEB1A-18E0-423A-B898-F697402E4F7F/Install_Messenger_nous.exe[/url]" '/// "[url]http://g.msn.com/8reen_us/EN_NOUS/INSTALL_MSN_MESSENGER_DL.EXE[/url]" Dim wRequest As HttpWebRequest = DirectCast(HttpWebRequest.Create(exepath), HttpWebRequest) Dim wResponse As WebResponse = DirectCast(wRequest.GetResponse(), WebResponse) Dim sWriter As FileStream = New FileStream("c:\msgr.exe", FileMode.OpenOrCreate) Dim ContentLength As Integer = wResponse.ContentLength Dim sizeInKB As String = (ContentLength / 1024).ToString() Me.Text = "The Size of the file is: " & sizeInKB.Substring(0, sizeInKB.IndexOf(".") + 3) & "KB" Dim buffer(ContentLength) As Byte Dim length As Integer = ContentLength Dim position As Integer = 0 Dim complete As Integer = 1 Dim returned As Integer = 0 ProgressBar1.Value = 0 '/// clear the progressbar. ProgressBar1.Maximum = ContentLength '/// set it's length. While Not complete = 0 position = wResponse.GetResponseStream().Read(buffer, returned, length) sWriter.Write(buffer, returned, position) complete = position returned += position length -= position ProgressBar1.Step = returned ProgressBar1.PerformStep() End While Me.Text = "Completed download" sWriter.Close() wRequest = Nothing Catch ex As Exception Console.WriteLine(ex.Message) Catch webex As WebException Console.WriteLine(webex.Message) End Try End Sub
-
Progressbar won't change by ProgressChanged from a BackgroundWorker
dynamic_sysop replied to Arokh's topic in Windows Forms
when using a BackgroundWorker, you may want to look at creating a Delegate Sub to handle the progress etc... rather than using the DoWork function. eg: '/// the backgroundworker... Private WithEvents bgworker As BackgroundWorker '/// the Delegate to handle progress... Private Delegate Sub download(ByVal wRequest As HttpWebRequest, ByVal wResponse As WebResponse, ByVal bar As ProgressBar) Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click bgworker = New BackgroundWorker bgworker.RunWorkerAsync(Me) End Sub Private Sub bgworker_DoWork(ByVal sender As Object, ByVal e As System.ComponentModel.DoWorkEventArgs) Handles bgworker.DoWork Dim imgPath As String = "[url]http://www.google.com/images/logo.gif[/url]" Dim wRequest As HttpWebRequest = DirectCast(HttpWebRequest.Create(imgPath), HttpWebRequest) Dim wResponse As WebResponse = DirectCast(wRequest.GetResponse(), WebResponse) Dim dl As New download(AddressOf downloadimage) '/// make an array of the arguments required. Dim objArgs As Object() = {wRequest, wResponse, ProgressBar1} '/// invoke the delegate sub to handle the download / progress. Me.Invoke(dl, objArgs) End Sub Private Sub downloadimage(ByVal wRequest As HttpWebRequest, ByVal wResponse As WebResponse, ByVal pBar As ProgressBar) Try Dim sWriter As FileStream = New FileStream("new.gif", FileMode.OpenOrCreate) Dim ContentLength As Integer = wResponse.ContentLength Dim sizeInKB As String = (ContentLength / 1024).ToString() Me.Text = "The Size of the Image is: " & sizeInKB.Substring(0, sizeInKB.IndexOf(".") + 3) & "KB" Dim buffer(ContentLength) As Byte Dim length As Integer = ContentLength Dim position As Integer = 0 Dim complete As Integer = 1 Dim returned As Integer = 0 pBar.Value = 0 '/// clear the progressbar. pBar.Maximum = ContentLength '/// set it's length. While Not complete = 0 position = wResponse.GetResponseStream().Read(buffer, returned, length) sWriter.Write(buffer, returned, position) complete = position returned += position length -= position pBar.Step = returned pBar.PerformStep() End While Me.Text = "Completed download" sWriter.Close() wRequest = Nothing MessageBox.Show("Complete!") Catch ex As Exception Console.WriteLine(ex.Message) End Try End Sub hope it helps. -
don't forget you need 2 X VbCrlf at the end of http data, if i remember it's also advised to add the Host property in the header & i know from experience that some sites won't allow anything to happen unless they have the correct refferer url, so you may want to specify that also.
-
�AddressOf� expression cannot be converted to �Integer�
dynamic_sysop replied to MadMaxMSCN's topic in General
first you need to make a delegate function ( YOU MUST NAME IT DIFFERENTLY TO YOUR ACTUAL FUNCTION ) ie: [size=2][color=#0000ff]Private [/color][/size][size=2][color=#0000ff]Delegate [/color][/size][size=2][color=#0000ff]Function[/color][/size][size=2] WProc([/size][size=2][color=#0000ff]ByVal[/color][/size][size=2] pHWnd [/size][size=2][color=#0000ff]As [/color][/size][size=2][color=#0000ff]Integer[/color][/size][size=2], [/size][size=2][color=#0000ff]ByVal[/color][/size][size=2] pMsg [/size][size=2][color=#0000ff]As [/color][/size][size=2][color=#0000ff]Integer[/color][/size][size=2], [/size][size=2][color=#0000ff]ByVal[/color][/size][size=2] wParam [/size][size=2][color=#0000ff]As [/color][/size][size=2][color=#0000ff]Integer[/color][/size][size=2], [/size][size=2][color=#0000ff]ByVal[/color][/size][size=2] lParam [/size][size=2][color=#0000ff]As [/color][/size][size=2][color=#0000ff]Integer[/color][/size][size=2]) [/size][size=2][color=#0000ff]As [/color][/size][size=2][color=#0000ff]Integer[/color][/size] [size=2][color=#0000ff] [/color]then modify the SetWindowLong API so the last parameter is WProc as above ie: [size=2][/size][size=2][color=#0000ff]Private [/color][/size][size=2][color=#0000ff]Declare [/color][/size][size=2][color=#0000ff]Function[/color][/size][size=2] SetWindowLong [/size][size=2][color=#0000ff]Lib[/color][/size][size=2] "user32.dll" [/size][size=2][color=#0000ff]Alias[/color][/size][size=2] "SetWindowLongA" ([/size][size=2][color=#0000ff]ByVal[/color][/size][size=2] hwnd [/size][size=2][color=#0000ff]As[/color][/size][size=2] Int32, [/size][size=2][color=#0000ff]ByVal[/color][/size][size=2] nIndex [/size][size=2][color=#0000ff]As[/color][/size][size=2] Int32, [/size][size=2][color=#0000ff]ByVal[/color][/size][size=2] dwNewLong [/size][size=2][color=#0000ff]As[/color][/size][size=2] WProc) [/size][size=2][color=#0000ff]As[/color][/size][size=2] Int32[/size] [size=2][/size] then your code will work, here's a quick example ... [size=2][color=#0000ff]Private [/color][/size][size=2][color=#0000ff]Const[/color][/size][size=2] GWL_WNDPROC [/size][size=2][color=#0000ff]As[/color][/size][size=2] Int32 = -4[/size] [size=2] [/size][size=2][color=#0000ff]Private [/color][/size][size=2][color=#0000ff]Declare [/color][/size][size=2][color=#0000ff]Function[/color][/size][size=2] SetWindowLong [/size][size=2][color=#0000ff]Lib[/color][/size][size=2] "user32.dll" [/size][size=2][color=#0000ff]Alias [/color][/size][size=2]"SetWindowLongA" ([/size][size=2][color=#0000ff]ByVal[/color][/size][size=2] hwnd [/size][size=2][color=#0000ff]As[/color][/size][size=2] Int32, [/size][size=2][color=#0000ff]ByVal[/color][/size][size=2] nIndex [/size][size=2][color=#0000ff]As[/color][/size][size=2] Int32, [/size][size=2][color=#0000ff]ByVal[/color][/size][size=2] dwNewLong [/size][size=2][color=#0000ff]As[/color][/size][size=2] WProc) [/size][size=2][color=#0000ff]As[/color][/size][size=2] Int32[/size] [size=2] [/size][size=2][color=#0000ff]Private [/color][/size][size=2][color=#0000ff]Delegate [/color][/size][size=2][color=#0000ff]Function[/color][/size][size=2] WProc([/size][size=2][color=#0000ff]ByVal[/color][/size][size=2] pHWnd [/size][size=2][color=#0000ff]As [/color][/size][size=2][color=#0000ff]Integer[/color][/size][size=2], [/size][size=2][color=#0000ff]ByVal[/color][/size][size=2] pMsg [/size][size=2][color=#0000ff]As [/color][/size][size=2][color=#0000ff]Integer[/color][/size][size=2], [/size][size=2][color=#0000ff]ByVal[/color][/size][size=2] wParam [/size][size=2][color=#0000ff]As [/color][/size][size=2][color=#0000ff]Integer[/color][/size][size=2], [/size][size=2][color=#0000ff]ByVal[/color][/size][size=2] lParam [/size][size=2][color=#0000ff]As [/color][/size][size=2][color=#0000ff]Integer[/color][/size][size=2]) [/size][size=2][color=#0000ff]As [/color][/size][size=2][color=#0000ff]Integer[/color][/size] [size=2][color=#0000ff] [/color][/size][size=2][color=#0000ff]Private[/color][/size][size=2] FPrevWinProc [/size][size=2][color=#0000ff]As [/color][/size][size=2][color=#0000ff]Integer[/color][/size] [size=2][color=#0000ff] [/color][/size][size=2][color=#0000ff]Private [/color][/size][size=2][color=#0000ff]Function[/color][/size][size=2] WinProc([/size][size=2][color=#0000ff]ByVal[/color][/size][size=2] pHWnd [/size][size=2][color=#0000ff]As [/color][/size][size=2][color=#0000ff]Integer[/color][/size][size=2], [/size][size=2][color=#0000ff]ByVal[/color][/size][size=2] pMsg [/size][size=2][color=#0000ff]As [/color][/size][size=2][color=#0000ff]Integer[/color][/size][size=2], [/size][size=2][color=#0000ff]ByVal[/color][/size][size=2] wParam [/size][size=2][color=#0000ff]As [/color][/size][size=2][color=#0000ff]Integer[/color][/size][size=2], [/size][size=2][color=#0000ff]ByVal[/color][/size][size=2] lParam [/size][size=2][color=#0000ff]As [/color][/size][size=2][color=#0000ff]Integer[/color][/size][size=2]) [/size][size=2][color=#0000ff]As [/color][/size][size=2][color=#0000ff]Integer[/color][/size] [size=2][color=#0000ff] [/color][/size] [size=2][color=#008000] [/color][/size][size=2][color=#0000ff]End [/color][/size][size=2][color=#0000ff]Function[/color][/size] [size=2][color=#0000ff] [/color][/size][size=2][color=#0000ff]Private [/color][/size][size=2][color=#0000ff]Sub[/color][/size][size=2] Button1_Click([/size][size=2][color=#0000ff]ByVal[/color][/size][size=2] sender [/size][size=2][color=#0000ff]As[/color][/size][size=2] System.Object, [/size][size=2][color=#0000ff]ByVal[/color][/size][size=2] e [/size][size=2][color=#0000ff]As[/color][/size][size=2] System.EventArgs) [/size][size=2][color=#0000ff]Handles[/color][/size][size=2] Button1.Click[/size] [size=2] [/size][size=2][color=#0000ff]Dim[/color][/size][size=2] FWinHandle [/size][size=2][color=#0000ff]As[/color][/size][size=2] Int32 = [/size][size=2][color=#0000ff]MyBase[/color][/size][size=2].Handle.ToInt32[/size] [size=2] FPrevWinProc = SetWindowLong(FWinHandle, GWL_WNDPROC, [/size][size=2][color=#0000ff]AddressOf[/color][/size][size=2] WinProc)[/size] [size=2] [/size][size=2][color=#0000ff]End [/color][/size][size=2][color=#0000ff]Sub [/color][/size] hope that explains things alittle [/size] -
marble, you forgot ' patient ' in that list ;) . Patient :