elhacker.net cabecera Bienvenido(a), Visitante. Por favor Ingresar o Registrarse
¿Perdiste tu email de activación?.


Tema destacado: Security Series.XSS. [Cross Site Scripting]


  Mostrar Mensajes
Páginas: 1 ... 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 [956] 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 ... 1254
9551  Programación / .NET (C#, VB.NET, ASP) / Re: Calcular el tiempo restante en: 18 Marzo 2013, 19:49 pm
Ya está solucionado...

Cambiar:
Código:
RemainingTime = Now().Subtract(EndTime)

Por:
Código:
RemainingTime = EndTime.Subtract(Now)

Saludos.
9552  Programación / .NET (C#, VB.NET, ASP) / [SOLUCIONADO] Calcular el tiempo restante en: 18 Marzo 2013, 18:34 pm
Lo del tiempo transcurrido lo tengo manejado ya, pero para mostrar el tiempo restante me estoy haciendo un lío...

Código
  1.    Dim time_out as integer = 60000 ' 'Milisegundos
  2.  
  3.    Dim StartTime As DateTime ' Tiempo inicio
  4.    Dim EndTime As DateTime ' Tiempo final
  5.  
  6.    Dim ElapsedTime As TimeSpan ' Tiempo transcurrido
  7.    Dim RemainingTime As TimeSpan ' Tiempo restante

He conseguido mostrar el tiempo restante pero de una manera extraña, el problema es que, aparte de que los valores se muestran negativos, el valor de la hora y el minutero deberían ser "00"... ya que sólo estoy intentando medir el tiempo restante de una operación de "10000" MS (10 segs)

Output:


Este es el code que uso, ¿Como lo arreglo?
Código
  1. #Region " Elapsed Time Function "
  2.  
  3.    Public Function Print_Elapsed_Time()
  4.        If StartTime.ToString = "01/01/0001 0:00:00" Then
  5.            StartTime = Now
  6.            StartTime = StartTime.AddSeconds(-1)
  7.        End If
  8.        ElapsedTime = Now().Subtract(StartTime)
  9.        Return String.Format("{0:00}:{1:00}:{2:00}", CInt(Math.Floor(ElapsedTime.TotalHours)) Mod 60, CInt(Math.Floor(ElapsedTime.TotalMinutes)) Mod 60, CInt(Math.Floor(ElapsedTime.TotalSeconds)) Mod 60)
  10.    End Function
  11. #End Region
  12.  
  13. #Region " Remaining Time Function "
  14.  
  15.    Public Function Print_Remaining_Time()
  16.        If EndTime.ToString = "01/01/0001 0:00:00" Then
  17.            EndTime = Now
  18.            EndTime = EndTime.AddMilliseconds(Time_Out - 1000)
  19.        End If
  20.        RemainingTime = Now().Subtract(EndTime)
  21.        Return String.Format("{0:00}:{1:00}:{2:00}", CInt(Math.Floor(RemainingTime.TotalHours)) Mod 60, CInt(Math.Floor(RemainingTime.TotalMinutes)) Mod 60, CInt(Math.Floor(RemainingTime.TotalSeconds)) Mod 60)
  22.    End Function
  23.  
  24. #End Region
9553  Programación / .NET (C#, VB.NET, ASP) / Re: Ayuda con esta excepción! (my.settings) en: 18 Marzo 2013, 18:02 pm
Ya lo he arreglado, lo que pasa es que tenia unas carpetas con el mismo nombre de proyecto en el directorio Roaming, pero el VS debería preveer estas cosas...

Saludos!
9554  Informática / Software / Re: Configuracion de Google Chrome en: 18 Marzo 2013, 14:12 pm

xD



Código:
"...\AppData\Local\Google\Chrome\User Data"

Si no quieres complicarte, también puedes usar aplicaciones para hacer backups de Chrome, como esta: http://google-chrome-backup.en.softonic.com/

Saludos.
9555  Programación / .NET (C#, VB.NET, ASP) / [SOLUCIONADO] Ayuda con esta excepción! (my.settings) en: 18 Marzo 2013, 14:00 pm
Tengo un problema con el namespace My.Settings cuando intento modificar un valor y guardar las settings (Me sucede con cualquier propiedad...):

Código
  1.    Private Sub Button1_Click(Sender As Object, e As MouseEventArgs) Handles Button1.Click
  2.        My.Settings.Remember_Settings = True
  3.        My.Settings.Save()
  4.    End Sub

Me salta este error:



Esta es la excepción:
Código:
System.Configuration.ConfigurationErrorsException was unhandled
  BareMessage=Configuration system failed to initialize
  HResult=-2146232062
  Line=0
  Message=Configuration system failed to initialize
  Source=System.Configuration
  StackTrace:
       at System.Configuration.ClientConfigurationSystem.OnConfigRemoved(Object sender, InternalConfigEventArgs e)
       at System.Configuration.Internal.InternalConfigRoot.RemoveConfigImpl(String configPath, BaseConfigurationRecord configRecord)
       at System.Configuration.BaseConfigurationRecord.GetSectionRecursive(String configKey, Boolean getLkg, Boolean checkPermission, Boolean getRuntimeObject, Boolean requestIsHere, Object& result, Object& resultRuntimeObject)
       at System.Configuration.BaseConfigurationRecord.GetSection(String configKey)
       at System.Configuration.ConfigurationManager.GetSection(String sectionName)
       at System.Configuration.ClientSettingsStore.ReadSettings(String sectionName, Boolean isUserScoped)
       at System.Configuration.LocalFileSettingsProvider.GetPropertyValues(SettingsContext context, SettingsPropertyCollection properties)
       at System.Configuration.SettingsBase.GetPropertiesFromProvider(SettingsProvider provider)
       at System.Configuration.SettingsBase.SetPropertyValueByName(String propertyName, Object propertyValue)
       at System.Configuration.SettingsBase.set_Item(String propertyName, Object value)
       at System.Configuration.ApplicationSettingsBase.set_Item(String propertyName, Object value)
       at Volium.My.MySettings.set_Remember_Settings(Boolean value) in C:\Projects\Volium\Volium\My Project\Settings.Designer.vb:line 137
       at Volium.Form1.CheckBox_Remember_Settings_CheckedChanged(Object sender, EventArgs e) in C:\Projects\Volium\Volium\Form1.vb:line 96
       at System.Windows.Forms.CheckBox.set_CheckState(CheckState value)
       at System.Windows.Forms.CheckBox.OnClick(EventArgs e)
       at System.Windows.Forms.CheckBox.OnMouseUp(MouseEventArgs mevent)
       at System.Windows.Forms.Control.WmMouseUp(Message& m, MouseButtons button, Int32 clicks)
       at System.Windows.Forms.Control.WndProc(Message& m)
       at System.Windows.Forms.ButtonBase.WndProc(Message& m)
       at System.Windows.Forms.NativeWindow.DebuggableCallback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)
       at System.Windows.Forms.UnsafeNativeMethods.DispatchMessageW(MSG& msg)
       at System.Windows.Forms.Application.ComponentManager.System.Windows.Forms.UnsafeNativeMethods.IMsoComponentManager.FPushMessageLoop(IntPtr dwComponentID, Int32 reason, Int32 pvLoopData)
       at System.Windows.Forms.Application.ThreadContext.RunMessageLoopInner(Int32 reason, ApplicationContext context)
       at System.Windows.Forms.Application.ThreadContext.RunMessageLoop(Int32 reason, ApplicationContext context)
       at Microsoft.VisualBasic.ApplicationServices.WindowsFormsApplicationBase.OnRun()
       at Microsoft.VisualBasic.ApplicationServices.WindowsFormsApplicationBase.DoApplicationModel()
       at Microsoft.VisualBasic.ApplicationServices.WindowsFormsApplicationBase.Run(String[] commandLine)
       at Volium.My.MyApplication.Main(String[] Args) in 17d14f5c-a337-4978-8281-53493378c1071.vb:line 81
       at System.AppDomain._nExecuteAssembly(RuntimeAssembly assembly, String[] args)
       at Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()
       at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
       at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
       at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
       at System.Threading.ThreadHelper.ThreadStart()
  InnerException: System.Configuration.ConfigurationErrorsException
       BareMessage=Unrecognized configuration section userSettings/WindowsApplication1.My.MySettings.
       Filename=C:\Users\Administrador\AppData\Local\Microsoft\Volium.vshost.exe_Url_irr03xswjdrhsokru05hku4eejmnb511\1.0.0.0\user.config
       HResult=-2146232062
       Line=4
       Message=Unrecognized configuration section userSettings/WindowsApplication1.My.MySettings. (C:\Users\Administrador\AppData\Local\Microsoft\Volium.vshost.exe_Url_irr03xswjdrhsokru05hku4eejmnb511\1.0.0.0\user.config line 4)
       Source=System.Configuration
       StackTrace:
            at System.Configuration.ConfigurationSchemaErrors.ThrowIfErrors(Boolean ignoreLocal)
            at System.Configuration.BaseConfigurationRecord.ThrowIfParseErrors(ConfigurationSchemaErrors schemaErrors)
            at System.Configuration.ClientConfigurationSystem.OnConfigRemoved(Object sender, InternalConfigEventArgs e)
       InnerException:
9556  Programación / .NET (C#, VB.NET, ASP) / Re: Librería de Snippets !! (Posteen aquí sus snippets) en: 18 Marzo 2013, 11:26 am
· String a hexadecimal:

Código
  1. #Region " String To Hex Function "
  2.  
  3.    ' [ String To Hex Function ]
  4.    '
  5.    ' Examples :
  6.    ' Dim Hex_str As String = String_To_Hex("Elektro H@cker")
  7.  
  8.    Private Function String_To_Hex(ByVal Source_String As String) As String
  9.        Dim Hex_StringBuilder As New System.Text.StringBuilder()
  10.        For Each c As Char In Source_String : Hex_StringBuilder.Append(Asc(c).ToString("x2")) : Next c
  11.        Return Hex_StringBuilder.ToString()
  12.    End Function
  13.  
  14. #End Region



· Hexadecimal a string:

Código
  1. #Region " Hex To String Function "
  2.  
  3.    ' [ Hex To String Function ]
  4.    '
  5.    ' Examples :
  6.    ' Dim str As String = Hex_To_String("456c656b74726f204840636b6572"))
  7.  
  8.    Private Function Hex_To_String(ByVal Source_String As String) As String
  9.        Dim Hex_StringBuilder As New System.Text.StringBuilder()
  10.        For x As Integer = 0 To Source_String.Length - 1 Step 2 : Hex_StringBuilder.Append(Chr(Val("&H" & Source_String.Substring(x, 2)))) : Next x
  11.        Return Hex_StringBuilder.ToString()
  12.    End Function
  13.  
  14. #End Region



· Effecto Matrix (Aplicación de consola)

Código
  1.    Module Module1
  2.        Sub Main()
  3.            Console.Title = "Matrix Effect"
  4.            Console.ForegroundColor = ConsoleColor.DarkGreen
  5.            Console.WindowLeft = InlineAssignHelper(0, 0)
  6.            Console.WindowHeight = InlineAssignHelper(Console.BufferHeight, Console.LargestWindowHeight)
  7.            Console.WindowWidth = InlineAssignHelper(Console.BufferWidth, Console.LargestWindowWidth)
  8.  
  9.            Console.CursorVisible = False
  10.            Dim width As Integer, height As Integer
  11.            Dim y As Integer()
  12.            Dim l As Integer()
  13.            Initialize(width, height, y, l)
  14.            Dim ms As Integer
  15.            While True
  16.                Dim t1 As DateTime = DateTime.Now
  17.                MatrixStep(width, height, y, l)
  18.                ms = 10 - CInt(Math.Truncate(CType(DateTime.Now - t1, TimeSpan).TotalMilliseconds))
  19.                If ms > 0 Then
  20.                    System.Threading.Thread.Sleep(ms)
  21.                End If
  22.                If Console.KeyAvailable Then
  23.                    If Console.ReadKey().Key = ConsoleKey.F5 Then
  24.                        Initialize(width, height, y, l)
  25.                    End If
  26.                End If
  27.            End While
  28.        End Sub
  29.  
  30.        Dim thistime As Boolean = False
  31.  
  32.        Private Sub MatrixStep(ByVal width As Integer, ByVal height As Integer, ByVal y As Integer(), ByVal l As Integer())
  33.            Dim x As Integer
  34.            thistime = Not thistime
  35.            For x = 0 To width - 1
  36.                If x Mod 11 = 10 Then
  37.                    If Not thistime Then
  38.                        Continue For
  39.                    End If
  40.                    Console.ForegroundColor = ConsoleColor.White
  41.                Else
  42.                    Console.ForegroundColor = ConsoleColor.DarkGreen
  43.                    Console.SetCursorPosition(x, inBoxY(y(x) - 2 - ((l(x) \ 40) * 2), height))
  44.                    Console.Write(R)
  45.                    Console.ForegroundColor = ConsoleColor.Green
  46.                End If
  47.                Console.SetCursorPosition(x, y(x))
  48.                Console.Write(R)
  49.                y(x) = inBoxY(y(x) + 1, height)
  50.                Console.SetCursorPosition(x, inBoxY(y(x) - l(x), height))
  51.                Console.Write(" "c)
  52.            Next
  53.        End Sub
  54.  
  55.        Private Sub Initialize(ByRef width As Integer, ByRef height As Integer, ByRef y As Integer(), ByRef l As Integer())
  56.            Dim h1 As Integer
  57.            Dim h2 As Integer = (InlineAssignHelper(h1, (InlineAssignHelper(height, Console.WindowHeight)) \ 2)) \ 2
  58.            width = Console.WindowWidth - 1
  59.            y = New Integer(width - 1) {}
  60.            l = New Integer(width - 1) {}
  61.            Dim x As Integer
  62.            Console.Clear()
  63.            For x = 0 To width - 1
  64.                y(x) = m_r.[Next](height)
  65.                l(x) = m_r.[Next](h2 * (If((x Mod 11 <> 10), 2, 1)), h1 * (If((x Mod 11 <> 10), 2, 1)))
  66.            Next
  67.        End Sub
  68.  
  69.        Dim m_r As New Random()
  70.        Private ReadOnly Property R() As Char
  71.            Get
  72.                Dim t As Integer = m_r.[Next](10)
  73.                If t <= 2 Then
  74.                    Return ChrW(CInt(AscW("0"c)) + m_r.[Next](10))
  75.                ElseIf t <= 4 Then
  76.                    Return ChrW(CInt(AscW("a"c)) + m_r.[Next](27))
  77.                ElseIf t <= 6 Then
  78.                    Return ChrW(CInt(AscW("A"c) + m_r.[Next](27)))
  79.                Else
  80.                    Return ChrW(m_r.[Next](32, 255))
  81.                End If
  82.            End Get
  83.        End Property
  84.  
  85.        Public Function inBoxY(ByVal n As Integer, ByVal height As Integer) As Integer
  86.            n = n Mod height
  87.            If n < 0 Then
  88.                Return n + height
  89.            Else
  90.                Return n
  91.            End If
  92.        End Function
  93.        Private Function InlineAssignHelper(Of T)(ByRef target As T, ByVal value As T) As T
  94.            target = value
  95.            Return value
  96.        End Function
  97.  
  98.    End Module
9557  Programación / Scripting / Re: con que extecion guardo los Scripting bash para que se ejecuten en backtrack en: 18 Marzo 2013, 09:42 am
ScriptBash.sh

Saludos
9558  Programación / .NET (C#, VB.NET, ASP) / Re: Librería de Snippets !! (Posteen aquí sus snippets) en: 18 Marzo 2013, 09:38 am
· Periodo Trial

Instrucciones:

1. Crear una Setting de "User" con el nombre "UsageDates" y de tipo "System.collection.specialized.stringcollection"

2. Añadir estas dos funcines al form:

Código
  1. Private Function CheckDate(ByVal dateToCheck As Date) As Boolean
  2.        'In reality, CheckDate would get the date (current date) itself and not have it passed in
  3.        Dim retValue As Boolean = False 'Fail safe, default to false
  4.        Dim usageDatesLeft As Int16 = 3 ' set it to 4 just for testing
  5.        'Dim usageDatesLeft As Int16 = 30 ' set this to the number of days of application access
  6.  
  7.        'Hash the date
  8.        Dim hashedDate As String = HashDate(dateToCheck)
  9.        'Check to see if the hash value exists in the UsageDates
  10.  
  11.        'Initialize the container if necessary
  12.        If My.Settings.UsageDates Is Nothing Then
  13.            My.Settings.UsageDates = New System.Collections.Specialized.StringCollection
  14.        End If
  15.  
  16.        If My.Settings.UsageDates.Contains(hashedDate) Then
  17.            'then we are ok...  it's already been checked
  18.            retValue = True
  19.            usageDatesLeft = CShort(usageDatesLeft - My.Settings.UsageDates.Count)
  20.  
  21.            'sanity check... if the system date is backed up to a previous date in the list, but not the last date
  22.            If usageDatesLeft <= 0 AndAlso My.Settings.UsageDates.IndexOf(hashedDate) <> My.Settings.UsageDates.Count - 1 Then
  23.                retValue = False
  24.            End If
  25.        Else
  26.            If My.Settings.UsageDates.Count < usageDatesLeft Then
  27.                My.Settings.UsageDates.Add(hashedDate)
  28.            End If
  29.            usageDatesLeft = CShort(usageDatesLeft - My.Settings.UsageDates.Count)
  30.  
  31.  
  32.            'If not, and the remining count has "slots" open, add it
  33.            If usageDatesLeft > 0 Then
  34.                retValue = True
  35.            Else
  36.                'If not and tree are no more slots, tell user, exit app
  37.                retValue = False
  38.            End If
  39.  
  40.        End If
  41.        'Display to the user how many days are remianing:
  42.        MessageBox.Show(String.Format("You have {0} day(s) remaining.", usageDatesLeft))
  43.  
  44.        Return retValue
  45.    End Function
  46.  
  47.    Private Function HashDate(ByVal dateToHash As Date) As String
  48.        'Get a hash object
  49.        Dim hasher As System.Security.Cryptography.MD5 = System.Security.Cryptography.MD5.Create()
  50.        'Take date, make it a Long date and hash it
  51.        Dim data As Byte() = hasher.ComputeHash(System.Text.Encoding.Default.GetBytes(dateToHash.ToLongDateString()))
  52.        ' Create a new Stringbuilder to collect the bytes
  53.        ' and create a string.
  54.        Dim sBuilder As New System.Text.StringBuilder()
  55.  
  56.        ' Loop through each byte of the hashed data
  57.        ' and format each one as a hexadecimal string.
  58.        Dim idx As Integer
  59.        For idx = 0 To data.Length - 1
  60.            sBuilder.Append(data(idx).ToString("x2"))
  61.        Next idx
  62.  
  63.        Return sBuilder.ToString
  64.  
  65.    End Function

3. Usar la función por ejemplo en el Form_Load:

Código
  1.    Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
  2.        Dim aCount As Integer = 0
  3.        Dim loopIt As Boolean = True
  4.        'My.Settings.Reset() 'This is here for design time support... otherwise you won't get your app to run agin
  5.  
  6.        Do While loopIt
  7.            MessageBox.Show(String.Format("Checking Date: {0}.", Date.Now.AddDays(aCount)))
  8.            loopIt = CheckDate(Date.Now.AddDays(aCount))
  9.            If Not loopIt Then
  10.                MessageBox.Show("Trial Period Ended! Application closing!")
  11.                Me.Close()
  12.            Else
  13.                MessageBox.Show("You can keep using the app")
  14.            End If
  15.            aCount += 1
  16.        Loop
  17.    End Sub




· Trial period (Modificado un poco por mí)

Código
  1. #Region " Trial Period Function "
  2.  
  3.    ' [ Trial Period Function ]
  4.    '
  5.    ' Examples :
  6.    ' Trial_Get(Trial_value.As_Boolean)
  7.    ' MsgBox(String.Format("You have {0} day(s) remaining.", Trial_Get(Trial_value.As_LeftDays)))
  8.  
  9.    Public Enum Trial_value
  10.        As_Boolean
  11.        As_LeftDays
  12.        As_CountDays
  13.    End Enum
  14.  
  15.    ' Trial Period [Get]
  16.    Public Function Trial_Get(ByVal Trial_value As Trial_value)
  17.        'My.Settings.Reset() 'If you want to reset the trial period
  18.        Dim TrialCount As Integer = 0
  19.        TrialCount += 1
  20.        Return Trial_CheckDate(Date.Now.AddDays(TrialCount), Trial_value)
  21.    End Function
  22.  
  23.    ' Trial Period [CheckDate]
  24.    Public Function Trial_CheckDate(ByVal Trial_DateToCheck As Date, ByVal Trial_value As Trial_value)
  25.  
  26.        Dim Trial_retValue As Boolean = False ' Fail safe, default to false
  27.        Dim Trial_usageDatesLeft As Int16 = 7 ' Set here the number of days of Trial period
  28.        Dim Trial_hashedDate As String = Trial_HashDate(Trial_DateToCheck)
  29.  
  30.        If My.Settings.Trial_Period Is Nothing Then My.Settings.Trial_Period = New System.Collections.Specialized.StringCollection
  31.  
  32.        If My.Settings.Trial_Period.Contains(Trial_hashedDate) Then
  33.            Trial_retValue = True
  34.            Trial_usageDatesLeft = CShort(Trial_usageDatesLeft - My.Settings.Trial_Period.Count)
  35.            If Trial_usageDatesLeft <= 0 AndAlso My.Settings.Trial_Period.IndexOf(Trial_hashedDate) <> My.Settings.Trial_Period.Count - 1 Then Trial_retValue = False
  36.        Else
  37.            If My.Settings.Trial_Period.Count < Trial_usageDatesLeft Then My.Settings.Trial_Period.Add(Trial_hashedDate)
  38.            Trial_usageDatesLeft = CShort(Trial_usageDatesLeft - My.Settings.Trial_Period.Count)
  39.            If Trial_usageDatesLeft > 0 Then Trial_retValue = True Else Trial_retValue = False
  40.        End If
  41.  
  42.        Select Case Trial_value
  43.            Case Trial_value.As_Boolean : Return Trial_retValue ' If False then Trial Period is expired
  44.            Case Trial_value.As_LeftDays : Return Trial_usageDatesLeft ' Days left
  45.            Case Trial_value.As_CountDays : Return My.Settings.Trial_Period.Count ' Count days
  46.            Case Else : Return Nothing
  47.        End Select
  48.  
  49.    End Function
  50.  
  51.    ' Trial Period [HashDate]
  52.    Public Function Trial_HashDate(ByVal Trial_DateToHash As Date) As String
  53.        Dim Trial_Hasher As System.Security.Cryptography.MD5 = System.Security.Cryptography.MD5.Create()
  54.        Dim Trial_Data As Byte() = Trial_Hasher.ComputeHash(System.Text.Encoding.Default.GetBytes(Trial_DateToHash.ToLongDateString()))
  55.        Dim Trial_StringBuilder As New System.Text.StringBuilder()
  56.        Dim Trial_IDX As Integer
  57.        For Trial_IDX = 0 To Trial_Data.Length - 1 : Trial_StringBuilder.Append(Trial_Data(Trial_IDX).ToString("x2")) : Next Trial_IDX
  58.        Return Trial_StringBuilder.ToString
  59.    End Function
  60.  
  61. #End Region
9559  Informática / Software / Re: ¿Algún programa que apague mi ordenador? en: 17 Marzo 2013, 19:04 pm
El problema de los scripts que le están aconsejando es que se corre el riesgo de que se pueda apagar el equipo mientras el renderizado todavía no haya finalizado... es lo que digo desde un principio, esa opción debe ir (casi al 90% seguro) en la aplicación que se usa para renderizar, no es necesario más.

Pero de hacer un script, como ya te dije te recomendaría que hagas mediciones del consumo de RAM de la aplicación, es decir, cuando no renderizas, cuando el proceso está en IDLE consume la memória normal (yo no puedo saber cuanto es porque no tengo la aplicación), pero cuando renderizas, el proceso consume MUCHA más memória, así que te hago un pequeño script:



Código
  1. @Echo OFF
  2.  
  3. REM Si el proceso está consumiendo menos de 104857600 Bytes (100 MB), el PC se apagará...
  4. REM de lo contrario, seguirá monitorizando el consumo de memória del proceso.
  5.  
  6. Set "APP_Name=explorer.exe"
  7. Set /A "Max_Memory=104857600"
  8. Set /A "Interval=5"
  9.  
  10. :Loop
  11. For /F "Tokens=*" %%# in ('wmic.exe process where "caption="%APP_Name%"" get WorkingSetSize ^| FINDSTR "^[0-9].*[0-9]"') Do (Set /A "Process_Memory=%%#")
  12.  
  13. If %Process_Memory% LSS %Max_Memory% (
  14.     Echo [%TIME:~0,-3%] Process "%APP_Name%" is consuming less than %Max_Memory% Bytes of memory...
  15.     Echo [%TIME:~0,-3%] Turning off the computer...
  16.     Shutdown.exe /S /F
  17. ) ELSE (
  18.     Echo [%TIME:~0,-3%] Process "%APP_Name%" memory consumition: %Process_Memory% Bytes...
  19.     Ping -n %Interval% LocalHost >NUL
  20.     Goto :Loop
  21. )

Saludos!
9560  Programación / .NET (C#, VB.NET, ASP) / Re: [APORTE] Snippets !! (Posteen aquí sus snippets) en: 17 Marzo 2013, 15:19 pm
· Función para modificar el color del borde de un control.



Nota:
Afecta a todos los controles handleados, es decir, si cambiamos el color de "button1", y luego el color de "button2", el color de "button1" pasará a ser el color que usa "button2", no he conseguido mejorarlo más, pero bueno, lo suyo es colorear todos los bordes dle mismo color, ¿no?, así que creo que no tiene mucha importancia...


#Region " Set Control Border Color Function "

    ' [ Set Control Border Color Function ]
    '
    ' // By Elektro H@cker
    '
    ' Examples :
    ' Set_Control_Border_Color(Button1, Pens.Crimson, Pens.Red, Pens.DarkRed)
    ' Set_Control_Border_Color(Checkbox1, Pens.Transparent, Pens.Transparent, Pens.Transparent)

    Dim Border_Color_Light As Pen
    Dim Border_Color_Middle As Pen
    Dim Border_Color_Dark As Pen

    Private Function Set_Control_Border_Color(ByVal Control As Control, Color_Light As Pen, ByVal Color_Middle As Pen, ByVal Color_Dark As Pen) As Boolean
        Try
            Border_Color_Light = Color_Light
            Border_Color_Middle = Color_Middle
            Border_Color_Dark = Color_Dark
            Handled_Controls.Add(Control)
            AddHandler Control.Paint, AddressOf Control_Paint
            Return True
        Catch ex As Exception : Throw New Exception(ex.Message)
        End Try
    End Function

    Private Sub Control_Paint(ByVal sender As System.Object, ByVal e As System.Windows.Forms.PaintEventArgs)
        Dim offset As Integer = 0
        e.Graphics.DrawRectangle(Border_Color_Light, New Rectangle(New Point(offset, offset), New Size(e.ClipRectangle.Width - ((offset * 2) + 1), e.ClipRectangle.Height - ((offset * 2) + 1))))
        offset += 1
        e.Graphics.DrawRectangle(Border_Color_Middle, New Rectangle(New Point(offset, offset), New Size(e.ClipRectangle.Width - ((offset * 2) + 1), e.ClipRectangle.Height - ((offset * 2) + 1))))
        offset += 1
        e.Graphics.DrawRectangle(Border_Color_Dark, New Rectangle(New Point(offset, offset), New Size(e.ClipRectangle.Width - ((offset * 2) + 1), e.ClipRectangle.Height - ((offset * 2) + 1))))
    End Sub

#End Region


Mejorado:

Código
  1. #Region " Set Control Border Color Function "
  2.  
  3.    ' [ Set Control Border Color Function ]
  4.    '
  5.    ' // By Elektro H@cker
  6.    '
  7.    ' Examples :
  8.    ' Set_Control_Border_Color(Button1, Pens.Crimson, Pens.Red, Pens.DarkRed)
  9.    ' Set_Control_Border_Color(Checkbox1, Pens.Transparent, Pens.Transparent, Pens.Transparent)
  10.  
  11.    Dim Border_Color_Light As Pen
  12.    Dim Border_Color_Middle As Pen
  13.    Dim Border_Color_Dark As Pen
  14.    Dim Last_Handled_control As Control
  15.  
  16.    Private Function Set_Control_Border_Color(ByVal Control As Control, Color_Light As Pen, ByVal Color_Middle As Pen, ByVal Color_Dark As Pen) As Boolean
  17.        Try
  18.            Border_Color_Light = Color_Light
  19.            Border_Color_Middle = Color_Middle
  20.            Border_Color_Dark = Color_Dark
  21.            AddHandler Control.Paint, AddressOf Control_Paint
  22.            Last_Handled_control = Control
  23.            Return True
  24.        Catch ex As Exception : Throw New Exception(ex.Message)
  25.        End Try
  26.    End Function
  27.  
  28.    Private Sub Control_Paint(ByVal sender As System.Object, ByVal e As System.Windows.Forms.PaintEventArgs)
  29.        If sender.name = Last_Handled_control.Name Then
  30.            Dim offset As Integer = 0
  31.            e.Graphics.DrawRectangle(Border_Color_Light, New Rectangle(New Point(offset, offset), New Size(e.ClipRectangle.Width - ((offset * 2) + 1), e.ClipRectangle.Height - ((offset * 2) + 1))))
  32.            offset += 1
  33.            e.Graphics.DrawRectangle(Border_Color_Middle, New Rectangle(New Point(offset, offset), New Size(e.ClipRectangle.Width - ((offset * 2) + 1), e.ClipRectangle.Height - ((offset * 2) + 1))))
  34.            offset += 1
  35.            e.Graphics.DrawRectangle(Border_Color_Dark, New Rectangle(New Point(offset, offset), New Size(e.ClipRectangle.Width - ((offset * 2) + 1), e.ClipRectangle.Height - ((offset * 2) + 1))))
  36.        End If
  37.    End Sub
  38.  
  39. #End Region
Páginas: 1 ... 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 [956] 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 ... 1254
WAP2 - Aviso Legal - Powered by SMF 1.1.21 | SMF © 2006-2008, Simple Machines