Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
530 views
in Technique[技术] by (71.8m points)

cmd - How to run a command on command prompt startup in Windows

EDIT

If you want to perform any task at computer startup or based on an event this is very helpful

http://answers.microsoft.com/en-us/windows/forum/windows_7-performance/how-to-schedule-computer-to-shut-down-at-a-certain/800ed207-f630-480d-8c92-dff2313c193b


Back to the question

I have two questions:

  1. I want some specific commands to be executed when I start command prompt.

    e.g. cls to clear my command prompt.

  2. I want to execute some commands in a batch file and wait for the user to enter new commands (if any).

    e.g. A batch file which will take the user to some specified folder and then wait for the user to rename/delete a file from the command prompt.

How can I do it?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

If you want a defined set of commands to run every time you start a command prompt, the best way to achieve that would be to specify an init script in the AutoRun registry value. Create it like this (an expandable string value allows you to use environment variables like %USERPROFILE%):

reg add "HKCUSoftwareMicrosoftCommand Processor" /v AutoRun ^
  /t REG_EXPAND_SZ /d "%"USERPROFILE"%init.cmd" /f

Then create a file init.cmd in your profile folder:

@echo off

command_A
command_B
...
cls

To remove these changes, delete the registry key:

reg delete "HKCUSoftwareMicrosoftCommand Processor" /v AutoRun

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...