Solved

Batch Script for opening the DOS prompt and run a command

Posted on 2016-08-29
9
111 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
  • 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 53

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
3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

 

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 53

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

3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

Question has a verified solution.

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

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…
You may have already been in the need to update a whole folder stucture using a script. Robocopy does it well and even provides a list of non-updated files in a log (if asked to). Generally those files that were locked by a user or a process by the …
Microsoft Active Directory, the widely used IT infrastructure, is known for its high risk of credential theft. The best way to test your Active Directory’s vulnerabilities to pass-the-ticket, pass-the-hash, privilege escalation, and malware attacks …
This video shows how to quickly and easily add an email signature for all users on Exchange 2016. The resulting signature is applied on a server level by Exchange Online. The email signature template has been downloaded from: www.mail-signatures…

803 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