查看積分策略說明發表回覆
Discuz! 代碼
提示插入
直接插入
說明訊息

插入粗體文本 插入斜體文本 插入下劃線 置中對齊 插入超級連結 插入信件位址 插入圖像 插入 flash 插入代碼 插入引言 插入列表
刪除線 直線分隔線 虛線分隔線
    
添加文字底框
內容 [字數檢查]:

表情符號

更多 Smilies
字型大小 |||
溫馨提示:本區開放遊客瀏覽。


文章關鍵字 : [功能說明]
(關鍵字可加強搜索準確性, 如關鍵字多於一組, 請以 , 作分隔, e.g. : 阿笨,shiuh,第一笨)

 關閉 URL 識別 | html 禁用
 關閉 表情符號 | 表情符號 可用
 關閉 Discuz! 代碼 | Discuz! 代碼 可用
使用個人簽名
接收新回覆信件通知
推薦放檔網絡空間

檔案(Torent, zip等)
  1. freedl
  2. multiupload
  3. btghost
  4. 便當狗
  5. mediafire
  6. pillowangel
圖片(JPG, GIF等)
  1. hotimg
  2. tinypic
  3. mousems2
  4. imageshack
  5. imm.io
>>>歡迎推薦好用空間


最新10篇文章回顧
copson

 發表於 2009-5-27 05:29 PM

樓主分享的東西真的很好用!
小弟在幾年前就用這語言收集公司內PC硬體及軟體資訊.
對於IT 管理者,真的是必學呀!


ROACH

 發表於 2009-5-26 12:58 PM

這真的很重要
上次我朋友傳給我一個vbs的檔案
這個可以把AD主機的帳號清單所有資訊傳回來產生Excel 檔
我覺得還不錯!

以下複製後貼在txt上~把副檔名改成vbs就可以執行

