| View previous topic :: View next topic |
| Author |
Message |
kosstr12 Master Cheater
Reputation: -1
Joined: 12 Jul 2008 Posts: 339
|
Posted: Tue Jan 13, 2009 7:09 pm Post subject: Executing DOS commands in VB6 |
|
|
Is there an easy way to do it without running a batch file? I would rather just have it run the command without having to open up the command line.
Thanks.
|
|
| Back to top |
|
 |
Stonehenge Master Cheater
Reputation: 0
Joined: 03 Oct 2008 Posts: 280 Location: Unknown Jumphole
|
Posted: Wed Jan 14, 2009 4:18 pm Post subject: |
|
|
Taken from http://www.codeguru.com/forum/showthread.php?s=&threadid=26939&highlight=dos
| Code: |
'This code will create "abcd" directory in current Path.
'You cannot debug normally: to work this need the dos
'window to have focus
'If you want to see dos window, comment the
'last commands that close that window
option Explicit
private Sub Command1_Click()
Dim strCommand as string
Dim retPointer as Long
'
'if winNt
retPointer = Shell("cmd.exe", vbMaximizedFocus)
'if win98/95/me, the following:
'retPointer = Shell("command.exe", vbMaximizedFocus)
'
'launch a command:
'activate the dos window
AppActivate retPointer
'put the command in string variable -start with a space!-
strCommand = " mkdir abcde"
'write it to the dos window:
SendKeys strCommand, true
'you've just typed something. Need to press enter?
SendKeys "{ENTER}", true
'close dos windows:
SendKeys "Exit", true
SendKeys "{ENTER}", true
End Sub |
It was the very first result in Google...
_________________
|
|
| Back to top |
|
 |
Tyggo Expert Cheater
Reputation: 0
Joined: 03 Jan 2008 Posts: 186
|
Posted: Wed Jan 14, 2009 4:28 pm Post subject: |
|
|
I don't see that working very well but how I did it in VB9 (Visual Basic 2008) was
| Code: | dim command as string
command = "ping google.com"
Shell ("cmd.exe /k" & ping, AppWinStyle.NormalFocus) |
Replace the command string with whatever command you want to execute.
Oh, nevermind, I didn't see that you said without command prompt, that would be impossible... :/
Last edited by Tyggo on Wed Jan 14, 2009 4:28 pm; edited 1 time in total |
|
| Back to top |
|
 |
Noz3001 I'm a spammer
Reputation: 26
Joined: 29 May 2006 Posts: 6220 Location: /dev/null
|
Posted: Wed Jan 14, 2009 4:28 pm Post subject: |
|
|
| How about GetStdHandle and WriteFile?
|
|
| Back to top |
|
 |
kosstr12 Master Cheater
Reputation: -1
Joined: 12 Jul 2008 Posts: 339
|
Posted: Wed Jan 14, 2009 5:20 pm Post subject: |
|
|
| Obidos wrote: | Taken from http://www.codeguru.com/forum/showthread.php?s=&threadid=26939&highlight=dos
| Code: |
'This code will create "abcd" directory in current Path.
'You cannot debug normally: to work this need the dos
'window to have focus
'If you want to see dos window, comment the
'last commands that close that window
option Explicit
private Sub Command1_Click()
Dim strCommand as string
Dim retPointer as Long
'
'if winNt
retPointer = Shell("cmd.exe", vbMaximizedFocus)
'if win98/95/me, the following:
'retPointer = Shell("command.exe", vbMaximizedFocus)
'
'launch a command:
'activate the dos window
AppActivate retPointer
'put the command in string variable -start with a space!-
strCommand = " mkdir abcde"
'write it to the dos window:
SendKeys strCommand, true
'you've just typed something. Need to press enter?
SendKeys "{ENTER}", true
'close dos windows:
SendKeys "Exit", true
SendKeys "{ENTER}", true
End Sub |
It was the very first result in Google... |
I've seen that. It didn't work.
@Tyggo: Okay, well I guess I'll find some other way, thanks.
|
|
| Back to top |
|
 |
pkyourface Master Cheater
Reputation: 0
Joined: 26 Dec 2006 Posts: 252
|
Posted: Wed Jan 14, 2009 6:11 pm Post subject: |
|
|
This should be what your looking for, can be used locally or remotely.
|
|
| Back to top |
|
 |
Tyggo Expert Cheater
Reputation: 0
Joined: 03 Jan 2008 Posts: 186
|
Posted: Thu Jan 15, 2009 8:18 pm Post subject: |
|
|
| kosstr12 wrote: | | Obidos wrote: | Taken from http://www.codeguru.com/forum/showthread.php?s=&threadid=26939&highlight=dos
| Code: |
'This code will create "abcd" directory in current Path.
'You cannot debug normally: to work this need the dos
'window to have focus
'If you want to see dos window, comment the
'last commands that close that window
option Explicit
private Sub Command1_Click()
Dim strCommand as string
Dim retPointer as Long
'
'if winNt
retPointer = Shell("cmd.exe", vbMaximizedFocus)
'if win98/95/me, the following:
'retPointer = Shell("command.exe", vbMaximizedFocus)
'
'launch a command:
'activate the dos window
AppActivate retPointer
'put the command in string variable -start with a space!-
strCommand = " mkdir abcde"
'write it to the dos window:
SendKeys strCommand, true
'you've just typed something. Need to press enter?
SendKeys "{ENTER}", true
'close dos windows:
SendKeys "Exit", true
SendKeys "{ENTER}", true
End Sub |
It was the very first result in Google... |
I've seen that. It didn't work.
@Tyggo: Okay, well I guess I'll find some other way, thanks. |
Well, to execute CMD commands you we need to have it open...
|
|
| Back to top |
|
 |
|