Solved

Execute Autoexec-like File(s)

Posted on 2001-07-23
8
309 Views
Last Modified: 2006-11-17
Hi Experts,
Can VB executes (or acts as) a autoexec-like file, which could execute line per line, for each command line? I need some examples for this questions.

Thank you.
0
Comment
Question by:MaxLen
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
8 Comments
 
LVL 3

Expert Comment

by:andysalih
ID: 6308978
yes

do you mean shell out and execute some .exes

shell "c:\command.com /e file.exe",,vbshow
shell "c:\command.com /e file1.exe",,vbshow

end sub



otherwise if you are wanting this to execute when you are booting the computer the only way to do it is to create and autoexec.bat file which points to your compiled .exe VB app.

but what would the point of the be because you will be able just to do the same in a batch file.

id still answer no you cannot do a vb - autoexec.bat file. without loading the exe file of the vb app first.

hope this helps
Andy
0
 
LVL 4

Expert Comment

by:VincentLawlor
ID: 6309012
Copy and Paste this code
It should do the trick

Private Declare Function ShellExecute Lib "shell32.dll" Alias _
     "ShellExecuteA" (ByVal hwnd As Long, ByVal lpszOp As _
     String, ByVal lpszFile As String, ByVal lpszParams As String, _
     ByVal lpszDir As String, ByVal FsShowCmd As Long) As Long

     Private Declare Function GetDesktopWindow Lib "user32" () As Long

     Const SW_SHOWNORMAL = 1

     Const SE_ERR_FNF = 2&
     Const SE_ERR_PNF = 3&
     Const SE_ERR_ACCESSDENIED = 5&
     Const SE_ERR_OOM = 8&
     Const SE_ERR_DLLNOTFOUND = 32&
     Const SE_ERR_SHARE = 26&
     Const SE_ERR_ASSOCINCOMPLETE = 27&
     Const SE_ERR_DDETIMEOUT = 28&
     Const SE_ERR_DDEFAIL = 29&
     Const SE_ERR_DDEBUSY = 30&
     Const SE_ERR_NOASSOC = 31&
     Const ERROR_BAD_FORMAT = 11&

     Function StartDoc(DocName As String) As Long
         Dim Scr_hDC As Long
         Scr_hDC = GetDesktopWindow()
         StartDoc = ShellExecute(Scr_hDC, "Open", DocName, _
         "", "C:\", SW_SHOWNORMAL)
     End Function

Private Sub Command1_Click()

Dim r As Long, msg As String
         r = StartDoc("Name of Program")
         If r <= 32 Then
             'There was an error
             Select Case r
                 Case SE_ERR_FNF
                     msg = "File not found"
                 Case SE_ERR_PNF
                     msg = "Path not found"
                 Case SE_ERR_ACCESSDENIED
                     msg = "Access denied"
                 Case SE_ERR_OOM
                     msg = "Out of memory"
                 Case SE_ERR_DLLNOTFOUND
                     msg = "DLL not found"
                 Case SE_ERR_SHARE
                     msg = "A sharing violation occurred"
                 Case SE_ERR_ASSOCINCOMPLETE
                     msg = "Incomplete or invalid file association"
                 Case SE_ERR_DDETIMEOUT
                     msg = "DDE Time out"
                 Case SE_ERR_DDEFAIL
                     msg = "DDE transaction failed"
                 Case SE_ERR_DDEBUSY
                     msg = "DDE busy"
                 Case SE_ERR_NOASSOC
                     msg = "No association for file extension"
                 Case ERROR_BAD_FORMAT
                     msg = "Invalid EXE file or error in EXE image"
                 Case Else
                     msg = "Unknown error"
             End Select
             MsgBox msg
         End If
     
end sub

Vin.
0
 
LVL 8

Expert Comment

by:Dave_Greene
ID: 6309079
Private Sub Form_Load()
 Dim arrParams() as string
 arrParams = Split(Command$," ")
 For i = 1 To UBound(arrParams)
   msgbox arrParams(i)  'do you line items here...
 Next
End Sub
0
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
LVL 28

Expert Comment

by:Ark
ID: 6310952
VB works exactly same way - execute code line-by-line.

Private Sub Command1_Click()
    Dim sCmd As String
    Open "c:\autoexec.bat" For Input As #1
        While Not EOF(1)
          Line Input #1, sCmd
          Shell "start " & sCmd, vbHide
        Wend
    Close #1
End Sub

Cheers
0
 
LVL 8

Expert Comment

by:glass_cookie
ID: 6311388
Hi!

Here's a file over the net for you:

Download...
http://www.planetsourcecode.com/upload/ftp/CODE_UPLOAD14742292001.zip

Description: This code will show you how to open an .ini file into a listbox, then take a random line from that listbox. This code is useful for programs like Hangman or Magic 8-Ball

You may want to use this code to load your file, into a listbox, then read the listbox line by line and then using the instr method to get the command or whatever then shell whatever application that you want.

That's it!

glass cookie ; )
0
 
LVL 8

Accepted Solution

by:
glass_cookie earned 100 total points
ID: 6311392
Hi!

This is a better example:

Download...
http://www.planetsourcecode.com/upload/ftp/CODE_UPLOAD3851372000.zip

Descrition: This routine will open an file, read it line by line and put each line in a listbox. When the text stops (there is no text anymore in the file)the program will also stop. So each line in ur file will come in a listbox

That's it!

glass cookie : )
0
 
LVL 4

Expert Comment

by:vindevogel
ID: 6311701
MaxLen,
It can, as described above.

But, may I suggest something else ?

Why don't you write your code into a .VBS file.
That's pure Visual Basic, and you can simply run it from the command prompt by typing "yourfile.vbs", since VBS files are automatically linked to the scripting environment just like a .exe, .bat or .com are executables.
0
 
LVL 4

Expert Comment

by:wileecoy
ID: 6529344
MaxLen,

Status update?  Are these the things you are looking for?

If I understand, you want to provide a method for processing commands line by line, similar to a batch file (which the autoexec acts like).

One option is a batch file.  If you want it to initiate at startup, you can call for it in the autoexec.bat.

Conversely, if you want to process other code, you can create a VB.exe that will process the code you want, and place the exe in the StartUp folder so that it will always run on start-up.

If you want the user to be able to dynamically change what is processed, you could use a text file.  Your program would look to the text file for the commands to process.

Is this what you are looking for?? If not, what do you need that is not posted.

Thanks.

Wileecoy.
0

Featured Post

Get HTML5 Certified

Want to be a web developer? You'll need to know HTML. Prepare for HTML5 certification by enrolling in July's Course of the Month! It's free for Premium Members, Team Accounts, and Qualified Experts.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Most everyone who has done any programming in VB6 knows that you can do something in code like Debug.Print MyVar and that when the program runs from the IDE, the value of MyVar will be displayed in the Immediate Window. Less well known is Debug.Asse…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…
Suggested Courses
Course of the Month3 days, 22 hours left to enroll

630 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question