Dim ObjWb
Dim ObjExcel
Dim x, zz
Set objRoot = GetObject("LDAP://RootDSE")
strDNC = objRoot.Get("DefaultNamingContext")
Set objDomain = GetObject("LDAP://" & strDNC) ' Bind to the top of the Domain using LDAP using ROotDSE
Call ExcelSetup("Sheet1")     '建立 Excel 活頁簿
x = 1
Call enummembers(objDomain)
Sub enumMembers(objDomain)
   On Error Resume Next
   Dim Secondary(20) ' Variable to store the Array of 2ndary email alias's
   For Each objMember In objDomain ' go through the collection     
       If ObjMember.Class = "user" Then ' if not User object, move on.
           x = x +1       'counter used to increment the cells in Excel
           
             objwb.Cells(x, 1).Value = objMember.Class
             ' I set AD properties to variables so if needed you could do Null checks or add if/then's to this code
             ' this was done so the script could be modified easier.
           SamAccountName = ObjMember.samAccountName
           Cn = ObjMember.CN
           FirstName = objMember.GivenName
           LastName = objMember.sn
           initials = objMember.initials
           Descrip = objMember.description
           Office = objMember.physicalDeliveryOfficeName
           Telephone = objMember.telephonenumber
           ExtPhone = objMember.otherTelephone
           FAX = objMember.FaxNumber
           EmailAddr = objMember.mail
           WebPage = objMember.wwwHomePage
           Addr1 = objMember.streetAddress
           City = objMember.l
           State = objMember.st
           ZipCode = objMember.postalCode
           Title = ObjMember.Title
           Department = objMember.Department
           Company = objMember.Company
           Manager = ObjMember.Manager
           Profile = objMember.profilePath
           LoginScript = objMember.scriptpath
           HomeDirectory = ObjMember.HomeDirectory
           HomeDrive = ObjMember.homeDrive
           AdsPath = Objmember.Adspath
           LastLogin = objMember.LastLogin
           
           zz = 1 ' Counter for array of 2ndary email addresses
           For Each email in ObjMember.proxyAddresses
              If Left (email,5) = "SMTP:" Then
           Primary = Mid (email,6) ' if SMTP is all caps, then it's the Primary
              Elseif Left (email,5) = "smtp:" Then
                 Secondary(zz) = Mid (email,6) ' load the list of 2ndary SMTP emails into Array.
                 zz = zz + 1
              End If
           Next
           ' Write the values to Excel, using the X counter to increment the rows.
           
           objwb.Cells(x, 2).Value = SamAccountName
           objwb.Cells(x, 3).Value = CN
           objwb.Cells(x, 4).Value = FirstName
           objwb.Cells(x, 5).Value = LastName
           objwb.Cells(x, 6).Value = Initials
           objwb.Cells(x, 7).Value = Descrip
           objwb.Cells(x, 8).Value = Office
           objwb.Cells(x, 9).Value = Telephone
           objwb.Cells(x, 10).Value = ExtPhone
           objwb.Cells(x, 11).Value = FAX
           objwb.Cells(x, 12).Value = EmailAddr
           objwb.Cells(x, 13).Value = WebPage
           objwb.Cells(x, 14).Value = Addr1
           objwb.Cells(x, 15).Value = City
           objwb.Cells(x, 16).Value = State
           objwb.Cells(x, 17).Value = ZipCode
           objwb.Cells(x, 18).Value = Title
           objwb.Cells(x, 19).Value = Department
           objwb.Cells(x, 20).Value = Company
           objwb.Cells(x, 21).Value = Manager
           objwb.Cells(x, 22).Value = Profile
           objwb.Cells(x, 23).Value = LoginScript
           objwb.Cells(x, 24).Value = HomeDirectory
           objwb.Cells(x, 25).Value = HomeDrive
           objwb.Cells(x, 26).Value = Adspath
           objwb.Cells(x, 27).Value = LastLogin
           objwb.Cells(x, 28).Value = Primary
           
           ' Write out the Array for the 2ndary email addresses.
           For ll = 1 To 20
               objwb.Cells(x,28+ll).Value = Secondary(ll)
           Next
           ' Blank out Variables in case the next object doesn't have a value for the property
           SamAccountName = "-"
           Cn = "-"
           FirstName = "-"
           LastName = "-"
           initials = "-"
           Descrip = "-"
           Office = "-"
           Telephone = "-"
           EmailAddr = "-"
           ExtPhone = "-"
           FAX = "-"
           WebPage = "-"
           Addr1 = "-"
           City = "-"
           State = "-"
           ZipCode = "-"
           Title = "-"
           Department = "-"
           Company = "-"
           Manager = "-"
           Profile = "-"
           LoginScript = "-"
           HomeDirectory = "-"
           HomeDrive = "-"
           Primary = "-"
           For ll = 1 To 20
               Secondary(ll) = ""
           Next
       End If
            
             ' If the AD enumeration runs into an OU object, call the Sub again to itinerate
            
       If objMember.Class = "organizationalUnit" or OBjMember.Class = "container" Then
           enumMembers (objMember)
       End If
   Next
End Sub
Sub ExcelSetup(shtName) ' This sub creates an Excel worksheet and adds Column heads to the 1st row
   Set ObjExcel = CreateObject("Excel.Application")
   Set objwb = objExcel.Workbooks.Add
   Set objwb = objExcel.ActiveWorkbook.Worksheets(shtName)
   Objwb.Name = "AD使用者"       '活頁簿名稱
   objwb.Activate
   ObjExcel.Visible = True
   objwb.Cells(1, 2).Value = "SamAccountName"         '帳號
   objwb.Cells(1, 3).Value = "CN"                     '顯示名稱
   objwb.Cells(1, 4).Value = "FirstName"              '名字
   objwb.Cells(1, 5).Value = "LastName"               '姓氏
   objwb.Cells(1, 6).Value = "Initials"               '英文縮寫
   objwb.Cells(1, 7).Value = "Description"            '描述
   objwb.Cells(1, 8).Value = "Office"                 '辦公室
   objwb.Cells(1, 9).Value = "Telephone"              '電話號碼
   objwb.Cells(1, 10).Value = "Ext Phone"             '電話號碼-分機
   objwb.Cells(1, 11).Value = "FAX"                   '傳真號碼
   objwb.Cells(1, 12).Value = "Email"                 '電子郵件
   objwb.Cells(1, 13).Value = "WebPage"               '網頁
   objwb.Cells(1, 14).Value = "Addr1"                 '街道
   objwb.Cells(1, 15).Value = "City"                  '縣/市
   objwb.Cells(1, 16).Value = "State"                 '省份
   objwb.Cells(1, 17).Value = "ZipCode"               '郵遞區號
   objwb.Cells(1, 18).Value = "Title"                 '職稱
   objwb.Cells(1, 19).Value = "Department"            '部門
   objwb.Cells(1, 20).Value = "Company"               '公司
   objwb.Cells(1, 21).Value = "Manager"               '主管
   objwb.Cells(1, 22).Value = "Profile"               '使用者設定檔-設定檔路徑
   objwb.Cells(1, 23).Value = "LoginScript"           '使用者設定檔-登入指令檔
   objwb.Cells(1, 24).Value = "HomeDirectory"         '主資料夾-連線目錄路徑
   objwb.Cells(1, 25).Value = "HomeDrive"             '主資料夾-連線磁碟名稱
   objwb.Cells(1, 26).Value = "Adspath"               '
   objwb.Cells(1, 27).Value = "LastLogin"             '最後登入時間
   objwb.Cells(1, 28).Value = "Primary SMTP"          '主要電子郵件 Exchange Server
   objwb.Cells(1, 29).Value = "Secondary SMTP"        '次要電子郵件 Exchange Server
   'formatting for header
   Set objRange = objExcel.Range("A1","AC1")
   objRange.Interior.ColorIndex = 40
   objRange.Font.Bold = True
   'objRange.Font.Underline = True
End Sub
'autofit the output
Set objRange = objwb.UsedRange
objRange.EntireColumn.Autofit()

MsgBox "AD資料收集完成"


jazzblue

 發表於 2008-1-24 11:26 PM

甚麼是Windows Script 呢 ?
簡單來說就是利用這個技術可以寫出類似批次檔一樣的文字描述語言來管理系統
有 Java Script 或VBasic Script  這兩種語言格式,比批次檔功能更強大  
很多人都知道Java Scipt 可以用來寫出動態網頁
但很少人知道Java Script 可以控制Windows 系統,譬如檔案處理、操作登錄檔...  
這種語言跟批次檔一樣都是文字檔,寫好之後,就可以馬上執行
所以相當容易學習與使用。

若你需要一個小程式來完成你的目的,不必為了這個目的去學C++ 或是VB
可能看了一個月的書還寫不出來
利用Windows Script 就可達成目的,初學者只要幾天就可以輕易寫出你要的程式。
若你有程式語言基礎要上手是輕而易舉 !

舉個簡單的例子,若你要建立一個文字檔並且在裡面記錄一些文字
你可以這樣寫
以Java Script 為例

var fso = new CreateObject("Scripting.FileSystemObject");
var a = fso.CreateTextFile("c:\\testfile.txt", true);
a.WriteLine("This is a test.");
a.Close();

以上程式建立一個檔名為testfile.txt 的文字檔內容為 This is a test.      
是不是很容易呢 ?  
當然Windows Script 的能耐還不僅只檔案處理,其他還有網路控制、執行程式、操作系統登錄..等
若搭配WMI 功能就更強大了 !

之前有個網友想寫一個簡單的樂透號碼產生器,而他又沒有語言基礎
所以求助於他人,若用Windows Script 只要幾天就可以寫出來了 !
怎麼寫呢 ?
利用亂數方法(函式)就可以產生亂數然後搭配陣列及迴圈 湊一湊就出來了
再利用小視窗秀出數字
若想將號碼記錄在檔案中當然也行

批次檔功能有限而一般程式語言又難上手
Windows Script 是最好的選擇,投資報酬率最高。
可能有人曾在木馬程式中發現.js 或 .vbs 等副檔名的檔案
沒錯這就是Windows Script,駭客用這個來改你的系統。   

對Windows Script 有興趣可下載這個文件檔案
Windows Script 基本教學及參考文件(中文版)
若想更深入學習可以參考微軟技術網站的相關資料
有問題也可以提出來大家一起研究 !

微軟現在又開發出一個新東西叫做 PowerShell  ,這是架構在.Net 之上
全新的語法與物件導向概念,初學者較難上手。  
目前未內建在Windows Vista 中, 需要另外安裝
應該會內建在未來的Windows 系統中取代cmd 命令提示列+ Windows Script

[jazzblue 在  2008-1-26 10:58 AM 作了最後編輯]





所在時區為 GMT+8, 現在時間是 2024-5-2 07:09 PM
清除 Cookies - 連絡我們 - TWed2k © 2001-2046 - 純文字版 - 說明
Discuz! 0.1 | Processed in 0.023343 second(s), 6 queries , Qzip disabled