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

 

 


Tema destacado: Guía rápida para descarga de herramientas gratuitas de seguridad y desinfección


+  Foro de elhacker.net
|-+  Programación
| |-+  Programación General
| | |-+  .NET (C#, VB.NET, ASP)
| | | |-+  Programación Visual Basic (Moderadores: LeandroA, seba123neo)
| | | | |-+  crear conosola con VB6?? :S
0 Usuarios y 1 Visitante están viendo este tema.
Páginas: [1] Ir Abajo Respuesta Imprimir
Autor Tema: crear conosola con VB6?? :S  (Leído 2,415 veces)
Xephiro

Desconectado Desconectado

Mensajes: 239



Ver Perfil WWW
crear conosola con VB6?? :S
« en: 6 Julio 2007, 01:01 am »

Hi, bueno me gustaria saber si es posible hacer una consola como la de win, pero en VB6...

Lo que quiero es poder tener en una sola pantalla mas de una consola funcionando y no tener varias ventanas ... ademas de agregarle algunos otros botones para otras cosas, no quiero que sea remoto, sino que suseda en el mismo PC donde lo abro..


En línea

~~
Ex-Staff
*
Desconectado Desconectado

Mensajes: 2.981


Ver Perfil WWW
Re: crear conosola con VB6?? :S
« Respuesta #1 en: 6 Julio 2007, 01:25 am »

Lo q tu necesitas es crear un pipe para otenr la salida de la consola (si creas varios podras tener varias consolas a la vez).
Busca sobre la api CreatePipe, en la api guide viene un ejemplo  ::)


En línea

Jareth


Desconectado Desconectado

Mensajes: 334



Ver Perfil
Re: crear conosola con VB6?? :S
« Respuesta #2 en: 6 Julio 2007, 02:04 am »

Código:
Option Explicit
Private Declare Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As Long)
Private Sub Command1_Click()
Dim ruta As String
On Error Resume Next
ruta = "c:\hi.txt"
Kill ruta
Kill "c:\tio.bat"
Open "c:\tio.bat" For Binary As #1
Put #1, , "@echo off" & vbCrLf
Put #1, , Text1.Text & ">>C:\hi.txt" & vbCrLf
Put #1, , "exit"
Close #1
Shell "c:\tio.bat", vbHide
Sleep 1000
Open "C:\hi.txt" For Input As #1
Dim resultado As String
Do While Not EOF(1)
Line Input #1, resultado
If Not resultado = "" Then Text2.Text = Text2.Text & vbCrLf & resultado
Loop




Close #1


End Sub

Private Sub Command2_Click()
Text2.Text = ""
End Sub

Private Sub Form_Load()
Me.Caption = "Shell"
End Sub

Private Sub Text1_KeyPress(KeyAscii As Integer)
If KeyAscii = 13 Then
KeyAscii = 0
Call Command1_Click
End If
End Sub
Espero qeu te sriva,es bastante sencilla y creo qeu servirá para tu proposito.
Evidentemente no es una consola,peor los comandos se envian y se lee las respuestas.
Saludos.
En línea

Xephiro

Desconectado Desconectado

Mensajes: 239



Ver Perfil WWW
Re: crear conosola con VB6?? :S
« Respuesta #3 en: 6 Julio 2007, 02:30 am »

nose si sera posible que me peguen una ayudita con api CreatePipe porquen o encuentro nada en VB sobre ello solo cosas con C++
En línea

Xephiro

Desconectado Desconectado

Mensajes: 239



Ver Perfil WWW
Re: crear conosola con VB6?? :S
« Respuesta #4 en: 6 Julio 2007, 09:26 am »

Bueno XD no tomen encuenta mi post anterios, ahora tengo una nueva pregunta XD porque no me funciona tal cual como CMD ?? hay carias cosasque no me corren :S

lo que pasa es que quiero hacer que se habra un server de L2 por medio de esa consola, para que quede un poco mejor ...

lo malo es que cuando trato de hacelo partir no me deja conectar con la DB desde la consola de VB6 pepi pero por medio de bat tal como es no hay problema :S porque esa diterencia ?? siendo que ambos estan en la misma carpeta, o tendre que agregar algo mas??
En línea

~~
Ex-Staff
*
Desconectado Desconectado

Mensajes: 2.981


Ver Perfil WWW
Re: crear conosola con VB6?? :S
« Respuesta #5 en: 6 Julio 2007, 11:34 am »

