Efficient office, a few lines from a batch script to start, you know?

Inscription: n remember years ago, just started working, a chicken dish, leadership tight time card, there are times exactly 8:29 clocking, and next door to the seat at the same table at the same time flying, began to turn on the computer, ready to log on the mailbox, open VC ++ 6.0, open the database ... open all the open. When I first enter the mailbox password, leadership behind the faint to the sentence: "How come you have not yet open environment, both 8:31 the next you look at XXX, people have begun to write code to work overtime at night, the. time to make it up .... " Toumiao one next door, and sure enough Gangster already crackling knocking the code, a kind of contempt for the voice in my ear. Later learned that people with a very efficient tool to automatically boot environment. This is the legend of the batch. Behind rookie I grew up, learned this technique, share out today. hope this helps.

In the workplace, time is money, efficiency is comparable to "life." Can leadership be completed on time and efficient layout tasks related to the follow-up assessment evaluation appreciate a raise, and took to the pinnacle of life, marry white Formica. Of course, there are some big brother home with mine, I would not say this ranks. For, like me, silently nine to five, look forward to one day programmers have water dragon, technological progress is the key, but whether the technology into the ladder of self-improvement, which requires quietly draw a question mark in everyone's mind .

Without further ado, today to share the article, explain how frequent the usual monotonous work, operating through the system comes with command line, it becomes automatic, you do not need everything themselves, save time and improve efficiency.

1, shutdown and restart
1.1 Shutdown

If you feel too much trouble to manually shut down every day, to give you a command line, let the computer automatically shut down regular day.

@echo off
at 00:00 shutdown -s -f REM 每天00:00关闭所有程序后关机。

Save this line commands to a .bat file, Win7 system to drag the " Start → Programs → start " directory, Win10 system drag to " C: \ ProgramData \ in the Microsoft \ Windows \ Start Menu \ Programs \ StartUp " path day to 00 points (specific time modified according to individual requirements), Windows will automatically execute commands ---- shutdown.

1.2 restart

If you frequently need to restart the computer, one step to seal the deal!

@echo off
:: -t表示等待时间,0表示立刻重启
shutdown -r -t 0
1.3, write-off

Logout computer, the same step to get! !

@echo off
:: -f 表示强制注销,不会提示用户
shutdown -l -f
1.3 hibernate
@echo off

:: 立刻休眠计算机
shutdown -h 

The above is part of the command used in daily life, if you want to delve into, you can see the direct help manual, enter cmd interface, type command /? To see more command as follows:
Here Insert Picture Description

2, back up data

If you have a copy of the data, the need for regular backup to a server or other location, you are not required to paste the copied it every time? Repeat doing this one thing, is not very boring, plus time is money, how can there be so much time repeat-create the wheel? Here to give you a medicine, used well, can save a lot of time and improve efficiency.

@echo off

::文件来源为本机e盘的work文件夹
set source=D:\work
::目标文件夹为PC机192.168.0.1的backup文件夹
set dest=\\192.169.1.12\backup
:: 登录远程环境
net use \\192.169.1.12\IPC$ "adm123" /user:"administrator"
:: 拷贝
xcopy /e /v /r /y /z %source% %dest% 

The above script on the desktop or add time to start tasks, each scheduled backups, you can save a lot of time is not it?

3, WinRAR Magical

    WinRAR is simply an artifact, Why? Prior to work, there are many tasks is to regularly upgrade project, and then posted on the company's official website, but some projects have not iterative, no need to update, and normally only need to be updated to modify the line. More than 20 projects, the need to manually check every package again, and then submit updated, very tedious. Fortunately, later met WinRAR this artifact, I only takes one time, the need to package content compressed tell it, follow me just double-click it, it can help me to complete the outstanding tasks, the most important point, it can Auto contrast file has not been modified, so as to decide whether or not to copy, save a lot of time.
    WinRAR has been able to find their own files need to be backed up on a secret list of files. This extension to the 1st file is actually a plain text file, the contents of which is a list of files to be backed up, you need to provide the complete path to the backup file.

\\fst1\work // 机器1上的工作文件夹
\\fst2\work // 机器2上的工作文件夹

① new in your favorite directory folder, such as data, create a new text file, enter the list of the top two lines, save as .lstYou can, remember the file extension is LST .
② After the completion of the preparation of the above documents, followed by WinRAR data backup. Open the data folder, right-click in the blank space, select "New → Shortcut" in the pop-up "Create Shortcut" dialog box, enter the following command:

"C: \ program files \ WinRAR \ WinRAR.exe" u -y -ep2 d: \ data \ data.rar @d: \ data \ bak.1st

