Solved

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

Posted on 2004-04-27
11
226 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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Introduction In a recent article (http://www.experts-exchange.com/A_7811-A-Better-Concatenate-Function.html) for the Excel community, I showed an improved version of the Excel Concatenate() function.  While writing that article I realized that no o…
Introduction While answering a recent question (http://www.experts-exchange.com/Q_27402310.html) in the VB classic zone, I wrote some VB code in the (Office) VBA environment, rather than fire up my older PC.  I didn't post completely correct code o…
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…
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…

896 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

14 Experts available now in Live!

Get 1:1 Help Now