nose si sera posible que me peguen una ayudita con api CreatePipe porquen o encuentro nada en VB sobre ello solo cosas con C++

Pues podias poner algun ejemplillo en C++ q andube buscandolos hace algun tiempo  :P

Para VB te dejo dos ejemplos, el de la api guide:
Código
  1. 'Redirects output from console program to textbox.
  2. 'Requires two textboxes and one command button.
  3. 'Set MultiLine property of Text2 to true.
  4. '
  5. 'Original bcx version of this program was made by
  6. ' dl <dl@tks.cjb.net>
  7. 'VB port was made by Jernej Simoncic <jernej@isg.si>
  8. 'Visit Jernejs site at http://www2.arnes.si/~sopjsimo/
  9. '
  10. 'Note: don't run plain DOS programs with this example
  11. 'under Windows 95,98 and ME, as the program freezes when
  12. 'execution of program is finnished.
  13.  
  14. Option Explicit
  15. Private Declare Function CreatePipe Lib "kernel32" (phReadPipe As Long, phWritePipe As Long, lpPipeAttributes As SECURITY_ATTRIBUTES, ByVal nSize As Long) As Long
  16. Private Declare Sub GetStartupInfo Lib "kernel32" Alias "GetStartupInfoA" (lpStartupInfo As STARTUPINFO)
  17. Private Declare Function CreateProcess Lib "kernel32" Alias "CreateProcessA" (ByVal lpApplicationName As String, ByVal lpCommandLine As String, lpProcessAttributes As Any, lpThreadAttributes As Any, ByVal bInheritHandles As Long, ByVal dwCreationFlags As Long, lpEnvironment As Any, ByVal lpCurrentDriectory As String, lpStartupInfo As STARTUPINFO, lpProcessInformation As PROCESS_INFORMATION) As Long
  18. Private Declare Function SetWindowText Lib "user32" Alias "SetWindowTextA" (ByVal hwnd As Long, ByVal lpString As String) As Long
  19. Private Declare Function ReadFile Lib "kernel32" (ByVal hFile As Long, lpBuffer As Any, ByVal nNumberOfBytesToRead As Long, lpNumberOfBytesRead As Long, lpOverlapped As Any) As Long
  20. Private Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, lParam As Any) As Long
  21. Private Declare Function CloseHandle Lib "kernel32" (ByVal hObject As Long) As Long
  22.  
  23. Private Type SECURITY_ATTRIBUTES
  24.  nLength As Long
  25.  lpSecurityDescriptor As Long
  26.  bInheritHandle As Long
  27. End Type
  28.  
  29. Private Type PROCESS_INFORMATION
  30.  hProcess As Long
  31.  hThread As Long
  32.  dwProcessId As Long
  33.  dwThreadId As Long
  34. End Type
  35.  
  36. Private Type STARTUPINFO
  37.  cb As Long
  38.  lpReserved As Long
  39.  lpDesktop As Long
  40.  lpTitle As Long
  41.  dwX As Long
  42.  dwY As Long
  43.  dwXSize As Long
  44.  dwYSize As Long
  45.  dwXCountChars As Long
  46.  dwYCountChars As Long
  47.  dwFillAttribute As Long
  48.  dwFlags As Long
  49.  wShowWindow As Integer
  50.  cbReserved2 As Integer
  51.  lpReserved2 As Byte
  52.  hStdInput As Long
  53.  hStdOutput As Long
  54.  hStdError As Long
  55. End Type
  56.  
  57. Private Type OVERLAPPED
  58.    ternal As Long
  59.    ternalHigh As Long
  60.    offset As Long
  61.    OffsetHigh As Long
  62.    hEvent As Long
  63. End Type
  64.  
  65. Private Const STARTF_USESHOWWINDOW = &H1
  66. Private Const STARTF_USESTDHANDLES = &H100
  67. Private Const SW_HIDE = 0
  68. Private Const EM_SETSEL = &HB1
  69. Private Const EM_REPLACESEL = &HC2
  70.  
  71. Private Sub Command1_Click()
  72.  Command1.Enabled = False
  73.  Redirect Text1.Text, Text2
  74.  Command1.Enabled = True
  75. End Sub
  76. Private Sub Form_Load()
  77.    Text1.Text = "ping"
  78. End Sub
  79. Private Sub Form_QueryUnload(Cancel As Integer, UnloadMode As Integer)
  80.  If Command1.Enabled = False Then Cancel = True
  81. End Sub
  82.  
  83. Sub Redirect(cmdLine As String, objTarget As Object)
  84.  Dim i%, t$
  85.  Dim pa As SECURITY_ATTRIBUTES
  86.  Dim pra As SECURITY_ATTRIBUTES
  87.  Dim tra As SECURITY_ATTRIBUTES
  88.  Dim pi As PROCESS_INFORMATION
  89.  Dim sui As STARTUPINFO
  90.  Dim hRead As Long
  91.  Dim hWrite As Long
  92.  Dim bRead As Long
  93.  Dim lpBuffer(1024) As Byte
  94.  pa.nLength = Len(pa)
  95.  pa.lpSecurityDescriptor = 0
  96.  pa.bInheritHandle = True
  97.  
  98.  pra.nLength = Len(pra)
  99.  tra.nLength = Len(tra)
  100.  
  101.  If CreatePipe(hRead, hWrite, pa, 0) <> 0 Then
  102.    sui.cb = Len(sui)
  103.    GetStartupInfo sui
  104.    sui.hStdOutput = hWrite
  105.    sui.hStdError = hWrite
  106.    sui.dwFlags = STARTF_USESHOWWINDOW Or STARTF_USESTDHANDLES
  107.    sui.wShowWindow = SW_HIDE
  108.    If CreateProcess(vbNullString, cmdLine, pra, tra, True, 0, Null, vbNullString, sui, pi) <> 0 Then
  109.      SetWindowText objTarget.hwnd, ""
  110.      Do
  111.        Erase lpBuffer()
  112.        If ReadFile(hRead, lpBuffer(0), 1023, bRead, ByVal 0&) Then
  113.          SendMessage objTarget.hwnd, EM_SETSEL, -1, 0
  114.          SendMessage objTarget.hwnd, EM_REPLACESEL, False, lpBuffer(0)
  115.          DoEvents
  116.        Else
  117.          CloseHandle pi.hThread
  118.          CloseHandle pi.hProcess
  119.          Exit Do
  120.        End If
  121.        CloseHandle hWrite
  122.      Loop
  123.      CloseHandle hRead
  124.    End If
  125.  End If
  126. End Sub

