Link to home
Start Free TrialLog in
Avatar of Deepak Kumar
Deepak KumarFlag for San Marino

asked on

Batch Script for opening the DOS prompt and run a command

Hi there,
   
    I need a batch script code which does the following
1)Open a command prompt
2)Run the Tasklist (Dos Command which provides the services and processes details and get the output in csv file)
    For this i run it in cmd prompt like as "tasklist>TasklistDetails.csv"
3)The above command from dos prompt works like charm, but however I am not sure how to put this command in .bat file and make to run as  windows  scheduled task

Thanks
Deepak
Avatar of [ fanpages ]
[ fanpages ]

If I understand your question correctly, I think you just need a simple ASCII Text file, say, "tasklist-cmd.bat", with the single line:

tasklist>TasklistDetails.csv

Use this file within the MS-Windows Task Scheduler (as attached, after renaming from "tasklist-cmd.bat.txt" to "tasklist-cmd.bat" in your local filing system).

The ".csv" file output will be created in the same folder where the ".bat" file is located...

...but this is not a Comma-Separated Values file (if that is what you were intending).

For that, the command will be:

tasklist /FO CSV>TasklistDetails.csv

(Please see attachment "tasklist-csv-cmd.bat.txt"; also rename to a file with just a ".bat" file extension).
tasklist-cmd.bat.txt
tasklist-csv-cmd.bat.txt
fanpages has your answer, I just wanted to share an additional option.
If the OS you are running has powershell installed then this command will also give you want you want and allow you some more customizations such as what information you want.

get-scheduledtask | export-csv  tasklist.csv
ASKER CERTIFIED SOLUTION
Avatar of Bill Prew
Bill Prew

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Deepak Kumar

ASKER

Hi All,

   Thank you all for your suggestions. I have setup a task in task scheduler based on Bill's suggestion.
Will post if anything required. You guys are really helping me out.

thanks
Deepak
I've requested that this question be closed as follows:

Accepted answer: 250 points for [ fanpages ]'s comment #a41774570
Assisted answer: 125 points for gdewrell's comment #a41774646
Assisted answer: 125 points for Bill Prew's comment #a41775667

for the following reason:

Suggested split:

fanpages (Best Answer): 250 points
gdewrell (Assisted Solution): 125 points
Bill Prew (Assisted Solution): 125 points
Hard to say what the OP found as useful, but he certainly called out the last post by billprew as part of their solution, so I would suggest an equal split rather than a weighted split:

    [ fanpages ]'s comment #a41774570 (167 points)
    gdewrell's comment #a41774646 (166 points)
    Bill Prew's comment #a41775667 (166 points)

~bp
Answering the question posed is obviously not worth anything now.

This site gets worse by the day.

Sigh.
Hi All,
  I have tried all of your suggestions and found that Bill's suggestion was easy to implement. Thank you all for your help.
According to me the points should be split as below,

1)FanPages -200 points

2)Bill Prew - 200 points

3) gdewrell's - 100 points

Please note, I feel that I have justified in giving points based on your assistance provided.

Thanks
Deepak