將 域用戶或租添加到本地組 Set objGroup = GetObject(WinNT://./Administrators) Set objUser = GetObject(WinNT://testnet/Engineers) objGroup.Add(objUser.ADsPath) 修改本地管理員密碼 Set objcnlar = GetObject(WinNT://./administrator, user) objcnla.SetPassword P@ssW0rd objcnla.SetInfo 彈出 YES or NO 的對(duì)話框,不同的選擇執(zhí)行不同的代碼 intAnswer = Msgbox(Do you want to delete these files?, vbYesNo, Delete Files) If intAnswer = vbYes Then Msgbox You answered yes. Else Msgbox You answered no. End If 運(yùn)行CMD命令行命令 set obshell=wscript.createobject(wscript.shell) obshell.run (ipconfig),,true 如果要運(yùn)行的命令中包含雙引號(hào),,可使用&chr(34)&代替 忽略代碼錯(cuò)誤繼續(xù)執(zhí)行 On Error Resume Next 放置于代碼的最開頭,當(dāng)代碼運(yùn)行出錯(cuò)后并不停止跳出而是繼續(xù)執(zhí)行下一條,。適當(dāng)應(yīng)用會(huì)很有效果。 注冊(cè)表的修改,,讀取,,刪除,創(chuàng)建 Set wso = CreateObject(WScript.Shell) '聲明 wso.RegWrite %Path%'創(chuàng)建子鍵 wso.RegWrite %Path%,%Value%'修改默認(rèn)鍵值 wso.RegWrite %Path%,%Value%,%RegType% '修改特定類型的鍵值 '(字符串值 REG_SZ 可擴(kuò)充字符串值 REG_EXPAND_SZ DWORD值 REG_DWORD 二進(jìn)制值 REG_BINARY) Set WSHShell= Wscript.CreateObject(Wscript.Shell) WSHShell.RegRead (%Path%) '讀取注冊(cè)表子鍵或鍵值(一般用于判斷某一事件是否執(zhí)行) Set wso = CreateObject(WScript.Shell) wso.RegDelete %Path% '刪除子鍵或鍵值 '(根鍵縮寫HKEY_CLASSES_ROOT HKCR HKEY_CURRENT_USER HKCU HKEY_LOCAL_MACHINE HKLM,其余無) 引用內(nèi)容 eg: Set wso = CreateObject(Wscript.Shell) wso.RegWrite HKLM\SOFTWARE\Microsft\Windows NT\#1 wso.RegWrite HKLM\SOFTWARE\Microsft\Windows NT\#1,0 wso.RegWrite HKLM\SOFTWARE\Microsft\Windows NT\#1\#2,0,REG_BINARY wso.RegDelete HKLM\SOFTWARE\Microsft\Windows NT\#1 Wscript.quit 文件的復(fù)制,,刪除,,創(chuàng)建,簡單的寫入 Set fso = Wscript.CreateObject(Scripting.FileSystemObject) ‘聲明 Set f = fso.CreateTextFile(%PATH%) '創(chuàng)建文件,其中f可任意,,包含縮略名 f.WriteLine(VBS) '寫文件內(nèi)容,該命令功能太簡單,目前看來只能用于TXT文件 f.Close set c=fso.getfile(%path%) '拷貝某文件 c.copy(%PATH2%) '拷貝文件到指定地點(diǎn) fso.deletefile(%PATH%) '刪除文件 Wscript.quit 引用內(nèi)容 eg. Set fso = Wscript.CreateObject(Scripting.FileSystemObject) Set f=fso.CreateTextFile(C:\Sample.txt) WriteLine(VBS) f.close set e=fso.getfile(C:\Sample.txt) e.copy(D:\Sample.txt) fso.deletefile(C:\Sample.txt) Wscript.quit 向應(yīng)用程序輸出簡單的連串指令 dim program1 '聲明變量program1 program1= %Path% '應(yīng)用程序路徑 set wshshell=createobject(wscript.shell) '聲明飲用函數(shù) set oexec=wshshell.exec(program1) '運(yùn)行程序 wscript.sleep 2000 '(該行命令未知作用.估計(jì)是設(shè)定延遲,,請(qǐng)高手指點(diǎn)) wshshell.appactivate %WindowsName% '激活運(yùn)用程序窗口 wshshell.sendkeys +{%KeyBoardName%} '第一次輸出鍵盤按鍵指令前要加+ wshshell.sendkeys 555555 '在程序輸入欄中輸入運(yùn)用該系列命令須首先確定程序可以實(shí)施連串的鍵盤操作,這在QQ登錄中最適用,,如下例,。 引用內(nèi)容 eg. dim program1 program1=D:\Program Files\Tencent\coralQQ.exe set wshshell=CreateObject(wscript.shell) set oexec=wshshell.exec(program1) wscript.sleep 2000 wshshell.appactivate QQ登錄 wshshell.sendkeys +{TAB} wshshell.sendkeys 250481892 wscript.sleep 2000 wshshell.sendkeys {TAB} wshshell.sendkeys **************** wscript.sleep 2000 wshshell.sendkeys {ENTER} Wscript.quit 文件夾的簡單操作 Set fso = Wscript.CreateObject(Scripting.FileSystemObject) ‘聲明 Set f = fso.CreateFolder(%PATH%) 創(chuàng)建文件夾 Set e = getFolder(%PATH%) 類似于“綁定目標(biāo)” e.copy(%PATH2%) 復(fù)制文件夾 fso.deletefolder(%PATH%) 刪除文件夾 引用內(nèi)容 eg. Set fso = Wscript.CreateObject(Scripting.FileSystemObject) Set f = fso.CreateObject(C:\sample) f.copy(D:\sample) fso.deletefolder(C:\sample) '(由上例可以看出,文件夾的操作很多是和文件的操作相通的,,因此VBS文件具有很多命令的統(tǒng)一性) 將某一指定文件夾的所有只讀文件轉(zhuǎn)為可讀文件 Const ReadOnly = 1 ‘設(shè)只讀屬性對(duì)應(yīng)值為1 Set FSO = CreateObject(Scripting.FileSystemObject) '聲明 Set Folder = FSO.GetFolder(%PATH%) '綁定文件夾 Set colFiles = Folder.Files ‘文件夾所有文件 For Each objFile in colFiles '下列語句應(yīng)用于文件夾所有文件 If File.Attributes AND ReadOnly Then '這是關(guān)鍵之處,,這里應(yīng)用了If判斷語句,來檢測文件屬性是否為只讀 File.Attributes = File.Attributes XOR ReadOnly ‘對(duì)判斷結(jié)果為Ture(默認(rèn)為True)'執(zhí)行XOR邏輯運(yùn)算,,將其改為可讀 End If ‘結(jié)束判斷 Next 將Word文件另存為文本文件 Const wdFormatText = 2 '設(shè)置常數(shù)值 (當(dāng)該值為8時(shí)另存為HTML文檔,,為11時(shí)另存為XML文檔) Set objWord = CreateObject(Word.Application) '申明調(diào)用函數(shù) Set objDoc = objWord.Documents.Open(%Path%) ‘打開某DOC文件 objDoc.SaveAs %PATH2%, wdFormatText 另存為…… objWord.Quit 引用內(nèi)容 eg: Const wdFormatText = 2 Set objWord = CreateObject(Word.Application) Set objDoc = objWord.Documents.Open(d:\doc1.doc) objDoc.SaveAs g:\doc1.txt, wdFormatText objWord.Quit 如對(duì)本文有疑問,請(qǐng)?zhí)峤坏浇涣魃鐓^(qū),,廣大熱心網(wǎng)友會(huì)為你解答?。? 點(diǎn)擊進(jìn)入社區(qū) |
|