Y otro un poco mas profesional q me baje en planet source code (me parece):
http://rapidshare.com/files/41320261/Shell_Pipes.zip.html

Espero q te sirvan
En línea

Hendrix
In The Kernel Land
Colaborador
***
Desconectado Desconectado

Mensajes: 2.276



Ver Perfil WWW
Re: crear conosola con VB6?? :S
« Respuesta #6 en: 6 Julio 2007, 12:43 pm »

Si se puede crear una consola...te dejo un ejemplo de la APIGuide

Código
  1. Private Const FOREGROUND_BLUE = &H1
  2. Private Const FOREGROUND_GREEN = &H2
  3. Private Const FOREGROUND_RED = &H4
  4. Private Const BACKGROUND_BLUE = &H10
  5. Private Const BACKGROUND_GREEN = &H20
  6. Private Const BACKGROUND_RED = &H40
  7. Private Const BACKGROUND_INTENSITY = &H80&
  8. Private Const BACKGROUND_SEARCH = &H20&
  9. Private Const FOREGROUND_INTENSITY = &H8&
  10. Private Const FOREGROUND_SEARCH = (&H10&)
  11. Private Const ENABLE_LINE_INPUT = &H2&
  12. Private Const ENABLE_ECHO_INPUT = &H4&
  13. Private Const ENABLE_MOUSE_INPUT = &H10&
  14. Private Const ENABLE_PROCESSED_INPUT = &H1&
  15. Private Const ENABLE_WINDOW_INPUT = &H8&
  16. Private Const ENABLE_PROCESSED_OUTPUT = &H1&
  17. Private Const ENABLE_WRAP_AT_EOL_OUTPUT = &H2&
  18. Private Const STD_OUTPUT_HANDLE = -11&
  19. Private Const STD_INPUT_HANDLE = -10&
  20. Private Const STD_ERROR_HANDLE = -12&
  21. Private Const INVALID_HANDLE_VALUE = -1&
  22. Private Declare Function AllocConsole Lib "kernel32" () As Long
  23. Private Declare Function FreeConsole Lib "kernel32" () As Long
  24. Private Declare Function CloseHandle Lib "kernel32" (ByVal hObject As Long) As Long
  25. Private Declare Function GetStdHandle Lib "kernel32" (ByVal nStdHandle As Long) As Long
  26. Private Declare Function WriteConsole Lib "kernel32" Alias "WriteConsoleA" (ByVal hConsoleOutput As Long, lpBuffer As Any, ByVal nNumberOfCharsToWrite As Long, lpNumberOfCharsWritten As Long, lpReserved As Any) As Long
  27. Private Declare Function ReadConsole Lib "kernel32" Alias "ReadConsoleA" (ByVal hConsoleInput As Long, ByVal lpBuffer As String, ByVal nNumberOfCharsToRead As Long, lpNumberOfCharsRead As Long, lpReserved As Any) As Long
  28. Private Declare Function SetConsoleTextAttribute Lib "kernel32" (ByVal hConsoleOutput As Long, ByVal wAttributes As Long) As Long
  29. Private Declare Function SetConsoleTitle Lib "kernel32" Alias "SetConsoleTitleA" (ByVal lpConsoleTitle As String) As Long
  30. Private hConsoleOut As Long, hConsoleIn As Long, hConsoleErr As Long
  31. Private Sub Form_Load()
  32.    'KPD-Team 2001
  33.    'URL: http://www.allapi.net/
  34.    'E-Mail: KPDTeam@Allapi.net
  35.    'Create console
  36.    If AllocConsole() Then
  37.        hConsoleOut = GetStdHandle(STD_OUTPUT_HANDLE)
  38.        If hConsoleOut = INVALID_HANDLE_VALUE Then MsgBox "Unable to get STDOUT"
  39.        hConsoleIn = GetStdHandle(STD_INPUT_HANDLE)
  40.        If hConsoleOut = INVALID_HANDLE_VALUE Then MsgBox "Unable to get STDIN"
  41.    Else
  42.        MsgBox "Couldn't allocate console"
  43.    End If
  44.    'Set the caption of the console window
  45.    SetConsoleTitle "The KPD-Team 2001"
  46.    'Set the background color of the text in the console to bright YELLOW text
  47.    'on a BLUE background
  48.    SetConsoleTextAttribute hConsoleOut, FOREGROUND_RED Or FOREGROUND_GREEN Or FOREGROUND_INTENSITY Or BACKGROUND_BLUE
  49.    'Write something in the console
  50.    ConsoleWriteLine "Hello World!"
  51.    ConsoleWrite "Please enter your name: "
  52.    'Ask for user input and show it in the caption
  53.    Me.Caption = "Your name: " + ConsoleReadLine()
  54. End Sub
  55. Private Sub Form_Unload(Cancel As Integer)
  56.    'Delete console
  57.    CloseHandle hConsoleOut
  58.    CloseHandle hConsoleIn
  59.    FreeConsole
  60. End Sub
  61. Sub ConsoleWriteLine(sInput As String)
  62.     ConsoleWrite sInput + vbCrLf
  63. End Sub
  64. Sub ConsoleWrite(sInput As String)
  65.     Dim cWritten As Long
  66.     WriteConsole hConsoleOut, ByVal sInput, Len(sInput), cWritten, ByVal 0&
  67. End Sub
  68. Function ConsoleReadLine() As String
  69.    Dim ZeroPos As Long
  70.    'Create a buffer
  71.    ConsoleReadLine = String(10, 0)
  72.    'Read the input
  73.    ReadConsole hConsoleIn, ConsoleReadLine, Len(ConsoleReadLine), vbNull, vbNull
  74.    'Strip off trailing vbCrLf and Chr$(0)'s
  75.    ZeroPos = InStr(ConsoleReadLine, Chr$(0))
  76.    If ZeroPos > 0 Then ConsoleReadLine = Left$(ConsoleReadLine, ZeroPos - 3)
  77. End Function

