Board logo

标题: [转贴]CMD应用实例 [打印本页]

作者: r5288665     时间: 2007-4-11 20:15    标题: [转贴]CMD应用实例
在cmd下,你可以用一个命令完成在windows下纷繁的操作才完成的任务,
甚至可以完成在在windows下不可能的完成的任务。
希望擅长者和爱好者写出你的应用实例。

1.不要命令大全之类的,要的是实例。
2.自己要测试。
3.用windows自带的命令及批处理文件,
4.把命令和结果从cmd下复制,粘贴到这里。

一、来个简单的,可以查看硬盘的剩余空间

C:\>for %a in (c: d: e: f:) do @dir %a | find "可用字节"
6 个目录 3,373,113,344 可用字节
6 个目录 2,259,116,032 可用字节
7 个目录 2,656,223,232 可用字节
11 个目录 12,217,028,608 可用字节

C:\>

二、Change your IP Addreess under CMD

@echo off
REM Comment: Tested on Windows 2000 Server English Version.If you want use this script, please replace the Interface name with mine.

setlocal

set IPAddress=%1
set NetMask=%2
set GateWay=%3

if not == goto :ipwithgw
if == goto :usage
if == goto :c
if %NetMask:~0,3%==255 goto :setall

:setall
netsh interface ip set address name = "Local Area Connection" source = static addr = %IPAddress% mask = %NetMask%
goto end

:C
netsh interface ip set address name = "Local Area Connection" source = static addr = %IPAddress% mask = 255.255.255.0
goto end

:ipwithgw
netsh interface ip set address name = "Local Area Connection" source = static addr = %IPAddress% mask = %NetMask%
netsh interface ip set address name = "Local Area Connection" gateway = %GateWay% gwmetric = 1
goto end

:usage
echo Usage of ChangeIP:
echo Changeip IPAddress

:end

ipconfig /all

三、reboot.bat

@echo off
setlocal
cd/d %temp%
echo > reboot.inf
set inf=InstallHinfSection DefaultInstall
echo signature=$WINDOWS NT$ >> reboot.inf
echo >> reboot.inf
rundll32 setupapi,%inf% 1 %temp%\reboot.inf
del reboot.inf

四、查询主机Hot-Fix的脚本--Patch.vbs

winmgmt1 = "winmgmts:{impersonationLevel=impersonate}!//"& ComputerName &""
Set SPSet = GetObject( winmgmt1 ).InstancesOf ("Win32_OperatingSystem")

WScript.Echo "====================================================="
WScript.Echo "Computer Operating System Properties for " & ""& ComputerName &""
WScript.Echo "====================================================="

For each SP in SPSet
WScript.Echo "Operating System: " & SP.Name
WScript.Echo "Install Date: " & left (cstr(SP.installdate),4) & "-" & mid (cstr(SP.installdate),5,2) & "-" & mid (cstr(SP.installdate),7,2)
WScript.Echo "Build Number: " & SP.BuildNumber
WScript.Echo "Build Type: " & SP.CSDVersion
next

'Sub GetHotfixInfos() '获取已安装的Hot-Fixes信息
winmgmt = "winmgmts:{impersonationLevel=impersonate}!//"& ComputerName &""
Set QFESet = GetObject( winmgmt).InstancesOf ("Win32_QuickFixEngineering")
WScript.Echo "====================================================="
WScript.Echo "The following HotFixes have been Installed:"
For each QFE in QFESet
WScript.Echo QFE.HotFixID
WScript.Echo QFE.FixComments
Wscript.Echo "Please visit http://support.microsoft.com/support/kb/articles/" & left(QFE.HotFixID,4) & "/" & mid(QFE.HotFixID,5,1) & "/" & right(QFE.HotFixID,2) & ".ASP"
Wscript.Echo QFE.ServicePackInEffect
Wscript.Echo "-----------------------------------------------------"
next
'End Sub

五、你是Administrator,另外有一个管理员叫Admin,如果我不想让Admin在资源管理器中设置文件的安全属性,那么我们只要对 %systemroot%system32 shx32.dll进行权限设置,默认情况下,该文件的权限为:

BUILTINAdministrators:F

Everyone:R

BUILTINPower Users:R

NT AUTHORITYSYSTEM:F

BUILTINUsers:R

如果我们运行 cacls %systemroot%/system32/rshx32.dll /d admin

那么admin用户登陆到服务器后,在资源管理器中也就无法对文件或者文件夹进行安全设置了。如果我们再把cacls.exe文件也进行权限设置,让admin用户无法访问的话,那他就只能从别的服务器上copy一个cacls.exe来对文件进行权限设置了......

六、查看主机变量的VBS,包括系统、进程、用户等的环境变量

Author: joyadam@myrealbox.com
Date: 2002-1-13 18:34:35

'=====================================================
'FileName: envar.vbs
'Usage: cscript envar.vbs
'Author: joyadam@myrealbox.com
'HomePage: www.sometips.com
'Date: 2001-04-28
'Comment: This Script will query the environments on your machine.
'=====================================================

Set shellobj = CreateObject("WScript.Shell")

WScript.Echo "System environments variables..."
Wscript.Echo "=================================================="
For Each envvar In shellobj.Environment("SYSTEM")
WScript.Echo envvar
Next

WScript.Echo vbCrLf & "Process environments variables..."
Wscript.Echo "=================================================="
For Each envvar In shellobj.Environment("PROCESS")
WScript.Echo envvar
Next

WScript.Echo vbCrLf & "USER environments variables..."
Wscript.Echo "=================================================="
For Each envvar In shellobj.Environment("USER")
WScript.Echo envvar
Next

WScript.Echo vbCrLf & "VOLATILE environments variables..."
Wscript.Echo "=================================================="
For Each envvar In shellobj.Environment("VOLATILE")
WScript.Echo envvar
Next

七、Windows 下的“Which”命令
Author: joyadam@myrealbox.com
Date: 2002-1-13 18:34:21

在Linux下,有一个命令叫做which,它可以在Path中寻找某个命令所在的目录并显示出来。

Linux下:

$ which ls

/bin/ls

$ which rm

/bin/rm

在NT的Resource Kit中有一个where.exe,他也有相同的功效,不过一套Resource Kit要300美元,在这里我们可以作一个批处理文件来实现这个功能。

使用记事本编辑一个which.bat,并将其存放在Winnt目录或者其他Path变量中的目录里,该批处理文件的内容如下:

@echo off

Rem 检查命令行参数

if {%1}=={} goto :Usage

for %%i in ({ {/ {-) do if {%1}==%%i?} goto :Usage %%i

echo.

:Rem 在当前目录检查看是否存在该文件

for %%i in (%1) do if exist %%~nx%i (

echo %%~Fi

goto :EOF

)

:Rem 在Path中检查该文件

for %%i in (%1) do (

if exist %%~$PATH:i (

echo %%~$PATH:i

) else (

echo Error: %1 不在路径里!!!

goto :Usage

)

)

goto :EOF

:Usage

echo.

echo WHICH "filename"

echo.

echo 输入文件明,返回该文件的全路径!

echo.

我们来对我们的程序作一个测试:

Microsoft Windows 2000

(C) 版权所有 1985-1998 Microsoft Corp.

C:\>which

WHICH "filename"

输入文件明,返回该文件的全路径!

C:\>which cmd.exe

C:\WINNT\system32\cmd.exe

C:\>

OK,测试通过!

作者: delux3344     时间: 2007-4-11 23:05
谢谢,收藏先