Solved

can  a file with .cmd extension be executed by a shell comman?

Posted on 2011-02-17
8
291 Views
Last Modified: 2012-05-11
Hello,
   I'm not exactly sure if the title makes sense or not but any input would be appreciated. Thanks
0
Comment
Question by:sn1fflez
8 Comments
 
LVL 8

Accepted Solution

by:
sharkbot221984 earned 167 total points
ID: 34917993
Yes. A plaintext file with a .bat or .cmd extension will be executed by the shell program -usually COMMAND.  Typically used for 'batch' scripting.
0
 
LVL 8

Expert Comment

by:sharkbot221984
ID: 34918008
Try it for yourself: create a new text file called 'test.cmd' (note you will need to be able to view extensions) with this content:

@echo off
echo test
pause

change the extension to .bat

you'll get the same thing.
0
 
LVL 1

Expert Comment

by:Kidwell_03
ID: 34918010
I agree with sharkbot221984.  Any plaintext file with a .bat or. cmd extenstion can be executed via powershell.
0
 

Author Comment

by:sn1fflez
ID: 34918148
Thank you for the quick responses. Maybe you guys can tell me why the code below doesn't work?
retval = CStr(Shell("C:\Program\INT_Fortran_ComLink.cmd", 1))

retval is declared as string

Open in new window

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 5

Assisted Solution

by:rdhoore108
rdhoore108 earned 167 total points
ID: 34918322
I don't know Visual Basic very well, but I believe the problem is that you can't execute a cmd script, you need to execute it through cmd.exe:

retval = CStr(Shell("cmd.exe /c C:\Program\INT_Fortran_ComLink.cmd", 1))
0
 
LVL 52

Expert Comment

by:Bill Prew
ID: 34919900
==> Maybe you guys can tell me why the code below doesn't work?

Is that VB6 code that you are working with?  If so, I did think that you could initiate the BAT file directly from the Shell() function, without using cmd.exe.  What type of error or problem are you seeing?

~bp
0
 
LVL 19

Assisted Solution

by:Thommy
Thommy earned 166 total points
ID: 34930575
You can execute a batch script from a batch script by using CALL command as follows...

Call C:\Program\INT_Fortran_ComLink.cmd

0
 

Author Closing Comment

by:sn1fflez
ID: 35018353
sorry it took me so long to respond. I eventually got it to work and what you guys said helped a lot. Thanks
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

One of my most closely kept secrets is revealed in this discussion How to output text on the same line This question was recently posted in EE by Simon336697 (http://www.experts-exchange.com/Programming/Languages/Scripting/Shell/Batch/Q_2459…
Being a system administrator some time we require to do things remotely, one of them is installing software. Here I am going to tell you how to install software through wmic (Windows management instrument console). I am not at all saying that this i…
Learn how to create flexible layouts using relative units in CSS.  New relative units added in CSS3 include vw(viewports width), vh(viewports height), vmin(minimum of viewports height and width), and vmax (maximum of viewports height and width).
Both in life and business – not all partnerships are created equal. As the demand for cloud services increases, so do the number of self-proclaimed cloud partners. Asking the right questions up front in the partnership, will enable both parties …

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

15 Experts available now in Live!

Get 1:1 Help Now