Current time: 09-03-2010, 07:28 AM Hello There, Guest! (LoginRegister)
Quick Login:


Poll: Rate 1/5 pl0x ^_^
5
4
3
2
1
[Show Results]
 
Post Reply  Post Thread 
[VB]Shell - Info, basics, and some examples
Author Message
12-30-2006, 11:57 PM
Post: #1
[VB]Shell - Info, basics, and some examples
Ok, I will be creating this tutorial pretty much all from memory.

First of all the Shell function lets you execute some of the commands you can execute in the Command Prompt (CMD).
Shell basically means it'll execute commands in a command prompt shell. Simple yet effective.
It's pretty simple, here's a quick example.

Code:
Private Sub Command1_Click()
Shell "cmd"
End Sub

What that does is it creates another cmd shell.
The great thing about the Shell command that you can easily use it to do stuff that would be pretty hard or complex in regular VB code.
In VB the code to kill or end a process, is really long, and complex.

Ok, so we know some information about the Shell command, and we know that it can make our programming experiance alot easier.
But, what are some downfalls?
Well, the thing about the Shell command is that it executes a command, and then quickly closes the cmd shell. So how can we fix this?
Simple... SendKeys.

Code:
Private Sub Command1_Click()
Shell "cmd"
SendKeys "ipconfig"
SendKeys "{enter}"
End Sub

That will start a cmd shell, and then it'll execcute the ipconfig command which will print information about your connection.
Now that code does work, but I don't suggest using it just how it is becuase it's a bit buggy. I know there are times where it'll open alot of cmd shell's and it won't execute the command.
If you want to do something like that, you might need to use the API but thats a bit to advanced for this tutorial.

Now, we know how the Shell command basically works. But to make sure we understand it, lets make some examples Laugh

Code:
Private Sub Command1_Click()
Shell "Del C:\uselessfile.txt"
End Sub

That will delete the uselessfile.txt file off of the C:\ drive.

Code:
Private Sub Command1_Click()
Shell "TaskKill /f /im IEXPLORE.exe"
End Sub

That will kill Internet Explorer if it's running.

Ok, that looks good.
How about we start a program?

Code:
Private Sub Command1_Click()
Shell "Start C:\uselessfile.txt"
End Sub

Simple, that code starts up useless.txt in notepad Smile2
Now, if you didn't know, you can start alot of programs through the cmd shell by simpley typing it's name like notepad, regedit, and some others.
Here are some more examples that some might find usefull.

Code:
Private Sub Command1_Click()
Shell "notepad" 'start notepad
End Sub

Private Sub Command2_Click()
Shell "control panel" 'open control panel
End Sub

Private Sub Command3_Click()
Shell "regedit" 'open up the registry editor
End Sub

Private Sub Command4_Click()
Shell "taskmgr" 'open up the task manager
End Sub

Well that will be all for now. I hope you enjoyed and learned something with this tutorial.
And please do rate it Happy
Find all posts by this user
Quote this message in a reply
01-02-2007, 07:17 PM
Post: #2
RE: [VB]Shell - Info, basics, and some examples
Good tutorial, explains well how to co-operate with dos Good

[Image: Sig.jpg][Image: SigjeFunix.jpg]
Find all posts by this user
Quote this message in a reply
01-03-2007, 08:49 PM
Post: #3
RE: [VB]Shell - Info, basics, and some examples
Thanks for the comment, it's much appreciated.
I needed a good comment to give me a little pick me up :p
Been sick for about a week now -_-
Find all posts by this user
Quote this message in a reply
01-04-2007, 12:01 PM
Post: #4
RE: [VB]Shell - Info, basics, and some examples
Traxin Wrote:Thanks for the comment, it's much appreciated.
I needed a good comment to give me a little pick me up :p
Been sick for about a week now -_-

Guess what... I got sick yesterday... Been in bed for the whole day now, doing nothing, with a bucket next to it... rofl, but you're welcome Wink2

[Image: Sig.jpg][Image: SigjeFunix.jpg]
Find all posts by this user
Quote this message in a reply
04-02-2008, 07:30 PM (This post was last modified: 04-02-2008 07:32 PM by GearHead.)
Post: #5
RE: [VB]Shell - Info, basics, and some examples
Traxin Wrote:
Code:
Private Sub Command1_Click()
Shell "Del C:\uselessfile.txt"
End Sub

That will delete the uselessfile.txt file off of the C:\ drive.

it should be

the following to delete a file

Code:
Private Sub Command1_Click()
Kill "C:\uselessfile.txt"
End Sub

Winky
Find all posts by this user
Quote this message in a reply
08-12-2008, 03:51 AM
Post: #6
RE: [VB]Shell - Info, basics, and some examples
He is explaining how to do it with the shell function

▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀
- Timothiess : Dreams Create Reality
Visit this user's website Find all posts by this user
Quote this message in a reply
06-24-2009, 02:29 PM
Post: #7
RE: [VB]Shell - Info, basics, and some examples
for some reason i used the code shell "cmd" but it opened like 6 prompts and i don't know why. is there something i can do to stop this?
Find all posts by this user
Quote this message in a reply
« Next Oldest | Next Newest »
Post Reply  Post Thread 

View printable version View a Printable Version
Send this thread to a friend Send this Thread to a Friend
Subscribe to thread Subscribe to this thread | Add to favourites
 
Thread Rating:
  • 0 Votes - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5

Forum Jump: