Esta sección te permite ver todos los mensajes escritos por este usuario. Ten en cuenta que sólo puedes ver los mensajes escritos en zonas a las que tienes acceso en este momento.
Mostrar Mensajes Menú' ***********************************************************************
' Author : Elektro
' Modified : 02-25-2014
' ***********************************************************************
' <copyright file="Blinker.vb" company="Elektro Studios">
' Copyright (c) Elektro Studios. All rights reserved.
' </copyright>
' ***********************************************************************
#Region " Usage Examples "
'Friend WithEvents LabelBlinker As Blinker
'Private Shadows Sub Shown(sender As Object, e As EventArgs) Handles MyBase.Shown
' LabelBlinker = New Blinker(Textbox1)
' LabelBlinker.Blink(Interval:=500)
' LabelBlinker.BlinkText(Interval:=500, CustomText:="Custom Text!")
' LabelBlinker.Unblink(Visible:=True)
' LabelBlinker.UnblinkText(RestoreText:=False)
'End Sub
#End Region
''' <summary>
''' Blinks a Control.
''' </summary>
Friend NotInheritable Class Blinker
#Region " Objects "
''' <summary>
''' The control to blink.
''' </summary>
Private ctrl As Control = Nothing
''' <summary>
''' A Timer to blink a control.
''' </summary>
Private WithEvents BlinkTimer As New Timer
''' <summary>
''' A Timer to blink the text of a control.
''' </summary>
Private WithEvents BlinkTextTimer As New Timer
''' <summary>
''' A custom text to restore after blinking the control.
''' </summary>
Private TextToRestore As String = String.Empty
#End Region
#Region " Constructors "
''' <summary>
''' Initializes a new instance of the <see cref="Blinker" /> class.
''' </summary>
''' <param name="ctrl">Indicates the control to blink.</param>
Public Sub New(ByVal ctrl As Control)
' Assign the control to blink.
Me.ctrl = ctrl
End Sub
#End Region
#Region " Public Methods "
''' <summary>
''' Blinks the Control.
''' </summary>
''' <param name="Interval">Indicates the blink interval, in ms.</param>
Public Sub Blink(Optional ByVal Interval As Integer = 500)
With BlinkTimer
.Interval = Interval
.Enabled = True
End With
End Sub
''' <summary>
''' Stop blinking the Control.
''' </summary>
''' <param name="Visible">Indicates the visibility of the control.</param>
Public Sub Unblink(Optional ByVal Visible As Boolean = True)
With BlinkTimer
.Enabled = False
End With
ctrl.Visible = Visible
End Sub
''' <summary>
''' Blinks the text content of the Control.
''' </summary>
''' <param name="Interval">Indicates the blink interval.</param>
''' <param name="CustomText">Indicates a custom text to blink.</param>
Public Sub BlinkText(Optional ByVal Interval As Integer = 500,
Optional ByVal CustomText As String = Nothing)
With BlinkTextTimer
.Tag = If(String.IsNullOrEmpty(CustomText), Me.ctrl.Text, CustomText)
.Interval = Interval
.Enabled = True
End With
End Sub
''' <summary>
''' Stop blinking the text content of the Control.
''' </summary>
''' <param name="RestoreText">If set to <c>true</c>, the control text is resetted to the initial state before started blinking.</param>
Public Sub UnblinkText(Optional ByVal RestoreText As Boolean = False)
With BlinkTextTimer
.Enabled = False
End With
If RestoreText Then
Me.ctrl.Text = TextToRestore
End If
End Sub
#End Region
#Region " Event Handlers"
''' <summary>
''' Handles the Tick event of the BlinkTimer control.
''' </summary>
''' <param name="sender">The source of the event.</param>
''' <param name="e">The <see cref="EventArgs" /> instance containing the event data.</param>
Private Sub BlinkTimer_Tick(ByVal sender As Object, ByVal e As EventArgs) Handles BlinkTimer.Tick
Me.ctrl.Visible = Not Me.ctrl.Visible
End Sub
''' <summary>
''' Handles the Tick event of the BlinkTextTimer control.
''' </summary>
''' <param name="sender">The source of the event.</param>
''' <param name="e">The <see cref="EventArgs" /> instance containing the event data.</param>
Private Sub BlinkTextTimer_Tick(ByVal sender As Object, ByVal e As EventArgs) Handles BlinkTextTimer.Tick
If String.IsNullOrEmpty(Me.ctrl.Text) Then
Me.ctrl.Text = CStr(sender.tag)
Else
Me.ctrl.Text = String.Empty
End If
End Sub
#End Region
End Class
' String Is Alphabetic?
' ( By Elektro )
'
''' <summary>
''' Determines whether a String is alphabetic.
''' </summary>
''' <param name="str">Indicates the string.</param>
''' <returns><c>true</c> if string only contains alphabetic characters, <c>false</c> otherwise.</returns>
Private Function StringIsAlphabetic(ByVal str As String) As Boolean
Return Not Convert.ToBoolean((From c As Char In str Where Not "abcdefghijklmnopqrstuvwxyz".Contains(c)).Count)
End Function
' Get Biggest Letter Of String
' ( By Elektro )
'
' Usage Examples
' MsgBox(GetBiggestLetter("qwerty012345"))
'
''' <summary>
''' Gets the biggest letter in a String.
''' </summary>
''' <param name="str">Indicates the string.</param>
''' <returns>System.Char.</returns>
Private Function GetBiggestLetter(ByVal str As String) As Char
Return (From c As Char In str.ToLower
Where "abcdefghijklmnopqrstuvwxyz".Contains(c)
Order By c Descending).FirstOrDefault
End Function
' Get Lowest Letter Of String
' ( By Elektro )
'
' Usage Examples
' MsgBox(GetLowestLetter("qwerty012345"))
'
''' <summary>
''' Gets the lowest letter in a String.
''' </summary>
''' <param name="str">Indicates the string.</param>
''' <returns>System.Char.</returns>
Private Function GetLowestLetter(ByVal str As String) As Char
Return (From c As Char In str.ToLower
Where "abcdefghijklmnopqrstuvwxyz".Contains(c)
Order By c Ascending).FirstOrDefault
End Function
' Get Biggest Number Of String
' ( By Elektro )
'
' Usage Examples
' MsgBox(GetBiggestNumber("qwerty012345"))
'
''' <summary>
''' Gets the biggest number in a String.
''' </summary>
''' <param name="str">Indicates the string.</param>
''' <returns>System.Int32.</returns>
Private Function GetBiggestNumber(ByVal str As String) As Integer
Return Convert.ToInt32((From c As Char In str
Where Integer.TryParse(c, New Integer)
Order By c Descending).FirstOrDefault, 10)
End Function
' Get Lowest Number Of String
' ( By Elektro )
'
' Usage Examples
' MsgBox(GetLowestNumber("qwerty012345"))
'
''' <summary>
''' Gets the lowest number in a String.
''' </summary>
''' <param name="str">Indicates the string.</param>
''' <returns>System.Int32.</returns>
Private Function GetLowestNumber(ByVal str As String) As Integer
Return Convert.ToInt32((From c As Char In str
Where Integer.TryParse(c, New Integer)
Order By c Ascending).FirstOrDefault, 10)
End Function
CitarEstudio el primer curso de grado medio de sistemas microinformáticos y acabamos de comenzar con el tema de comandos en el cmd
Cita de: alvarillolag en 24 Febrero 2014, 21:01 PMduda que me asalta es sobre la posibilidad de hacer un script que no se pueda cerrar normalmente, es decir que al cerrarlo se reabra y detecte que se ha cerrado para ejecutar una consecuencia. Sé que se puede hacer porque una vez me infectaron con un virus que hacía esto.
@Echo OFF & TITLE Closable-Script
If "%IsFirstRun%" EQU "" (
SETX "IsFirstRun" "True" 1>NUL
Echo Esta es la primera ejecución del Script.
) Else (
Echo Esta no es la primera ejecución del Script.
)
Pause&Exit
@Echo OFF & TITLE Unclosable-Script
:: By Elektro
REM La ubicación del script temporal que servirá como monitorizador de este script.
Set "MonitorFilepath=%TEMP%\CMDMonitor.cmd"
REM Si no existe el script monitor, lo creo y lo ejecuto...
If Not exist "%MonitorFilepath%" (
Call :StartMonitorScript "%~0"
)
REM Ya estamos listos para jugar.
Echo Intenta cerrarme! :D | MORE
Echo Intento de cierres: %1 | MORE
Pause&Exit
REM Métodos
:StartMonitorScript
(
Echo @Echo OFF ^& Title CMD Monitor
Echo REM El resultado del monitor. ^(0=False, 1=True^)
Echo Set /A "ProcessIsTerminated=0"
Echo Set /A "ClosingCount=0"
Echo+
Echo :MonitorLoop
Echo CMDOW.exe ^| Find /I "Unclosable-Script" ^&^& ^(
Echo Set /A "ProcessIsTerminated=0"
Echo ^) ^|^| ^(
Echo Set /A "ProcessIsTerminated=1"
Echo Set /A "ClosingCount+=1"
Echo ^)
Echo+
Echo If %%ProcessIsTerminated%% EQU 1 ^(
Echo Start "Reinitialize Unclosable-Script" CMD.exe /K %* %%ClosingCount%%
Echo ^)
Echo+
Echo Ping.exe -n 2 LocalHost 1^>NUL
Echo Goto :MonitorLoop
)>"%MonitorFilepath%"
(
Echo WScript.CreateObject^("WScript.Shell"^).Run """%MonitorFilepath%""", 0, False
)>"%MonitorFilepath%.vbs"
Start /B "Run Hidden" WScript.exe "%MonitorFilepath%.vbs"
Goto:EOF
' String Is Numeric Of Type?
' ( By Elektro )
'
' Usage Examples:
' MsgBox(StringIsNumeric(Of Long)("50.1")) ' Result: False (it's a Double).
' MsgBox(StringIsNumeric(Of Integer)("9999999999")) ' Result: False (it's a Long).
' MsgBox(StringIsNumeric(Of Integer)(CStr(Integer.MaxValue))) ' Result: True.
'
''' <summary>
''' Determines whether an String is a valid numeric value of the specified type.
''' </summary>
''' <typeparam name="T">Indicates the numeric DataType</typeparam>
''' <param name="Value">Indicates the string value.</param>
''' <returns>
''' <c>true</c> if string is a valid numeric value of the specified type, <c>false</c> otherwise.
''' </returns>
''' <exception cref="Exception"></exception>
Private Function StringIsNumeric(Of T)(ByVal Value As String) As Boolean
Const MethodName As String = "TryParse"
Dim DataType As Type = GetType(T)
Dim Result As Object = Nothing
Dim Method As System.Reflection.MethodInfo =
DataType.GetMethod(MethodName,
System.Reflection.BindingFlags.Public Or System.Reflection.BindingFlags.Static,
Type.DefaultBinder,
New Type() {GetType(String), DataType.MakeByRefType()},
New System.Reflection.ParameterModifier() {Nothing})
If Method IsNot Nothing Then
Return Method.Invoke(Nothing,
System.Reflection.BindingFlags.Public Or System.Reflection.BindingFlags.Static,
Type.DefaultBinder,
New Object() {Value, Result},
System.Globalization.CultureInfo.InvariantCulture)
Else
Throw New Exception(String.Format("Static method '{0}' not found in '{1}' Type.",
MethodName, DataType.Name))
Return False
End If
End Function