Tải bản đầy đủ (.doc) (6 trang)

Một số thủ thuật lập trình với ngôn ngữ Vbscript ppt

Bạn đang xem bản rút gọn của tài liệu. Xem và tải ngay bản đầy đủ của tài liệu tại đây (55.62 KB, 6 trang )

Một số thủ thuật lập trình với ngôn ngữ Vbscript
Chúng ta copy code sau đây ở Notepad và lưu nó dưới đuôi là vbs
Chẳng hạn như vb xoá prefetch save với tên là xoa prefetch.vbs

VB Xoá prefetch để tăng tốc CPU
Dim fso
Set fso = Createobject("Scripting.FileSystemObject")
Dim MyVar
MyVar = MsgBox ("ban co muon xoa cac muc rac co trong
prefetch khong ( de tang toc CPU )?", 0, "Xoa Prefetch (tran thang
long)")
fso.DeleteFile("C:\WINDOWS\Prefetch\*.*")
VB xem ngày,giờ,tháng,năm,quý….
On Error Resume Next
strComputer = "."
Set objWMIService = GetObject("winmgmts:\\" & strComputer &
"\root\cimv2")
Set colItems = objWMIService.ExecQuery("Select * from
Win32_UTCTime")
For Each objItem in colItems
Wscript.Echo "ngay: " & objItem.day
Wscript.Echo "ngay trong tuan: " & objItem.DayOfWeek
Wscript.Echo "gio: " & objItem.Hour
Wscript.Echo "phut: " & objItem.Minute
Wscript.Echo "thang: " & objItem.Month
Wscript.Echo "quy: " & objItem.Quarter
Wscript.Echo "giay: " & objItem.Second
Wscript.Echo "tuan trong thang: " & objItem.WeekInMonth
Wscript.Echo "nam: " & objItem.Year
Wscript.Echo "het roi"
Next


VB ẩn hiện chức năng foder option
Option Explicit
Dim WSHShell, n, MyBox, p, p1, Title911, errnum, vers, itemtype
Set WSHShell = WScript.CreateObject("WScript.Shell")
p =
"HKCU\Software\Microsoft\Windows\CurrentVersion\Policies\Ex
plorer\"
p1 =
"HKLM\Software\Microsoft\Windows\CurrentVersion\Policies\Ex
plorer\"
p = p & "NoFolderOptions"
p1 = p1 & "NoFolderOptions"
itemtype = "REG_DWORD"
Title911 = " Tran Thang Long"
Err.Clear
On Error Resume Next
n = WSHShell.RegRead (p)
On Error Goto 0
errnum = Err.Number
if errnum <> 0 then
WSHShell.RegWrite p, 0, itemtype
WSHShell.RegWrite p1, 0, itemtype
End If
If n = 0 Then
n = 1
WSHShell.RegWrite p, n, itemtype
WSHShell.RegWrite p1, n, itemtype
Mybox = MsgBox("Folder Options cua ban da bi AN ,xin thanh
that chia buon voi ban( chu y: log off lai de co ket qua.)", 4096,
Title911)

ElseIf n = 1 then
n = 0
WSHShell.RegWrite p, n, itemtype
WSHShell.RegWrite p1, n, itemtype
Mybox = MsgBox("Chuc nang foder option da duoc mo (chu y:
log off lai de co ket qua.)", 4096, Title911)
", 4096, Title911)
End If
VB khoá mở registry
Option Explicit
Dim WSHShell, n, MyBox, p, Titletan_co, errnum, vers, itemtype
Set WSHShell = WScript.CreateObject("WScript.Shell")
p =
"HKCU\Software\Microsoft\Windows\CurrentVersion\Policies\Sy
stem\"
p = p & "DisableRegistryTools"
itemtype = "REG_DWORD"
Titletan_co = "tran thang long"
Err.Clear
On Error Resume Next
n = WSHShell.RegRead (p)
On Error Goto 0
errnum = Err.Number
if errnum <> 0 then
WSHShell.RegWrite p, 0, itemtype
End If
If n = 0 Then
n = 1
WSHShell.RegWrite p, n, itemtype
Mybox = MsgBox("registry cua ban da KHOA {~_~}' ", 4096,

Titletan_co)
ElseIf n = 1 then
n = 0
WSHShell.RegWrite p, n, itemtype
Mybox = MsgBox("Registry da MO {=+0+=}", 4096, Titletan_co)
End If
Xem dung lượng của ổ
Option Explicit
MsgBox RunOutput( "COMMAND /C DIR chọn ổ:\", 0 )
Function RunOutput( cProgram, nWindowType )
Dim oFS
Set oFS = CreateObject("Scripting.FileSystemObject")
Dim cFile
cFile = oFS.GetSpecialFolder(2).Path & "\" & oFS.GetTempName
Dim oShell
Set oShell = CreateObject( "WScript.Shell" )
oShell.Run cProgram & " >" & cFile, nWindowType, True
Set oShell = Nothing
Dim oFile
Set oFile = oFS.OpenTextFile(cFile, 1, True)
RunOutput = oFile.ReadAll()
oFile.Close
oFS.DeleteFile cFile
End Function
Chúc các bạn thành công! 



×