Un Saludo.  ;)

En línea

"Todos los días perdemos una docena de genios en el anonimato. Y se van. Y nadie sabe de ellos, de su historia, de su peripecia, de lo que han hecho, de sus angustias, de sus alegrías. Pero al menos una docena de genios se van todos los días sin que sepamos de ellos". - Juan Antonio Cebrián
Xephiro

Desconectado Desconectado

Mensajes: 239



Ver Perfil WWW
Re: crear conosola con VB6?? :S
« Respuesta #7 en: 6 Julio 2007, 19:53 pm »

ñp qie àsa es que cpn el Pepi no me conecta a las DB de mi PC como lo hacon un archivo.bar :S porque puede ser¿¿
En línea

Hendrix
In The Kernel Land
Colaborador
***
Desconectado Desconectado

Mensajes: 2.276



Ver Perfil WWW
Re: crear conosola con VB6?? :S
« Respuesta #8 en: 6 Julio 2007, 19:54 pm »

Puede hablar.....mmmmm.....Can you speak spanish??? :-\ :-\
En línea

"Todos los días perdemos una docena de genios en el anonimato. Y se van. Y nadie sabe de ellos, de su historia, de su peripecia, de lo que han hecho, de sus angustias, de sus alegrías. Pero al menos una docena de genios se van todos los días sin que sepamos de ellos". - Juan Antonio Cebrián
Xephiro

