Solved

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

Posted on 2011-02-17
8
284 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
What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

 
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 51

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

Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

Join & Write a Comment

The following is a collection of cases for strange behaviour when using advanced techniques in DOS batch files. You should have some basic experience in batch "programming", as I'm assuming some knowledge and not further explain the basics. For some…
Using dates in 'DOS' batch files has always been tricky as it has no built in ways of extracting date information.  There are many tricks using string manipulation to pull out parts of the %date% variable or output of the date /t command but these r…
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.
This video demonstrates how to create an example email signature rule for a department in a company using CodeTwo Exchange Rules. The signature will be inserted beneath users' latest emails in conversations and will be displayed in users' Sent Items…

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

20 Experts available now in Live!

Get 1:1 Help Now