顯示具有 Microsoft 標籤的文章。 顯示所有文章
顯示具有 Microsoft 標籤的文章。 顯示所有文章

2012-12-09

Forfiles


http://technet.microsoft.com/en-us/library/cc753551(WS.10).aspx
Syntax

forfiles [/p Path] [/m SearchMask] [/s] [/c Command] [/d[{+ | -}] [{MM/DD/YYYY | DD}]]

Parameters

/p Path
指定您要在其上開始搜尋的 Path。預設資料夾為目前的工作目錄,您可以透過輸入句點 (.) 來指定。
/m SearchMask
依據 SearchMask 來搜尋檔案。預設的 SearchMask 為 *.*。
/s
指示 forfiles 在子目錄中搜尋。
/c Command
在每個檔案上執行指定的 Command。您必須將帶有空格的命令字串包含在引號中。預設的 Command 為 "cmd /c echo @file"。
/d[{+ | -}] [{MM/DD/YYYY | DD}]
選取日期大於等於 (+) 或小於等於 (-) 指定日期的檔案,其中 MM/DD/YYYY 是指定的日期,而 DD 是目前日期減去 DD 天。如果您未指定 + 或 -,則會使用 +。DD 的有效範圍為 0 - 32768。
/?
在命令提示字元上顯示說明。
Remarks

Forfiles 最常使用於批次檔案中。

Forfiles /s 與 dir /s 類似。
下列表格列出了您可以在 /cCommand 命令字串中使用的變數。

變數 描述
@file 檔案名稱

@fname 不含副檔名的檔案名稱

@ext 副檔名

@path 檔案的完整路徑

@relpath 檔案的相對路徑

@isdir 如果檔案類型是目錄,則判斷值是 TRUE,否則判斷值是 FALSE。

@fsize 檔案大小 (以位元組為單位)

@fdate 檔案上的上次修改日期戳記

@ftime 檔案上的上次修改時間戳記

使用 forfiles,您可以在多個檔案上執行命令,或將引數傳送到多個檔案。例如,您可以在樹狀目錄中帶有 *.txt 副檔名的所有檔案上執行 TYPE 命令。或者,您可以執行 C: 磁碟機上的每個批次檔案 (*.bat),以檔案名稱 Myinput.txt 作為第一個引數。

使用 forfiles,您可以執行下列任何一項動作:

使用 /d 按絕對或相對日期選取檔案。

使用變數,例如 @fsize (檔案大小) 及 @fdate (檔案日期),來建立檔案的保存樹狀目錄。

使用 @isdir 變數以從目錄中區分檔案。

藉由在命令列中包含特殊字元,及使用十六進位字碼 0xHH 包圍字元,來格式化輸出。

Forfiles 藉由執行工具 (設計用於僅處理單一檔案)上的 recurse subdirectories 旗標來運作。

Examples

若要列出 C: 磁碟機上的所有批次檔案,請輸入:

forfiles /p c:\ /s /m *.bat /c "cmd /c echo @file is a batch file"

若要列出 C: 磁碟機上的所有目錄,請輸入:

forfiles /p c:\ /s /m *.* /c "cmd /c if @isdir==true echo @file is a directory"

若要列出 C: 磁碟機上 100 天之前的所有檔案,請輸入:

forfiles /p c:\ /s /m *.* /dt-100 /c "cmd /c echo @file :date >= 100 days"

若要列出 C: 磁碟機上 1993 年 1 月 1 日之前的所有檔案,再為這些檔案顯示 "file is quite old!",請輸入:

forfiles /p c:\ /s /m *.* /dt-01011993 /c "cmd /c echo @file is quite old!"

若要列出 C: 磁碟機上所有檔案的所有副檔名(按欄位格式),請輸入:

forfiles /p c:\ /s /m *.* /c "cmd /c echo extension of @file is 0x09@ext0x09" With:

若要列出 C: 磁碟機上的所有批次檔案,請輸入:

forfiles /p c:\ /s /m *.bat /c "cmd /c echo @file is a batch file"

若要列出 C: 磁碟機上的所有目錄,請輸入:

forfiles /p c:\ /s /m *.* /c "cmd /c if @isdir==true echo @file is a directory"

若要列出 C: 磁碟機上 100 天之前的所有檔案,請輸入:

forfiles /p c:\ /s /m *.* /d t-100 /c "cmd /c echo @file :date >= 100 days"

若要列出 C: 磁碟機上 1993 年 1 月 1 日之前的所有檔案,再為這些檔案顯示 "file is quite old!",請輸入:

forfiles /p c:\ /s /m *.* /d t-01011993 /c "cmd /c echo @file is quite old!"

若要列出 C: 磁碟機上所有檔案的所有副檔名(按欄位格式),請輸入:

forfiles /p c:\ /s /m *.* /c "cmd /c echo extension of @file is 0x09@ext0x09"


#刪除超過7天,位於 c:\windows\Temp 路徑中檔名 sess開頭的檔案
forfiles /P c:\Windows\Temp /M sess_* /S /D -7 /C "cmd /c del /F @path"

2012-10-13

Windows How to Finding non present devices

1. Open Command shell
2. type "set devmgr_show_nonpresent_devices=1"
3. type "start devmgmt.msc"
4. Select "Show hidden devices"

2012-08-14

dsquery command

dsquery user -inactive 13 ==>list users have no login for 91 days.
dsquery user -stalepwd 180 ==>list users that the password had been used for 180 days.

2012-08-08

netsh command change IP address

netsh interface ip set address "Local Area Connection" static 192.168.0.1 255.255.255.0 192.168.0.254 1

netsh firewall set icmpsetting 8          => allow others to ping you
netsh firewall set icmpsetting 8 disable=> deny others to ping you

2012-07-23

EventTriggers

http://www.microsoft.com/resources/documentation/windows/xp/all/proddocs/en-us/eventtriggers.mspx?mfr=true


  • /create - is used to create an event trigger,
  • /delete can be used to delete the trigger
  • /eid - is the event id number you wish to track
  • /tr - is the name you would like to give to the event trigger
  • /ru - is the user name to run under userdomain or user@domain.com are both acceptable
  • /rp - is the user password
  • /tk - is the action you would like performed when triggered

  • /query - a list of event triggers

How to set event log security locally or by using Group Policy in Windows Server 2003

http://support.microsoft.com/kb/323076/en-us
http://social.technet.microsoft.com/Forums/zh-TW/winserverzhcht/thread/eda758fa-8841-4d64-9edb-5b798d99600d/

HKEY_LOCAL_MACHINE\System\CurrentControlSet\Services\Eventlog\Security
對CustomSD點兩下後,在最後面加上下面一行

(A;; 0x1;;;UserSID)

A=Allow

D=Deny

1 = 讀取
2 = 寫入

3 = 讀取+寫入
4 = 清除

7 = 讀取+寫入+清除

2011-12-13

微軟出品 -- 管理工具

Sysinternal

用來管理微軟的作業系統,非常好用的小工具,小工具、大功用。
http://technet.microsoft.com/en-us/sysinternals/default.aspx
打包http://download.sysinternals.com/Files/SysinternalsSuite.zip

Patch 派送 -- 沒有 WSUS or SMS 怎麼辦?

Patch 派送 -- 沒有 WSUS or SMS 怎麼辦?

1. 若是在 AD 的環境中,可以使用網域管理者的帳號或是具有本機管理者權限的帳號來做。
2. 若是非 AD 的環境,則必須有本機管理者權限的帳號與密碼。

For example
psexec.exe \\computername or IP -u "user_name" -p "password" -c "patch" /q /norestart
\\computername or IP 可以用 @file 來大量部署,將 "電腦名稱或IP"輸入txt檔
"user_name" 必須具有本機管理者權限
"password" 當然就是要輸入 "密碼" 囉
-c 就是把 patch 複製到該台電腦上執行
/q 不顯示安裝畫面
/norestart 安裝完,不重開機