Desconectado Desconectado

Mensajes: 239



Ver Perfil WWW
Re: crear conosola con VB6?? :S
« Respuesta #9 en: 6 Julio 2007, 19:57 pm »

XD no se que hice con el texto anterior, bueno lo que pasa esque cuando quiero archivos java que se conectar a la DB desde la consola, por medio de la API Pepi no me funciona, pero por medio de un archivo .bat funciona exelente... :S

como puedo solucionar eso ??

Esta es la parte que trata de hacer conexion con la DB, pero no me deja :S

Código:
INFO : Initializing c3p0 pool... com.mchange.v2.c3p0.ComboPooledDataSource@110c424[ acquireIncrement -> 5, acquireRetryAttempts -> 0, acquireRetryDelay -> 500, autoCommitOnClose -> true, automaticTestTable -> connection_test_table, breakAfterAcquireFailure -> false, checkoutTimeout -> 0, connectionTesterClassName -> com.mchange.v2.c3p0.impl.DefaultConnectionTester, description -> null, driverClass -> com.mysql.jdbc.Driver, factoryClassLocation -> null, forceIgnoreUnresolvedTransactions -> false, identityToken -> 110c424, idleConnectionTestPeriod -> 60, initialPoolSize -> 3, jdbcUrl -> jdbc:mysql://localhost/l2jdb, loginTimeout -> 0, maxIdleTime -> 0, maxPoolSize -> 20, maxStatements -> 0, maxStatementsPerConnection -> 100, minPoolSize -> 1, numHelperThreads -> 20, preferredTestQuery -> null, properties -> {user=******, password=******}, propertyCycle -> 300, testConnectionOnCheckin -> true, testConnectionOnCheckout -> false, usesTraditionalReflectiveProxies -> false ]  
WARNING SQL Error: 0, SQLState: 08S01
SEVERE Communications link failure due to underlying exception:

** BEGIN NESTED EXCEPTION **

java.net.SocketException
MESSAGE: java.net.SocketException: Unrecognized Windows Sockets error: 10106: create




 asi me queda cuando lo uso con un archivo .bat en forma directa :S

Código:
INFO : Initializing c3p0 pool... com.mchange.v2.c3p0.ComboPooledDataSource@110c4
24[ acquireIncrement -> 5, acquireRetryAttempts -> 0, acquireRetryDelay -> 500,
autoCommitOnClose -> true, automaticTestTable -> connection_test_table, breakAft
erAcquireFailure -> false, checkoutTimeout -> 0, connectionTesterClassName -> co
m.mchange.v2.c3p0.impl.DefaultConnectionTester, description -> null, driverClass
 -> com.mysql.jdbc.Driver, factoryClassLocation -> null, forceIgnoreUnresolvedTr
ansactions -> false, identityToken -> 110c424, idleConnectionTestPeriod -> 60, i
nitialPoolSize -> 3, jdbcUrl -> jdbc:mysql://localhost/l2jdb, loginTimeout -> 0,
 maxIdleTime -> 0, maxPoolSize -> 20, maxStatements -> 0, maxStatementsPerConnec
tion -> 100, minPoolSize -> 1, numHelperThreads -> 20, preferredTestQuery -> nul
l, properties -> {user=******, password=******}, propertyCycle -> 300, testConne
ctionOnCheckin -> true, testConnectionOnCheckout -> false, usesTraditionalReflec
tiveProxies -> false ]

Luego comienza a cargar de inmediato los archivos de la DB
« Última modificación: 6 Julio 2007, 20:02 pm por Hacktor » En línea

Páginas: [1] Ir Arriba Respuesta Imprimir 

Ir a:  
WAP2 - Aviso Legal - Powered by SMF 1.1.21 | SMF © 2006-2008, Simple Machines