中国DOS联盟论坛

中国DOS联盟

-- 联合DOS 推动DOS 发展DOS --

联盟域名:www.cn-dos.net  论坛域名:www.cn-dos.net/forum
DOS,代表着自由开放与发展,我们努力起来,学习FreeDOS和Linux的自由开放与GNU精神,共同创造和发展美好的自由与GNU GPL世界吧!

游客:  注册 | 登录 | 命令行 | 会员 | 搜索 | 上传 | 帮助 »
中国DOS联盟论坛 » DOS批处理 & 脚本技术(批处理室) » 【共同参与】"批处理函数库"
« [1] [2] [3] »
作者:
标题: 【共同参与】"批处理函数库" 上一主题 | 下一主题
plp626
银牌会员

钻石会员


积分 2278
发帖 1020
注册 2007-11-19
状态 离线
『楼 主』:  【共同参与】"批处理函数库"

为了防止某些人灌水设了积分限制,请谅解,,

学了几个月批处理感觉收获真不少,(主要是好玩)

只是感觉功夫长进没有原来那么明显了,大部分时间都是在编一些重复的代码,即使一个很有挑战行动代码,花了不少功夫编出来,回过头认真一搜,论坛以前就有类似的代码,只是需要把各种方法"整合"就可以完成自己的代码了,

借鉴别人的,然后改进综合,这样进步才会很快.

只是很少人做这个工作,起码willsort以前发的帖子注意的人就寥寥(个人认为, 只有足够的函数,才能往面向对象那里想)

大家把自己能知道的一些常用的函数,(基本是都是call调用)共享下,交流下,然后极少成多多了,以后编代码就光查,既省时有省力,

