|
-
Aug 19th, 2006, 08:02 AM
#1
Thread Starter
Lively Member
Extending CMD
Hello, I am trying the new msdn 200 express edition but also got VB6, anyone know if there is a way to make a cmd prompt like inside a form, so when running dos apps, it will show the stuff in prompt on your form and not a new cmd prompt?
-
Aug 19th, 2006, 08:38 AM
#2
Re: Extending CMD
You would have to get the list of commands from the system. You would also have to define standard IO, which would display input and output.
-
Aug 19th, 2006, 08:41 AM
#3
Thread Starter
Lively Member
Re: Extending CMD
How might I go about getting the list and defineing the IO. I have no idea. =/
-
Aug 19th, 2006, 08:45 AM
#4
Re: Extending CMD
You can get the list of commands in My computer, Properties, Advanced, Environment variables. You also have a lot of IO definitions/samples all over the net. All applications which can be run in a command line, base on standard IO. Are you familiar to, i don't know... C's stdio library?
-
Aug 19th, 2006, 08:48 AM
#5
Thread Starter
Lively Member
Re: Extending CMD
No, just started, well anyway hmm is there a way even if I run app in standard cmd, to minimize it but not showing in tray or taskbar or the tasklist thing [CTRL+ATL+DEL] ?
-
Aug 19th, 2006, 08:58 AM
#6
Re: Extending CMD
Few people have done what you're after. However, you can familiarize yourself with CygWIN, which does something similar (implements terminal into Windows command line), and it's also available in open-source... i think so
-
Aug 19th, 2006, 09:00 AM
#7
Thread Starter
Lively Member
-
Aug 19th, 2006, 09:06 AM
#8
Hyperactive Member
Re: Extending CMD
VB Code:
'Purpose : Optionally Synchronously runs a DOS command line and returns the captured screen output.
'Inputs : sCommandLine The DOS command line to run.
' [bShowWindow] If True displays the DOS output window.
'Outputs : Returns the screen output
'Notes : This routine will work only with those program that send their output to
' the standard output device (stdout).
' Windows NT ONLY.
'Revisions :
Function ShellExecuteCapture(sCommandLine As String, Optional bShowWindow As Boolean = False, Optional waitFlag As Boolean = True) As String
Const clReadBytes As Long = 256, INFINITE As Long = &HFFFFFFFF
Const STARTF_USESHOWWINDOW = &H1, STARTF_USESTDHANDLES = &H100&
Const SW_HIDE = 0, SW_NORMAL = 1
Const NORMAL_PRIORITY_CLASS = &H20&
Const PIPE_CLIENT_END = &H0 'The handle refers to the client end of a named pipe instance. This is the default.
Const PIPE_SERVER_END = &H1 'The handle refers to the server end of a named pipe instance. If this value is not specified, the handle refers to the client end of a named pipe instance.
Const PIPE_TYPE_BYTE = &H0 'The named pipe is a byte pipe. This is the default.
Const PIPE_TYPE_MESSAGE = &H4 'The named pipe is a message pipe. If this value is not specified, the pipe is a byte pipe
Dim tProcInfo As PROCESS_INFORMATION, lRetVal As Long, lSuccess As Long
Dim tStartupInf As STARTUPINFO
Dim tSecurAttrib As SECURITY_ATTRIBUTES, lhwndReadPipe As Long, lhwndWritePipe As Long
Dim lBytesRead As Long, sBuffer As String
Dim lPipeOutLen As Long, lPipeInLen As Long, lMaxInst As Long
tSecurAttrib.nLength = Len(tSecurAttrib)
tSecurAttrib.bInheritHandle = 1&
tSecurAttrib.lpSecurityDescriptor = 0&
lRetVal = CreatePipe(lhwndReadPipe, lhwndWritePipe, tSecurAttrib, 0)
If lRetVal = 0 Then
'CreatePipe failed
Exit Function
End If
tStartupInf.cb = Len(tStartupInf)
tStartupInf.dwFlags = STARTF_USESTDHANDLES Or STARTF_USESHOWWINDOW
tStartupInf.hStdOutput = lhwndWritePipe
If bShowWindow Then
'Show the DOS window
tStartupInf.wShowWindow = SW_NORMAL
Else
'Hide the DOS window
tStartupInf.wShowWindow = SW_HIDE
End If
lRetVal = CreateProcessA(0&, sCommandLine, tSecurAttrib, tSecurAttrib, 1&, NORMAL_PRIORITY_CLASS, 0&, 0&, tStartupInf, tProcInfo)
If lRetVal <> 1 Then
'CreateProcess failed
Exit Function
End If
'Process created, wait for completion. Note, this will cause your application
'to hang indefinately until this process completes.
If waitFlag Then WaitForSingleObject tProcInfo.hProcess, INFINITE
'Determine pipes contents
lSuccess = GetNamedPipeInfo(lhwndReadPipe, PIPE_TYPE_BYTE, lPipeOutLen, lPipeInLen, lMaxInst)
If lSuccess Then
'Got pipe info, create buffer
sBuffer = String(lPipeOutLen, 0)
'Read Output Pipe
lSuccess = ReadFile(lhwndReadPipe, sBuffer, lPipeOutLen, lBytesRead, 0&)
If lSuccess = 1 Then
'Pipe read successfully
ShellExecuteCapture = Left$(sBuffer, lBytesRead)
End If
End If
'Close handles
Call CloseHandle(tProcInfo.hProcess)
Call CloseHandle(tProcInfo.hThread)
Call CloseHandle(lhwndReadPipe)
Call CloseHandle(lhwndWritePipe)
End Function
This is a good function.. Let me know if you need Win9x support and I'll try to dig up one I used to use..
-
Aug 19th, 2006, 09:14 AM
#9
Thread Starter
Lively Member
Re: Extending CMD
I have no idea what this does.
-
Aug 19th, 2006, 09:28 AM
#10
Hyperactive Member
Re: Extending CMD
This allows you to issue CMD console type commands in a procedure, and it returns what would be displayed by the console in the string variable ShellExecuteCapture that you can read and write to controls like text boxes etc or do any other string operations.. It has options to display the console window or execute the process 100% invisibly, and the option to pause your app's execution until the process completes, or continue your app's execution immediately.. (Continuing immediately will cause the function to return only the CMD output that has been written by the time the function exits BTW)
You can just put this in your form or in a module, Add whatever API/Type declarations it demands via errors the first time you execute it and you're good to go..
-
Aug 19th, 2006, 09:42 AM
#11
Thread Starter
Lively Member
Re: Extending CMD
So if I put this entire function somewhere where would I put it exactly, and how would I get it to work, just type in richtextbox1 and press enter and it will display crap just like CMD?
Last edited by Goat Spirit; Aug 19th, 2006 at 09:47 AM.
-
Aug 19th, 2006, 09:48 AM
#12
Thread Starter
Lively Member
Re: Extending CMD
Oh and I use Windows XP so Would it still work?
-
Aug 19th, 2006, 10:00 AM
#13
Hyperactive Member
Re: Extending CMD
You should save yourself alot of grief and hit the tutorials..
The function can be called with 1, 2, or 3 arguments..
It needs the commandline you wish to run obviously..
The other 2 can be added, but if they are not there then they will use the default values.
Defaults:
Dont pop up a visible command window
Wait until process completes before continuing running your app.
egs:
text1.text = ShellExecuteCapture("dir")
text1.text = ShellExecuteCapture("dir",true,false)
text1.text = ShellExecuteCapture("dir",,false)
text1.text = ShellExecuteCapture("dir",true)
This uses text2.text as the command to execute:
text1.text = ShellExecuteCapture(text2.text)
Here are the necessary declarations.. Put these at the top of the module/form you add the function to.. (Putting it in a module makes reusing it in other apps simpler)
VB Code:
Private Type SECURITY_ATTRIBUTES
nLength As Long
lpSecurityDescriptor As Long
bInheritHandle As Long
End Type
Private Type STARTUPINFO
cb As Long
lpReserved As Long
lpDesktop As Long
lpTitle As Long
dwX As Long
dwY As Long
dwXSize As Long
dwYSize As Long
dwXCountChars As Long
dwYCountChars As Long
dwFillAttribute As Long
dwFlags As Long
wShowWindow As Integer
cbReserved2 As Integer
lpReserved2 As Long
hStdInput As Long
hStdOutput As Long
hStdError As Long
End Type
Private Type PROCESS_INFORMATION
hProcess As Long
hThread As Long
dwProcessID As Long
dwThreadID As Long
End Type
Private Declare Function CreatePipe Lib "kernel32" (phReadPipe As Long, phWritePipe As Long, lpPipeAttributes As Any, ByVal nSize As Long) As Long
Private Declare Function ReadFile Lib "kernel32" (ByVal hFile As Long, ByVal lpBuffer As String, ByVal nNumberOfBytesToRead As Long, lpNumberOfBytesRead As Long, ByVal lpOverlapped As Any) As Long
Private Declare Function GetNamedPipeInfo Lib "kernel32" (ByVal hNamedPipe As Long, lType As Long, lLenOutBuf As Long, lLenInBuf As Long, lMaxInstances As Long) As Long
Private Declare Function WaitForSingleObject Lib "kernel32" (ByVal hHandle As Long, ByVal dwMilliseconds As Long) As Long
Private Declare Function CreateProcessA Lib "kernel32" (ByVal lpApplicationName As Long, ByVal lpCommandLine As String, lpProcessAttributes As Any, lpThreadAttributes As Any, ByVal bInheritHandles As Long, ByVal dwCreationFlags As Long, ByVal lpEnvironment As Long, ByVal lpCurrentDirectory As Long, lpStartupInfo As Any, lpProcessInformation As Any) As Long
Private Declare Function CloseHandle Lib "kernel32" (ByVal hObject As Long) As Long
Private Const STARTF_USESHOWWINDOW As Long = &H1&
Private Const SW_HIDE As Integer = 0&
-
Aug 19th, 2006, 10:03 AM
#14
Hyperactive Member
Re: Extending CMD
Yes, Win2K, XP, Server2003 are todays common WINNT's
-
Aug 19th, 2006, 10:07 AM
#15
Thread Starter
Lively Member
Re: Extending CMD
Okay it seems to compile okay, but it won't show theinfo for "dir" in Text1.Text, any ideas?
-
Aug 19th, 2006, 10:19 AM
#16
Hyperactive Member
Re: Extending CMD
Post your code..
Also, add the line:
debug.print ShellExecuteCapture("dir")
right above where you used it in your form code.. What you see returned in the immediate window is what text1.text would be assigned.. Perhaps its a size limitation that another user knows more about than I, or maybe I pooched something.. Who knows..
-
Aug 19th, 2006, 10:31 AM
#17
Thread Starter
Lively Member
Re: Extending CMD
What in the hell, I think it's doing something because the default text disippears but wont display the dir output info like on CMD prompt when you type dir it shows the dir's but wont show anything for me. in my Text1.Text...
VB Code:
Text1.Text = ShellExecuteCapture("dir", False, True)
Debug.Print ShellExecuteCapture("dir")
Help?
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|