Solved

Batch Script for opening the DOS prompt and run a command

Posted on 2016-08-29
9
142 Views
Last Modified: 2016-09-18
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
0
Comment
Question by:Deepak Kumar
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
  • 2
  • +1
9 Comments
 
LVL 35

Expert Comment

by:[ fanpages ]
ID: 41774570
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
1
 
LVL 12

Expert Comment

by:Gary Dewrell
ID: 41774646
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
0
 
LVL 56

Accepted Solution

by:
Bill Prew earned 500 total points
ID: 41775667
You don't need a BAT script for this, just schedule the following command line to run in Task Scheduler.

cmd /c tasklist>c:\temp\TasklistDetails.csv

Open in new window

~bp
1
Free learning courses: Active Directory Deep Dive

Get a firm grasp on your IT environment when you learn Active Directory best practices with Veeam! Watch all, or choose any amount, of this three-part webinar series to improve your skills. From the basics to virtualization and backup, we got you covered.

 

Author Comment

by:Deepak Kumar
ID: 41775789
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
0
 
LVL 35

Expert Comment

by:[ fanpages ]
ID: 41796004
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
0
 
LVL 56

Expert Comment

by:Bill Prew
ID: 41796005
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
0
 
LVL 35

Expert Comment

by:[ fanpages ]
ID: 41796298
Answering the question posed is obviously not worth anything now.

This site gets worse by the day.

Sigh.
0
 

Author Comment

by:Deepak Kumar
ID: 41804319
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
0

Featured Post

What is SQL Server and how does it work?

The purpose of this paper is to provide you background on SQL Server. It’s your self-study guide for learning fundamentals. It includes both the history of SQL and its technical basics. Concepts and definitions will form the solid foundation of your future DBA expertise.

Question has a verified solution.

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

When you receive another warning that your shared drive is almost full and you have asked your users to clean out old files again and again, here is a single command that may help. This command will place all the files that have not been used rec…
AutoHotkey is an excellent, free, open source programming/scripting language for Windows. It started out as a keyboard/mouse macros product, but has expanded into a robust language. This article provides an introduction to it, with links to addition…
There are cases when e.g. an IT administrator wants to have full access and view into selected mailboxes on Exchange server, directly from his own email account in Outlook or Outlook Web Access. This proves useful when for example administrator want…
Michael from AdRem Software explains how to view the most utilized and worst performing nodes in your network, by accessing the Top Charts view in NetCrunch network monitor (https://www.adremsoft.com/). Top Charts is a view in which you can set seve…

622 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