(对于"私藏者",我引用一个小朋友的话"别当那是个宝,说不定还是个...,大家交流下说不定还有更高效的算法,这对你总是有好处的).

感觉很好的子过程或函数请发到这个帖子:

http://www.cn-dos.net/forum/viewthread.php?tid=39777&fpage=1常用子过程、函数收集【专用帖】

我这里有篇文章,虽然是英文但说的很到位,就是告诉我们些批处理函数的标准格式,供他人方便调用.

函数也就分有参函数与无参函数:

无参函数
call:标签A


rem 注释....(该函数的功能等)

:标签A
任务A
goto :eof
有参函数:
call:标签A "参数1" "参数2"


rem 注释....(该函数的功能等)

:标签A
setlocal ENABLEEXTENSIONS

参数接收
任务A

endlocal&设定返回参数1,参数2,...
goto :eof
对于注释部分以及变量的定义与返回,需要个规范,大家参考下面文章,交流下,

我英文不好,就不翻译,英语差点自己到http://www.google.cn/language_tools搜.

[ Last edited by plp626 on 2008-4-27 at 12:12 AM ]



山外有山,人外有人;低调做人,努力做事。

进入网盘(各种工具)~~ 空间~~cmd学习
2008-4-1 23:17
查看资料  发短消息 网志   编辑帖子  回复  引用回复
plp626
银牌会员

钻石会员


积分 2278
发帖 1020
注册 2007-11-19
状态 离线
『第 2 楼』:  Batch Function Library

[转载]

原文:http://commandline.co.uk/lib/treeview/index.php
●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●
Batch Function Overview (批处理函数概述)

What are they?

A batch function is a block of batch code that can be called by a batch file, optionally with a number of parameters. The function performs its task without unintentionally modifying variables outside of its own scope, and then returns control to the statement following the one that called the function.

Why use them?

The primary benefit of functions is reusable code. Once a function has been written, it can be used over and over again. This reduces the time spent developing and debugging scripts

Scripts that use functions naturally have a modular structure and use fewer 'global' variables, therefore they are much easier to understand, debug and maintain.

What do they look like?

All the functions in the library are based on the following template(下面是提供的模板):

:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
:<Function Name> <Parameter list>
::
:: By:   <Author/date/version information>
::
:: Func: <Function description>
::
:: Args: <Argument description>
:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
setlocal ENABLEEXTENSIONS
<Body of function>
endlocal&<Set return values>&goto :EOF
:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::

<Function name> Name of the function, eg GetDate
<Parameter list> List of arguments. This list only serves as a reminder of how to call the function (everything after the function name is ignored by the command interpreter)
<Author/date/version information> Self explanatory
<Function description> Brief explanation of what the function does and which platforms it has been designed for (NT4, W2K or XP)
<Argument description> Detailed description of the functions arguments
<Body of function> This is where the function performs its main purpose
<Set return values> This is where the function 'returns' any local values back to the calling routine
●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●
Batch Functions Explained (批处理函数解释)

Passing Arguments

Most high-level programming languages allow arguments to be passed to functions 'by value' and 'by reference'. Passing by value means that the function receives a copy of the arguments value. Any changes made to this copy by the function do no affect the original variable.

When a variable is passed by reference, the function receives a pointer to the original variable, and loosely speaking, changes made to this pointer by the function do affect the original variable.

In the batch programming language variables are passed by reference. Unfortunately the pointers to the original variables are read only and consequently cannot be assigned values and therefore are unable to alter the variable which they point to.

The good news is that with a little ingenuity, the batch language can be coerced into passing variables by value and by reference in a similar way to high-level languages such as C and Visual Basic.

By Value

Below is a very simple example showing how to pass an argument by value and how that value is then read by the function.

1. @echo off & setlocal ENABLEEXTENSIONS
2. set str=Hello
3. call :demoA %str%
4. goto :EOF
5.
6. :demoA
7. echo/%1
8. goto :EOF

In line 3, %str% is expanded to Hello, and then the memory location of where Hello is actually stored is assigned to %1. Line 7 then references %1 which is then expanded to Hello.

If two or more arguments were being passed, they could be referenced using %2, %3 and so on, all the way up to %9. If more than nine variables were being passed, then to reference the tenth, the shift command would have to be used.

shift effectively increments all the pointers. Before shift is used, %0 points to the name of the function or routine and %1 points to the first argument. After shift is used, %0 points to what %1 used to point to, %1 points to what %2 used to point to and so on. The tenth argument can now be referenced using %9.

By Reference

Here is a slighty different version of the example above. Instead of passing the value Hello to the function, the name of a variable that contains Hello is passed instead.

1. @echo off & setlocal ENABLEEXTENSIONS
2. set str=Hello
3. call :demoB str
4. goto :EOF
5.
6. :demoB
7. call echo/%%%1%%
8. goto :EOF

Inside the function demoB, %1 expands to str. To read the value contained in str, it is necessary to enclose %1 with double percents and instruct the command interpreter to perform another expansion. This is most easily accomplished by using the CALL command as shown in line 7. For a detailed explanation of variable expansion, see the thread in alt.msdos.batch.nt titled "Variable expansion (W2KSP2)".

Why would we want to pass arguments like this? Well now that the function knows the name of a variable, it can assign it a value and thereby the function can now return values.

Returning Values

So far the contrived examples have only served to illustrate the points being made. This next example demonstrates how a function can return a value and is typical of the functions in this library. The methods used guarantee this function can be inserted, as it stands, into any batch file without causing any side effects whatsoever.

The function below is called Area and it simply calculates the product of width and height and then returns the result. Three arguments are required, the first two should be passed by value, the third by reference.

[It is a convention of this library to document a function's arguments by including an argument list immediately after the function name (as shown below on line 08). This is a convenient location as anything after the function name is ignored by the command interpreter. This list serves no other purpose than to act as a reminder of the type and number of arguments a function expects.]

01. @echo off & setlocal ENABLEEXTENSIONS
02. set x=2
03. set y=3
04. call :Area %x% %y% answer
05. echo/The area is: %answer%
06. goto :EOF
07.
08. :Area %width% %height% result
09. setlocal
10. set /a res=%1*%2
11. endlocal & set "%3=%res%"
12. goto :EOF

Line 04 calls the Area function passing three arguments (it could equally have read call :Area 2 3 answer). The first command of the function (line 09) is setlocal. This command creates a copy of the current environment and this copy then becomes the current environment. Line 10 calculates the product of arguments %1 and %2 and saves the result in the variable called res.

The next line consists of two commands seperated by an ampersand (&). This causes the command interpreter to expand both commands and then execute them one after the other. So line 11, after it has been expanded equates to endlocal & set "answer=6". Now the endlocal command is executed, which deletes the copy of the environment created by the most recent setlocal command, and restores the previous environent. Then set "answer=6" is executed, and finally on line 12 goto :EOF exits the function and execution continues at line 05. The net result is that the Area function has returned a value.

If on line 11, the command set "%3=%res%", had been expanded after endlocal had been executed, then instead of expanding to set "answer=6" it probably would have been set "answer=" as the res variable was deleted by the endlocal command.

By Value or Reference

The rule of thumb is to pass arguments by value unless you need to modify the original values, in which case pass by reference. The Area function above demonstrates this rule as the first and second arguments (width and height) are passed by value, but in order to assign the result of the calculation to the answer variable, it was passed to the function by reference.

Sometimes it's necessary to pass arguments by reference even though read-only access is required. For example, when passing two or more unquoted arguments where at least one of them contains whitespace, the function would not be able to determine which argument was which if they had been passed by value. Calling by reference can also be used to pass arguments containing so-called 'poison' characters (such as " ! | < > ^ " & %).

Protecting out of Scope Variables

In order to create truely reusable functions, you must ensure that they do not unintentionally modify variables outside of their own scope. This is accomplished by enclosing your function's main routine with the setlocal and endlocal statements as shown in the example above.

Unfortunately things get a little more complicated when two or more arguments are passed by reference and those arguments need to be read by your function (as opposed to just being assigned values). This is best illustrated by the Swap function shown below.

Protecting Arguments

When passing two or more arguments by reference where those arguments need to be read, care must be taken not to destroy any of the arguments before they have all been read. Consider this example below.

01. @echo off & setlocal ENABLEEXTENSIONS
02. set a=one
03. set b=two
04. echo/Before call   :swap a b [%a% %b%]
05. call :Swap a b
06. echo/After call 1 :swap a b [%a% %b%]
07. call :Swap b a
08. echo/After call 2 :swap b a [%a% %b%]
09.
10. goto :EOF
11.
12. :Swap
13. setlocal
14. call set a=%%%1%%
15. call set b=%%%2%%
16. endlocal & set "%1=%b%" & set "%2=%a%" & goto :EOF

The above example displays:-

Before call   :swap a b [one two]
After call 1 :swap a b [two one]
After call 2 :swap b a [one one]

This function is supposed to swap the contents of two variables. Notice it succeed the first time, but failed on the second. This was caused by variable names outside of the function clashing with duplicate names inside the function. Specifically, this is what went wrong:-

Line 07 called Swap, the first argument is b, the second a.

Line 14 is expanded twice because of the call command, after the second expansion, the line equates to set a=one, and once this command is executed, a is overwritten.

Line 15 is also expanded twice and equates to set b=one, in other words both a and b are now the one

The usual workaround for this problem is to use variable names that are unique to your function by preceeding all function variables with the function name separated by a period. However, if using that approach, it's actually only necessary to use unique names for vulnerable variables. Rewriting lines 14-16 of the Area function as shown below would prevent any arguments being overwritten before they had been saved.

14. call set Swap.a=%%%1%%
15. call set b=%%%2%%
16. endlocal&set %1=%b%&set %2=%Swap.a%&goto :EOF

This method has several drawbacks. Firstly, you must never use a period in any variable name outside of your functions. Secondly, if the function doesn't have a really short name and reads a number of variables by reference, the number of lines of code in the function can double if you want to avoid 'long' lines of code.
An alternative method is to read the variables with the FOR /F command using a delimiter character not present in any of the argument values. Using this method the Swap function could be rewritten as follows:-

12. :Swap
13. setlocal ENABLEEXTENSIONS
14. for /f "tokens=1-2 delims=¬" %%a in ('echo/%%%1%%¬%%%2%%') do (
15.    set a=%%a&set b=%%b
16. )
17. endlocal&set %1=%b%&set %2=%a%&goto :EOF

The delimiter character is a '¬' (ASCII 172, which looks like a back-to-front 'L' on its side). It was chosen because it's rarely used and it appears on a UK keyboard (above the TAB key). If you don't have this key, you can type it by holding down the Alt key and typing 172 on the numeric keypad. The only drawback of this method being your variables must never contain the delimiter character otherwise you may obtain incorrect results.

This issue was covered in alt.msdos.batch.nt in a thread titled "Function parameters".

●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●

Using the Functions(函数的使用)

Copy the Function

To use any of the functions, just copy and paste them to the end of your batch file. To prevent the function(s) from being executed after your main batch file code has run, add goto :EOF after your main batch file code but before the function(s). For example:-

Example 1a

<-- Your main batch file code goes here
goto :EOF
<-- 1st function here
<-- 2nd function here
<-- and so on...

[The documentation for each function includes an example that demonstrates how the function should be called. In these examples the actual function itself has been omitted to avoid unnecessarily duplicating code. When using any of the examples, remember to append the function to the end of your batch file.]

Calling the Function

The documentation for each function describes the number of required and optional parameters, the type of data each parameter should contain and whether the parameter must be passed 'by value' or 'by reference'. Both terms are used very loosely here and the reason is covered in great detail in the next section. Suffice to say that to pass a variable by value, call the function with a constant or expanded variable. And to pass by reference, call the function with the name of a variable.

By Value

To pass a parameter 'by value', either call the function with a constant or an expanded variable that contains the value. As an example, the Sleep function expects one parameter (a number of seconds) to be passed by value. Here are three ways to call the Sleep function with the value 9:-

Example 2a

call :Sleep 9


Example 2b

set AnyVarName=9
call :Sleep %AnyVarName%


Example 2c

call :Sleep %1

Notes: In example 2b, practically any variable name could have been used. Example 2c assumes the value of 9 was passed to the batch file as a commandline parameter.

By Reference

To pass a value 'by reference' simply use the name of a variable. As an example, the GetDate function expects three parameters, all passed by reference. Here's how to call the GetDate function and use the 'returned' values:-

Example 3a

call :GetDate yy mm dd
echo/Todays date is: %yy%-%mm%-%dd%

Note that although example 3a used the variable names yy, mm and dd, practically any variable names could have been used. For instance, example 3b is functionally equivalent to example 3a (but not so easy to understand).

Example 3b

call :GetDate x y z
echo/Todays date is: %x%-%y%-%z%
●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●
应用举例:

DateToDOW

The DateToDOW function returns the day of week number for a given calendar date..

:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
:DateToDOW %yy% %mm% %dd% dow
::
:: By:   Ritchie Lawrence, 2003-04-29. Version 1.1
::
:: Func: Creates a day of week number from a calendar date, where 1 = Mon
::       and 7 = Sun. For NT4/2000/XP/2003.
::
:: Args: %1 year component to be converted, 2 or 4 digits (by val)
::       %2 month component to be converted, leading zero ok (by val)
::       %3 day of month to be converted, leading zero ok (by val)
::       %4 var to receive day of week number, 1 to 7 (by ref)
:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
setlocal ENABLEEXTENSIONS
set yy=%1&set mm=%2&set dd=%3
if 1%yy% LSS 200 if 1%yy% LSS 170 (set yy=20%yy%) else (set yy=19%yy%)
set /a dd=100%dd%%%100,mm=100%mm%%%100
set /a z=14-mm,z/=12,y=yy+4800-z,m=mm+12*z-3,dow=153*m+2
set /a dow=dow/5+dd+y*365+y/4-y/100+y/400-2472630,dow%%=7,dow+=1
endlocal&set %4=%dow%&goto :EOF
:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::  

Parameters

%1 year component to be converted, 2 or 4 digits (by val)
%2 month component to be converted, leading zero ok (by val)
%3 day of month to be converted, leading zero ok (by val)
%4 var to receive day of week number, 1 to 7 (by ref)

Return Values

See parameters above.

Example

@echo off & setlocal ENABLEEXTENSIONS
call :GetDate y m d
call :DateToDOW %y% %m% %d% dow
call :DayName %dow% day
echo/Today is %day%
goto :EOF

Remarks

The DateToWeek function also returns day of week (in addition to year and month).

See Also

DateToWeek, DayName, DayNumber



山外有山,人外有人;低调做人,努力做事。

进入网盘(各种工具)~~ 空间~~cmd学习
2008-4-1 23:35
查看资料  发短消息 网志   编辑帖子  回复  引用回复
plp626
银牌会员

钻石会员


积分 2278
发帖 1020
注册 2007-11-19
状态 离线
『第 3 楼』:  

真就这么无动于衷吗?
fastslz zh159 HAT 26933062
你们在线呀!我就不信你们也不感兴趣.

有多少人因为这样相继离去,(当然我不会的,∵我还没成为高手)



山外有山,人外有人;低调做人,努力做事。

进入网盘(各种工具)~~ 空间~~cmd学习
2008-4-2 00:22
查看资料  发短消息 网志   编辑帖子  回复  引用回复
HAT
版主





积分 9023
发帖 5017
注册 2007-5-31
状态 离线
『第 4 楼』:  

别人写的,我帮忙贴一下吧:
rem 字符串长度计算
set str=abc
for /f "skip=1 delims=:" %%a in ('^(echo "%str%"^&echo.^)^|findstr /o ".*"') do set /a length=%%a-5
echo %length%


2008-4-2 01:01
查看资料  发短消息 网志   编辑帖子  回复  引用回复
Shinaterry
初级用户





积分 97
发帖 51
注册 2008-3-19
状态 离线
『第 5 楼』:  



弱弱请教一下..

假如A.bat内容如下:
@echo off
:c
echo "do"
goto :eof
现时B.bat能否利用call直接调用A.bat->:c(标签)?

[ Last edited by Shinaterry on 2008-4-2 at 02:38 PM ]

2008-4-2 14:35
查看资料  发送邮件  发短消息 网志   编辑帖子  回复  引用回复
huahua0919
银牌会员




积分 1608
发帖 780
注册 2007-10-7
状态 离线
『第 6 楼』:  

不是无动于衷,BAT没什么函数及方法之类的东东,全是靠命令堆积起来的,变化的只是头脑,缺少的只是经验!如果真的想了解函数库,那还不如多了解JS,VBS,JAVA,C的函数,及相关联的组建,如COM.DLL之!

2008-4-2 14:48
查看资料  发送邮件  访问主页  发短消息 网志   编辑帖子  回复  引用回复
Shinaterry
初级用户





积分 97
发帖 51
注册 2008-3-19
状态 离线
『第 7 楼』:  

谢谢两位! abcd 兄的方法正正是我原先所使用的, 因为觉得笨拙, 所以特意请教有没有方法可直接调用..

看来楼主, 看透我的意图, 因为这样"批处理函数库"的存在才有更大意义..



[ Last edited by Shinaterry on 2008-4-2 at 03:36 PM ]

2008-4-2 15:30
查看资料  发送邮件  发短消息 网志   编辑帖子  回复  引用回复
zh159
金牌会员




积分 3687
发帖 1467
注册 2005-8-8
状态 离线
『第 8 楼』:  

真正常用的子过程并不多,而且不一定能通用,或多或少都需要适当修改,基本上是根据实际应用再编写



2008-4-2 17:04
查看资料  发短消息 网志   编辑帖子  回复  引用回复
knoppix7
银牌会员





积分 1287
发帖 634
注册 2007-5-2
来自 cmd.exe
状态 离线
『第 9 楼』:  

个人感觉:
函数库很有必要.
貌似目前更需要"方法库".给人写了一堆代码。该不会的还不会.(BC到搜索都懒得用.同一个问题回答N便很让人烦..)
直接给出大致方法.他们自己发挥去.

2008-4-7 19:26
查看资料  发短消息 网志   编辑帖子  回复  引用回复
plp626
银牌会员

钻石会员


积分 2278
发帖 1020
注册 2007-11-19
状态 离线
『第 10 楼』:  

[code]:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
::输出彩色字符{code by jvive@cn-dos.net|2008-4-9}
::call:Colstr <attr> <sp> <"str"> <bk> <sp> <enter>  
::               |     |     |      |    |     |
::             颜色   空格  字符串   退格  空格 回车换行
::效率:      约18次/s  (XP 5.1/2.4GHz/256M)      
:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
::说明:
::   attr   16进位数字颜色属性。请参考16进位数字颜色属性配置演示代码。
::   sp     范围:{0,

2008-4-23 16:04
查看资料  发短消息 网志   编辑帖子  回复  引用回复
plp626
银牌会员

钻石会员


积分 2278
发帖 1020
注册 2007-11-19
状态 离线
『第 11 楼』:  

.....

[ Last edited by plp626 on 2008-4-25 at 07:15 PM ]



山外有山,人外有人;低调做人,努力做事。

进入网盘(各种工具)~~ 空间~~cmd学习
2008-4-23 16:05
查看资料  发短消息 网志   编辑帖子  回复  引用回复
metoo
初级用户





积分 195
发帖 93
注册 2006-10-28
状态 离线
『第 12 楼』:  

发了一个用来删除文件的
http://www.cn-dos.net/forum/viewthread.php?tid=39723&fpage=2
。。貌似没多少人感兴趣 - -! 这个可以直接加参数用call调用,当然要调用的话重启那段代码可以去掉
call :delf 要删的文件1 要删的文件2 。。。。
:delf
@echo off
set t=0
title=文件删除工具  code by 逐月鹰
:begin
set/a t=%t%+1
del/a/f/s/q %1 >nul 2>nul
rd /s /q %1 >nul 2>nul
if %ERRORLEVEL%==1 GOTO end1
if exist "%~1" echo %~nx1被锁定,将尝试重启后删除&&goto redel
shift
GOTO begin
:end1
IF not "%t%"=="1" GOTO end2
title=文件删除工具使用说明  code by 逐月鹰
color 0a
echo.
echo 请将需要删除的文件拖到这个程序的图标上
echo 本代码支持多个文件、文件夹同时删除
echo 当遇到文件因为正在使用而无法删除时
echo 会尝试在下次重启后删除,当文件夹中有
echo 文件运行时,会提示先删除其中的文件
echo.
pause
goto :eof
:end2
if "%u%"=="%%0%" (
echo del %u%>>"%userprofile%\「开始」菜单\程序\启动\runonce.bat"
goto reb
)else if "%u%"=="error" (
echo 某些文件夹在使用中,请尝试先删除其中的文件
)else ECHO 文件/文件夹已被全部删除
pause
goto :eof
:redel
Attrib -r -a -s -h %1
set a=%random%
ren %1 "%~nx1.%a%" 2>nul||ECHO 失败!请尝试先删除文件夹中的文件&&SHIFT&&set u=error&&goto begin
echo 123>%1
attrib +r +a +s +h %1
set u=%%0%
ECHO ^@ECHO OFF>>"%userprofile%\「开始」菜单\程序\启动\runonce.bat"
echo del /a/f/s/q %1>>"%userprofile%\「开始」菜单\程序\启动\runonce.bat"
echo del /a/f/s/q "%~dpnx1.%a%">>"%userprofile%\「开始」菜单\程序\启动\runonce.bat"
SHIFT
goto begin
:reb
set/p shut=是否马上重启?Y(是)其他任意键退出:
if /i "%shut%"=="y" shutdown -r -t 0 -f
goto :eof
pause
[ Last edited by metoo on 2008-4-24 at 09:07 PM ]

2008-4-24 21:04
查看资料  发送邮件  发短消息 网志   编辑帖子  回复  引用回复
slore
铂金会员





积分 5212
发帖 2478
注册 2007-2-8
状态 离线
『第 13 楼』:  

还是用DEL 和RD命令?又不能强删,所以实用性不高呀
UNLOCKER,右键很方便……

2008-4-24 21:07
查看资料  发短消息 网志   编辑帖子  回复  引用回复
metoo
初级用户





积分 195
发帖 93
注册 2006-10-28
状态 离线
『第 14 楼』:  

加上了重命名后重启删除,确实实用性一般,我写这也就是想作为一个函数调用的  p终究不是万能的

正在考虑寻找一些更加霸道的命令加入代码,这个只能算一个雏形把,慢慢完善

[ Last edited by metoo on 2008-4-24 at 09:10 PM ]

2008-4-24 21:09
查看资料  发送邮件  发短消息 网志   编辑帖子  回复  引用回复
metoo
初级用户





积分 195
发帖 93
注册 2006-10-28
状态 离线
『第 15 楼』:  

还有一段查看网络性息的事别人写的
::调用格式:
call :select "ip address" "ip"
call :select "Physical Address" "mac"
call :select "Default Gateway" "gateway"
call :select "DNS Servers" "dns"
call :select "Description" "netcard"

:: 演示效果
echo IP:%ip%
echo MAC:%mac%
echo DNS:%dns%
echo GATEWAY:%gateway%
echo NETCARD:%netcard%
pause>nul
goto :eof

::**************************************************************
::              解析ipconfig命令输出通用函数
::**************************************************************
:select
    for /f "tokens=2 delims=:" %%i in ('ipconfig /all ^| findstr /i /c:%1') do if not "!%~2!" == "" set "%~2=%%i"
goto :eof


   此帖被 +3 点积分     点击查看详情   
评分人:【 plp626 分数: +3  时间:2008-4-27 00:12


2008-4-24 21:13
查看资料  发送邮件  发短消息 网志   编辑帖子  回复  引用回复
« [1] [2] [3] »
请注意:您目前尚未注册或登录,请您注册登录以使用论坛的各项功能,例如发表和回复帖子等。


可打印版本 | 推荐给朋友 | 订阅主题 | 收藏主题



论坛跳转: