Solved

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

Posted on 2011-02-17
8
293 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
Are your AD admin tools letting you down?

Managing Active Directory can get complicated.  Often, the native tools for managing AD are just not up to the task.  The largest Active Directory installations in the world have relied on one tool to manage their day-to-day administration tasks: Hyena. Start your trial today.

 

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

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

Enterprise Mobility and BYOD For Dummies

Like “For Dummies” books, you can read this in whatever order you choose and learn about mobility and BYOD; and how to put a competitive mobile infrastructure in place. Developed for SMBs and large enterprises alike, you will find helpful use cases, planning, and implementation.

Question has a verified solution.

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

TOMORROW TOMORROW.BAT is inspired by a question I get asked over and over again; that is, "How can I use batch file commands to obtain tomorrow's date?" The crux of this batch file revolves around the XCOPY command - a technique I discovered w…
VALIDATING DATES One method of validating dates is to jam the date into the DATE command and see if it accepts it by examining the system's errorlevel value. A non-zero result indicates failure. A typical example might look something like the fol…
This Micro Tutorial will give you a basic overview how to record your screen with Microsoft Expression Encoder. This program is still free and open for the public to download. This will be demonstrated using Microsoft Expression Encoder 4.
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…

821 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