Click "Next" until complete, you can create a shortcut. The above command line parameter meaning is:

  • u represents the compressed file update package;
  • -ep2 means that when compression store the full file path;
  • -y means that all queries are answered "yes."

Some, however, a new version of the file is not completely replace the old version, and therefore can not be updated replacement must be saved as a different backup files each day. At this point, we command in the "Create Shortcut" dialog box to enter should look like this:

** ″C:\Program files\WinRAR\WinRAR.exe″ a -ep2 -ag ddmmyy d:\data\data.rar @d\data\bak.1st **

Wherein, "-Ag" indicates the current date and time to generate a compressed file name, the additional strings behind "ddmmyy" represented by the date format. data.rar for the base file name, file name behind the last generation we will be in accordance with the format specified date attached. Thus, each time the shortcut operation, the disc D will be in the server's data folder data200321.rar generate a backup file of the form.

4, Batch Launcher

    As said at the beginning, as they were led hanging, because what is it? 8:30 to work on time, 8:31, when the work environment did not open, still slow logon mailbox, big brother next contrast, has started to work, of course, not comfortable with the leadership of the heart, then how can you make quickly open work environment, work efficiently it, the following command line to help you.
    With the batch command start it, will need to start the programming is good, just double-click to start or join items, boot will be started directly.

@echo off 

echo Start Google..
start "" "C:\Program Files (x86)\Chrome\chrome.exe"

echo Start youdao..
start "" "D:\Program Files (x86)\youdao"

:: 按照上述格式,将需要打开的程序路径写在start后的第二个参数位置即可。
5, add routes

    When rookie newly recruited staff, the company network there are many small network segment, even how Rom, ask mentors, tutors use a command line, so I can smooth the network, the original is adding a route, I believe a lot of new people entering the workplace also I encountered such a small problem. Here are the final script.

:: 添加永久路由
route add 192.168.0.0 mask 255.255.0.0 192.169.13.1 -p

    The above command will add the route to 192.169.13.1 192.168.0.0 network gateway, such bloggers 192.169.13.5 can access all servers 192.168.0.0 network segment. Details about the route command, use the /? Parameter view, you can see the bloggers summary of mind mapping , at the end of chapters in this article.

6, batch script compiled code

    As we all know, Windows is developed under C ++, visual interface, commonly used Visual Studio series, this visual programming tool that provides a fool-programming process. As long as you write business code, click Compiler "Rebuild Solution", the compiler will automatically help you compile a program, you do not need to understand the principles of the compiler, you can easily finish work. However, the question is, for example, you have multiple projects n, is not the same solution, if you want to publish version, you are not required in order to open a number of projects which n, Click on a compilation? Zhou and forth, never tired?
    In fact, we all know that we remain sensitive to new, fresh after a period, generally will feel boring boring, legendary marriage is like this, I do not know whether all of you big brother experience? That is also true compiler, each release version, you must do so, sick of it. That it supposed to do? Give you a trick, so you only once fresh, cool! ! !
    Entered, bloggers will use a script years ago batch compilation projects posted in Windows, needy students can be reused.

Startup file

@echo off

set TargetDirOld=MyWork
set TargetDir=%~dp0%date:~0,4%%date:~5,2%%date:~8,2%_MyWork.100
set TargetDir1=%~dp0%date:~0,4%%date:~5,2%%date:~8,2%MyWork.100Bak
set LogFile=%~dp0output.txt 

set deven2008="C:\Program Files (x86)\Microsoft Visual Studio 9.0\Common7\IDE\devenv.exe"

if exist %LogFile% (
 del %LogFile%
) 

echo 原文件夹:%TargetDirOld% >>%LogFile%
echo 目标文件夹:%TargetDir% >>%LogFile% 

echo 1、拷贝原文件
if not exist %TargetDir% ( 
 mkdir %TargetDir%
)
if not exist %TargetDir1% (
 mkdir %TargetDir1%
)

cd ..
echo 开始拷贝文件,%Date% %time%
echo 当前路径:%cd% 
echo 目标为 %TargetDir% ,拷贝一份作为最终文件
xcopy /y /R /e %TargetDirOld%\*.* %TargetDir% >>%LogFile%
echo 目标为 %TargetDir% ,拷贝一份作为编译临时文件
xcopy /y /R /e %TargetDirOld%\*.* %TargetDir1% >>%LogFile%

::进入编译目录
cd %TargetDir1%  
echo 当前路径 : %cd% 

cd ..
echo 开始编译 %Date% %time%
call VideoPlay.bat %deven2008% %TargetDir1% %TargetDir% %LogFile%
echo 编译结束,当前路径 %cd%
echo 结束编译时间 %Date% %time%

echo
pause

Specific project file

@echo off

