Solved

Shelling Command to run a Batchfile (WILL YOU EVER WORK???)

Posted on 2004-04-27
11
225 Views
Last Modified: 2010-05-02
Oh Masters of the universe :P


Hey all before you say that this is a simple shell to the command line to excute a batch file think again. The reason i can't just shell the file is that the batch file takes time to execute .. Between processes.. So i have to wait. So i decide to use SHELLEXECUTEINFO which waited for the process to finish as all you know. This worked great for me but then the batch file got bigger and this no longer works .... So now when the command prompt runs nothing happens .. Well the batchfile is run but then nothing ... It doesn't execute the file. If i click on the batchfile and run it everything works fine ....

Thanks in advance,

Simpson  
0
Comment
Question by:shutuplonnie
11 Comments
 

Author Comment

by:shutuplonnie
ID: 10931304
Hahahaha Whoops forgot the part where i need to say I need to be able to run this batchfile without clicking on it ...

Thanks guys ..


Simpson
0
 
LVL 1

Expert Comment

by:hal3000
ID: 10931759
Hi shutuplonnie,

SHELLEXECUTEINFO is a structure and not an executable command.

What are you using to execute the batchfile?

What platform are you running?

Good luck
0
 
LVL 11

Expert Comment

by:jmwheeler
ID: 10932157
Try This


Public Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Long

Shell("C:\YourBatchFile.bat")

Do
   Do Events
Until FindWindow(vbNullString, "C:\WIN2000\system32\cmd.exe) = 0          'substitute the caption from the window that appears, this example is for Windows 2000


0
 
LVL 11

Accepted Solution

by:
jmwheeler earned 250 total points
ID: 10932178
Sorry, Do Events should be no spaces.
 
ex.

Shell("C:\YourBatchFile.bat")
Do
   DoEvents
Until FindWindow(vbNullString, "C:\WIN2000\system32\cmd.exe) = 0          'substitute the caption from the window that appears, this example is for Windows 2000


This should stop your program until the batch file is done.
0
 
LVL 9

Expert Comment

by:p_sie
ID: 10932216
Use the ShellExecute API , Shell only works with exe-files !!
0
How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

 
LVL 76

Expert Comment

by:David Lee
ID: 10932281
0
 
LVL 11

Expert Comment

by:jmwheeler
ID: 10933517
p_sie, your wrong.  Shell works just fine with batch files.
0
 
LVL 9

Expert Comment

by:p_sie
ID: 10936403
From MSDN

Shell Function
Runs an executable program and returns a Variant (Double) representing the program's task ID if successful, otherwise it returns zero.
---------------------------------------------------
As it says : executable program , don't think a bat file is an executable program!
And I use ShellExecute and that works perfectly!
0
 
LVL 11

Expert Comment

by:jmwheeler
ID: 10943991
Regardless of what msdn says if you type in Shell("C:\Autoexec.bat") your program will run Autoexec.bat.
0
 
LVL 9

Expert Comment

by:p_sie
ID: 10947307
jmWheeler,

you are right I tried it and it worked, but in my memory I know I had trouble with the Shell function once, don't remember what, and since then
I am using ShellExecute and that works fine ...

0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Introduction While answering a recent question about filtering a custom class collection, I realized that this could be accomplished with very little code by using the ScriptControl (SC) library.  This article will introduce you to the SC library a…
This article describes some techniques which will make your VBA or Visual Basic Classic code easier to understand and maintain, whether by you, your replacement, or another Experts-Exchange expert.
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
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…

705 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

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now