Welcome to Dream.In.Code
Become a VB Expert!

Join 137,267 VB Programmers for FREE! Get instant access to thousands of VB experts, tutorials, code snippets, and more! There are 1,496 people online right now. Registration is fast and FREE... Join Now!




Shell Comand

 
Reply to this topicStart new topic

Shell Comand, Shell Command

gregoryjg
26 Dec, 2006 - 12:25 PM
Post #1

New D.I.C Head
*

Joined: 26 Dec, 2006
Posts: 2


My Contributions
I have one problem and one question about using the shell command. Looking in books and the web I have not been able to find an answer yet. If somone could shed some light or point me in the right direction I would be greatly appreciate it.

Problem:
At the command prompt I can type: "ping PCName > c:\results.txt" and it creates the file results.txt and inserts the results in the text file. In my VB program I use the shell command and run: "ShellID = Shell("ping " & trim(txtpcname.text) & " > c:\results.txt", vbnormalfocus)" and the windows opens and closes with no txt file being created. I even have tried "PingIt = "Ping " & trim(txtpcname.text) & " > c:\results.txt"" then "Shell(PingIt, vbnormalfocus) " with the same results. When I get a screen capture of the windows it says, "Bad parameter >." So why does it work from the command prompt but not the shell command?

Questions:
When I run a shell command I get a number in the ShellID "ShellID = Shell("ping " & trim(txtpcname.text) & " > c:\results.txt", vbnormalfocus)". What is that number? Is it just a random number, or does the numbers have a meaning that I could use to test if it was successfull or not?
User is offlineProfile CardPM
+Quote Post

m2s87
RE: Shell Comand
26 Dec, 2006 - 04:20 PM
Post #2

D.I.C Regular
Group Icon

Joined: 28 Nov, 2006
Posts: 390



Thanked: 1 times
Dream Kudos: 1225
My Contributions
If you just want to get it working as in cmd, just copy paste code from here.

now you can use
CODE
a = ExecCmdPipe("ping " & trim(txtpcname.text))
, and if you want to put it still in a file just
CODE
    a = ExecCmdPipe("ping " & trim(txtpcname.text))
    Call wrf("c:\results.txt", a)


This post has been edited by m2s87: 26 Dec, 2006 - 04:22 PM
User is offlineProfile CardPM
+Quote Post

gregoryjg
RE: Shell Comand
27 Dec, 2006 - 09:50 AM
Post #3

New D.I.C Head
*

Joined: 26 Dec, 2006
Posts: 2


My Contributions
Thanks for the help!

The code works well for pinging and other simple commands. A couple of problems I have is that when I mapped to the computer I ping it worked great. But when I ran it again I failed to un-map the drive and it caused my computer to lock up. It also locked up when I tried to use the XCOPY command. Every time it locks up at the following line "bSuccess = ReadFile(hReadPipe, mybuff, Len(mybuff), bytesread, 0&)". Is there a better way to test if it was successfull or not? Or better way to bring back the error message?

Again thanks for the help!
User is offlineProfile CardPM
+Quote Post

Fast ReplyReply to this topicStart new topic
Time is now: 12/4/08 07:36PM

Live VB Help!

VB Tutorials

Reference Sheets

VB Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month