:: 接收调用者传入的参数
:: 编译器路径
set buildTarget=%1%
:: 需要编译目录
set source=%2%
:: 编译后拷贝路径
set target=%3%
:: 日志路径
set logFile=%4%

echo  ===========开始编译 VideoPlay 项目===================

set current=%source%\VideoPlay\
set targetNew=%target%\VideoPlay\


pushd %current%

    %buildTarget% VideoPlay.sln /rebuild "RELEASE|Win32" /out %logFile% 
    copy %current%\bin\VideoPlay.exe %targetNew%\bin\
    
popd 

echo  ===========编译完成 VideoPlay demo===================

Some of the symbols explained above script as follows:

::    英文双冒号是注释作用,也可以用REM 后加注释内容。
@     显示当前命令不要在控制台输出回显。如@echo off 关闭所有命令输出的回显。
set   设置变量,后续引用,需要用 %变量% 这种形式。
call  启动批处理文件,可以实现传参。传入的参数在被调用文件中以%1%、 %2%等依次接收。
pushd 切换到后面的路径下。
popd  退出切换后的路径,返回到之前的原始路径。
特别提醒:批处理文件中一段字符串中切记不能出现空格,有空格就会被解析为两段字符串。

    Introduction to bloggers batch file, this involves only a few simple batch command, there are many, many, such as compression packing after compilation released a series of processes, batch processing can be used to get. Bloggers subsequent finishing commonly used batch commands, the same mind map issued forms to facilitate the reference study.

7, other commands

The following summarizes the commands from the network, most of the bloggers own tests on the computer too, and there is need to look.

ver 在DOS窗口下显示版本信息 
winver 弹出一个窗口显示版本信息(内存大小、系统版本、补丁版本、计算机名) 
format 盘符 /FS:类型 格式化磁盘,类型:FAT、FAT32、NTFS ,例:Format D: /FS:NTFS 
md 目录名 创建目录 
replace 源文件 要替换文件的目录 替换文件 
ren 原文件名 新文件名 重命名文件名 
tree 以树形结构显示出目录,用参数-f 将列出第个文件夹中文件名称 
type 文件名 显示文本文件的内容 
more 文件名 逐屏显示输出文件 
doskey 要锁定的命令=字符
doskey 要解锁命令= 为DOS提供的锁定命令(编辑命令行,重新调用win2k命令,并创建宏)。如:锁定dir命令:doskey dir=entsky (不能用doskey dir=dir);解锁:doskey dir= 
taskmgr 调出任务管理器 
chkdsk /F D: 检查磁盘D并显示状态报告;加参数/f并修复磁盘上的错误 
tlntadmn telnt服务admn,键入tlntadmn选择3,再选择8,就可以更改telnet服务默认端口23为其它任何端口 
exit 退出cmd.exe程序或目前,用参数/B则是退出当前批处理脚本而不是cmd.exe 
path 路径\可执行文件的文件名 为可执行文件设置一个路径。 
cmd 启动一个win2K命令解释窗口。参数:/eff、/en 关闭、开启命令扩展;更我详细说明见cmd /? 
regedit /s 注册表文件名 导入注册表;参数/S指安静模式导入,无任何提示; 
regedit /e 注册表文件名 导出注册表 
cacls 文件名 参数 显示或修改文件访问控制列表(ACL)——针对NTFS格式时。参数:/D 用户名:设定拒绝某用户访问;/P 用户名:perm 替换指定用户的访问权限;/G 用户名:perm 赋予指定用户访问权限;Perm 可以是: N 无,R 读取, W 写入, C 更改(写入),F 完全控制;例:cacls D:\test.txt /D pub 设定d:\test.txt拒绝pub用户访问。 
cacls 文件名 查看文件的访问用户权限列表 
REM 文本内容 在批处理文件中添加注解 
netsh 查看或更改本地网络配置情况

8. Mind Mapping batch command summary

    All batch script posted in this section summarizes the mind map, in view of the length of the relationship, the other maps as an asset spread to the next blogger resources, free download, includes front involved, the original mind map, mind map pictures, etc., need venue can download .

Here Insert Picture Description

9, written at the end of

    Inspired article from blogger recent project requirements, but to engage in a batch before relatively long time, actually forget the previous knowledge, time really nasty people, took my youth. So come back to, and rummaging through to find out the notes before, finished demand, organize your notes the way here, if you also work encountered the same problem, you can learn to solve, I hope you can help. If it helps you, please support me like attention, follow-up there will be more dry goods output; if you find problems in reading or bug, or leave a message at any time private letter to me, I will update, so that more needed people can benefit. Thanks a million ~
This article is derived from a blogger CSDN

Guess you like

Origin www.cnblogs.com/MarDebug/p/12546882.html