Ejemplo para monitorear la ejecución de los procesos del sistema:
Public Class Form1
Private WithEvents ProcessStartWatcher As ManagementEventWatcher =
New ManagementEventWatcher(
New WqlEventQuery("SELECT * FROM Win32_ProcessStartTrace"))
Private WithEvents ProcessStopWatcher As ManagementEventWatcher =
New System.Management.ManagementEventWatcher(
New WqlEventQuery("SELECT * FROM Win32_ProcessStopTrace"))
Private Shadows Sub Load() Handles MyBase.Load
ProcessStartWatcher.Start()
ProcessStopWatcher.Start()
End Sub
Private Shadows Sub Closing() Handles MyBase.Closing
ProcessStartWatcher.Stop()
ProcessStopWatcher.Stop()
End Sub
Public Sub ProcessStartWatcher_EventArrived(ByVal sender As Object, ByVal e As EventArrivedEventArgs) _
Handles ProcessStartWatcher.EventArrived
MsgBox(String.Format("Process started: {0}",
e.NewEvent.Properties("ProcessName").Value))
End Sub
Private Sub ProcessStopWatcher_Stopped(ByVal sender As Object, ByVal e As EventArrivedEventArgs) _
Handles ProcessStopWatcher.EventArrived
MsgBox(String.Format("Process stopped: {0}",
e.NewEvent.Properties("ProcessName").Value))
End Sub
End Class
Modificar el proxy de un GeckoFX Webbrowser:
' By Elektro
''' <summary>
''' ProxyTypes of Gecko webbrowser.
''' </summary>
Public Enum ProxyType
''' <summary>
''' Direct connection, no proxy.
''' (Default in Windows and Mac previous to 1.9.2.4 /Firefox 3.6.4)
''' </summary>
DirectConnection = 0
''' <summary>
''' Manual proxy configuration.
''' </summary>
Manual = 1
''' <summary>
''' Proxy auto-configuration (PAC).
''' </summary>
AutoConfiguration = 2
''' <summary>
''' Auto-detect proxy settings.
''' </summary>
AutoDetect = 4
''' <summary>
''' Use system proxy settings.
''' (Default in Linux; default for all platforms, starting in 1.9.2.4 /Firefox 3.6.4)
''' </summary>
System = 5
End Enum
''' <summary>
''' Sets the proxy type of a Gecko Webbrowser.
''' </summary>
''' <param name="ProxyType">Indicates the type of proxy.</param>
Private Sub SetGeckoProxyType(ByVal ProxyType As ProxyType)
GeckoPreferences.Default("network.proxy.type") = ProxyType
End Sub
''' <summary>
''' Sets the proxy of a Gecko Webbrowser.
''' </summary>
''' <param name="Host">Indicates the proxy host.</param>
''' <param name="Port">Indicates the proxy port.</param>
Private Sub SetGeckoProxy(ByVal Host As String,
ByVal Port As Integer)
' Set the ProxyType to manual configuration.
GeckoPreferences.Default("network.proxy.type") = ProxyType.Manual
' Set the HTP proxy Host and Port.
GeckoPreferences.Default("network.proxy.http") = Host
GeckoPreferences.Default("network.proxy.http_port") = Port
' Set the SSL proxy Host and Port.
GeckoPreferences.Default("network.proxy.ssl") = Host
GeckoPreferences.Default("network.proxy.ssl_port") = Port
End Sub
Devuelve un String con el source de una página
' Get SourcePage String
' ( By Elektro )
'
' Usage Examples:
' MsgBox(GetSourcePageString("http://www.elhacker.net"))
'
''' <summary>
''' Gets a web source page.
''' </summary>
''' <param name="URL">Indicates the source page URL to get.</param>
''' <returns>System.String.</returns>
''' <exception cref="Exception"></exception>
Private Function GetSourcePageString(ByVal URL As String) As String
Try
Using StrReader As New IO.StreamReader(Net.HttpWebRequest.Create(URL).GetResponse().GetResponseStream)
Return StrReader.ReadToEnd
End Using
Catch ex As Exception
Throw New Exception(ex.Message)
Return Nothing
End Try
End Function
Devuelve un Array con el source de una página:
' Get SourcePage Array
' ( By Elektro )
'
' Usage Examples:
' Dim SourceLines As String() = GetSourcePageArray("http://www.ElHacker.net", TrimLines:=True)
' For Each Line As String In SourceLines : MsgBox(Line) : Next Line
'
''' <summary>
''' Gets a web source page.
''' </summary>
''' <param name="URL">Indicates the source page URL to get.</param>
''' <param name="TrimLines">Indicates whether to trim the lines.</param>
''' <param name="SplitOptions">Indicates the split options.</param>
''' <returns>System.String[][].</returns>
''' <exception cref="Exception"></exception>
Private Function GetSourcePageArray(ByVal URL As String,
Optional ByVal TrimLines As Boolean = False,
Optional ByVal SplitOptions As StringSplitOptions =
StringSplitOptions.None) As String()
Try
Using StrReader As New IO.StreamReader(Net.HttpWebRequest.Create(URL).GetResponse().GetResponseStream)
If TrimLines Then
Return (From Line As String
In StrReader.ReadToEnd.Split({Environment.NewLine}, SplitOptions)
Select Line.Trim).ToArray
Else
Return StrReader.ReadToEnd.Split({Environment.NewLine}, SplitOptions)
End If
End Using
Catch ex As Exception
Throw New Exception(ex.Message)
Return Nothing
End Try
End Function
Devuelve el directorio de un proceso en ejecución
' Get Process Path
' ( By Elektro )
'
' Usage Examples:
' MsgBox(GetProcessPath("notepad.exe").First)
'
''' <summary>
''' Gets the absolute path of a running process.
''' </summary>
''' <param name="ProcessName">Indicates the name of the process.</param>
''' <returns>System.String[][].</returns>
''' <exception cref="Exception">ProcessName parametter can't be Null.</exception>
Public Function GetProcessPath(ByVal ProcessName As String) As String()
If ProcessName.EndsWith(".exe", StringComparison.OrdinalIgnoreCase) Then
ProcessName = ProcessName.Remove(ProcessName.Length - 4)
End If
Return (From p As Process In Process.GetProcesses
Where p.ProcessName.Equals(ProcessName, StringComparison.OrdinalIgnoreCase)
Select p.MainModule.FileName).ToArray
End Function
Desordena un archivo de texto y devuelve un String
' Randomize TextFile String
' ( By Elektro )
'
' Usage Examples:
' MsgBox(RandomizeTextFileString("C:\File.txt", Encoding:=Nothing)))
'
''' <summary>
''' Randomizes the contents of a text file.
''' </summary>
''' <param name="TextFile">Indicates the text file to randomize.</param>
''' <param name="Encoding">Indicates the text encoding to use.</param>
''' <returns>System.String.</returns>
Public Function RandomizeTextFileString(ByVal TextFile As String,
Optional ByVal Encoding As System.Text.Encoding = Nothing) As String
Dim Randomizer As New Random
Return String.Join(Environment.NewLine,
(From Item As String
In IO.
File.
ReadAllLines(TextFile,
If(Encoding Is Nothing, System.Text.Encoding.Default, Encoding))
Order By Randomizer.Next))
End Function
Desordena un archivo d etexto y devuelve un Array:
' Randomize TextFile Array
' ( By Elektro )
'
' Usage Examples:
' MsgBox(RandomizeTextFileArray("C:\File.txt", Encoding:=Nothing).First))
'
''' <summary>
''' Randomizes the contents of a text file.
''' </summary>
''' <param name="TextFile">Indicates the text file to randomize.</param>
''' <param name="Encoding">Indicates the text encoding to use.</param>
''' <returns>System.String[].</returns>
Public Function RandomizeTextFileArray(ByVal TextFile As String,
Optional ByVal Encoding As System.Text.Encoding = Nothing) As String()
Dim Randomizer As New Random
Return (From Item As String
In IO.
File.
ReadAllLines(TextFile,
If(Encoding Is Nothing, System.Text.Encoding.Default, Encoding))
Order By Randomizer.Next).ToArray
End Function