Solved

Batch Script for opening the DOS prompt and run a command

Posted on 2016-08-29
9
90 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 51

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
 

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
How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

 
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 51

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

Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

Join & Write a Comment

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…
Being a system administrator some time we require to do things remotely, one of them is installing software. Here I am going to tell you how to install software through wmic (Windows management instrument console). I am not at all saying that this i…
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, Just open a new email message.  In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…
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…

760 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

22 Experts available now in Live!

Get 1:1 Help Now