Wrox Programmer Forums
Go Back   Wrox Programmer Forums > Microsoft Office > Access and Access VBA > Access VBA
|
Access VBA Discuss using VBA for Access programming.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Access VBA section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old December 7th, 2006, 10:12 AM
Registered User
 
Join Date: Apr 2006
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
Default Sending a string of commands to the command prompt

I'll try to explain this as well as I can.

I already know how to open the command prompt send an initial command to it, such as:

StrInput = "TELNET.EXE " + IPAddr
    Call Shell(StrInput, 1)

What I'm trying to do now is open the command prompt and send a list of commands to it.

Here is an example set of commands I want to execute:

telnet 1.2.3.4
admin
password
system
reboot

As you can see, from within Access I want to have a button that I push that will telnet to a device and reboot it. Is this possible?

 
Old December 7th, 2006, 11:13 AM
Friend of Wrox
 
Join Date: Sep 2003
Posts: 155
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via Yahoo to leehambly
Default

Wire,

Not sure if this is the best suggestion but something I have used in the past is to build a batch file from your command lines and then run the batch file.

1. So you need something to build the commands, which you look like you already have.
2. You also need to create a textfile, the FileSystemObject will help you with this... as will I, if you have no experience of this.
3. then you need to save the textfile and then Execute it, which is fairly similar to your current routine, ie: Call Shell().

Of course, there may be a more suitable process which will allow individual lines to be sent to the same instance of the command prompt.

If you need help with the fso, just shout.

Lee
 
Old December 7th, 2006, 11:42 AM
Registered User
 
Join Date: Apr 2006
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
Default

I could probably use some help. Let me know if I'm on the right track so far:

Dim FileNum As Integer
Dim TelnetScript As String

TelnetScript= _
"ftp " + IPAddr + vbCrLf + _
"admin" + vbCrLf + _
"password" + vbCrLf + _
"system" + vbCrLf + _
"reboot" + vbCrLf

On Error GoTo Err_cmdtelnet_Click

FileNum = FreeFile
Open "c:\" + "telnet script.txt" For Output As #FileNum
Print #FileNum, TelnetScript
Close #FileNum

Exit_cmdTelnet_Click:
    Exit Sub

Err_cmdTelnet_Click:
    MsgBox "The text file wasn't created"
    Resume Exit_cmdTelnet_Click

Where would I go from here?


 
Old December 14th, 2006, 05:59 AM
Friend of Wrox
 
Join Date: Sep 2003
Posts: 155
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via Yahoo to leehambly
Default

Not quite the way I would have done it, but as long as the file is created then you're on a winner. You will want to rename the file to .bat though, otherwise it will merely be opened in notepad!

Now execute the file, Call Shell (filename) I think should do the trick.

Lee
 
Old December 14th, 2006, 06:14 AM
Friend of Wrox
 
Join Date: Sep 2003
Posts: 155
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via Yahoo to leehambly
Default

Been a while since I did this... you need to identify the commmand.com file, someone else (TheAccessWeb) has done this for us, fortunately... so:

Call Shell(Environ$("COMSPEC") & " /c " & strFile, vbNormalFocus)

where strFile is your batchfile to be executed.





Similar Threads
Thread Thread Starter Forum Replies Last Post
Issue Sending SMS using AT commands tavi C# 4 September 4th, 2007 09:09 AM
command prompt karthisena BOOK: ASP.NET Website Programming Problem-Design-Solution 1 February 27th, 2007 04:11 AM
Command Prompt karthisena General .NET 2 January 25th, 2007 12:29 PM
Command Prompt Compile andyj00 ASP.NET 1.0 and 1.1 Professional 1 June 16th, 2005 10:28 AM
Command Prompt joconnor PHP How-To 1 August 11th, 2004 06:29 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.