Solved

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

Posted on 2004-04-27
11
231 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
[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
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
PeopleSoft Has Never Been Easier

PeopleSoft Adoption Made Smooth & Simple!

On-The-Job Training Is made Intuitive & Easy With WalkMe's On-Screen Guidance Tool.  Claim Your Free WalkMe Account Now

 
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
 
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

Online Training Solution

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action. Forget about retraining and skyrocket knowledge retention rates.

Question has a verified solution.

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

If you have ever used Microsoft Word then you know that it has a good spell checker and it may have occurred to you that the ability to check spelling might be a nice piece of functionality to add to certain applications of yours. Well the code that…
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.
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…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…

695 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