Professional Documents
Culture Documents
Const TempWin =
C:\Windows\Temp\
Const Recent =
C:\Windows\Recent\*.*
DelTempDir
Sub DelTempDir ()
Dim fso
Set fso =
CreateObject(Scripting.FileSystemObject)
End Sub
end;
//===============================================================
============
//
// Topic: InstallNetFrameWork
//
// Description:
//
// My Name :
//
//===============================================================
============
function InstallNetFrameWork(filePath)
NUMBER nvDx, nvDy, nvResult, nvType, nvSize;
STRING svResult, svVersionNumber;
begin
MessageBox("NetFx20SP1_x86.exe
doesn't exist in Net Frmework foder in CD, please check
again.",WARNING);
//abort;
InformFinishNetFramWork();
else
//if (AskYesNo("Would you
like to restart computer now?", YES ) = YES) then
//SdFinishReboot ( szTitle, szMsg1, SYS_BOOTMACHINE, szMsg2, 0 );
// System
(SYS_BOOTMACHINE);
// abort;
// endif;
endif;
else
endif;
else
//abort;
MessageBox("Microsoft .NET Framework 2.0
installation is not completed",WARNING);
InformFinishNetFramWork();
endif;
if(CheckNetFameWorkRuning()==FALSE) then
MessageBox("Microsoft .NET Framework 2.0
installation is not completed",WARNING);
InformFinishNetFramWork();
//MessageBox("HAHHAHAH",WARNING);
endif;
end;
//===============================================================
============
//
// Topic: CheckNetFameworkCreateFile
//
// Description:
//
// My Name :
//
//===============================================================
============
function BOOL
CheckNetFameworkCreateFile(strFolderPath,fileEXE,createdFile)
BOOL blnResult;
NUMBER nvDx, nvDy, nvResult, nvType, nvSize;
STRING svVersionNumber;
STRING para;
begin
blnResult=FALSE;
para="\""+ strFolderPath^ createdFile+ "\"";
if LaunchAppAndWait (strFolderPath^fileEXE,para,
LAAW_OPTION_WAIT|LAAW_OPTION_HIDDEN)=0 then
if Is(FILE_EXISTS,strFolderPath^
createdFile)==TRUE then
blnResult=TRUE;
DeleteFile(strFolderPath^ createdFile);
else
blnResult=FALSE;
endif;
endif;
return blnResult;
end;
//===============================================================
============
//
// Topic: InformFinishNetFramWork
//
// Description:
//
// My Name :
//
//===============================================================
============
function BOOL CheckNetFameWorkRuning()
begin
if
CheckNetFameworkCreateFile(SUPPORTDIR,"CheckNetFamework.exe","Che
ckNetFamework.txt")=FALSE then
return FALSE;
else
return TRUE;
endif;
end;
//===============================================================
============
//
// Topic: InformFinishNetFramWork
//
// Description:
//
// My Name :
//
//===============================================================
============
function InformFinishNetFramWork()
NUMBER nResult, nLevel, nSize, nSetupType;
STRING szTitle, szMsg, szOpt1, szOpt2, szLicenseFile;
STRING szName, szCompany, szTargetPath, szDir, szFeatures;
BOOL bLicenseAccepted;
STRING szProductName;
STRING szMsg1, szMsg2;
BOOL bvOpt1, bvOpt2;
NUMBER nReturn;
NUMBER nType, nMediaFlags;
STRING szIgnore,svOldPath;
STRING szKey, szNumName, szNumValue, svNumValue;
begin
svFilePath=WINDISK+"\\WINDOWS\\system32\\msiexec.exe";
rs = VerGetFileVersion (svFilePath ,svVersionNumber);
if(svVersionNumber=="") then
else
if(rs ==FILE_NOT_FOUND ||
svVersionNumber< "3.1.0.0" ) then
if( LaunchAppAndWait(SUPPORTDIR^"\\WindowsInstaller-KB893803-v2-
x86.exe","",LAAW_OPTION_WAIT)<0)then
MessageBox("
WindowsInstaller3.1 installation is not completed",WARNING);
InformFinishWI3_1();
else
//if
(AskYesNo("Would you like to restart computer now?", YES ) = YES)
then
//endif;
endif;
endif;
if(CheckSencondWINDOWS()==FALSE)
then
MessageBox("
WindowsInstaller3.1 installation is not completed",WARNING);
InformFinishWI3_1();
else
endif;
endif;
end;
//===============================================================
============
//
// Topic: CheckSencondWINDOWS
//
// Description:
//
// My Name :
//
//===============================================================
============
function BOOL CheckSencondWINDOWS()
string
svVersionNumber,svFilePath,svFilePath2,svVersionNumber2;
number rs;
begin
svFilePath=WINDISK+"\\WINDOWS\\system32\\msiexec.exe";
rs = VerGetFileVersion (svFilePath ,svVersionNumber);
if(svVersionNumber<"3.1.0.0") then
return FALSE;
else
return TRUE;
endif;
end;
Chú ý : Tất cả những file này được save tại E:\SQL_Backup\scripts. Bạn có thể thay
đổi đường dẫn thư mục tùy ý.
Tiếp theo,chúng ta cần tạo một file VBScript để xóa những database cũ .Script này
cũng được ghi tại file log .
Bạn cần tạo một file trống E:\SQL_Backup\scripts\LOG.txt để save log của
file bị xóa.
Đặt script theo đường dẫn E:\SQL_Backup\scripts\deleteBAK.vbs
On Error Resume Next
Dim fso, folder, files, sFolder, sFolderTarget
Set fso = CreateObject("Scripting.FileSystemObject")
'location of the database backup files
sFolder = "E:\SQL_Backup\"
Set folder = fso.GetFolder(sFolder)
Set files = folder.Files
'used for writing to textfile - generate report on database backups deleted
Const ForAppending = 8
'you need to create a folder named “scripts” for ease of file management &
'a file inside it named “LOG.txt” for delete activity logging
Set objFile = fso.OpenTextFile(sFolder & "\scripts\LOG.txt", ForAppending)
objFile.Write "================================================================"
& VBCRLF & VBCRLF
objFile.Write " DATABASE BACKUP FILE REPORT "
& VBCRLF
objFile.Write " DATE: " & FormatDateTime(Now(),1) & ""
& VBCRLF
objFile.Write " TIME: " & FormatDateTime(Now(),3) & ""
& VBCRLF & VBCRLF
objFile.Write "================================================================"
& VBCRLF
'iterate thru each of the files in the database backup folder
For Each itemFiles In files
'retrieve complete path of file for the DeleteFile method and to extract
'file extension using the GetExtensionName method
a=sFolder & itemFiles.Name
'retrieve file extension
b = fso.GetExtensionName(a)
'check if the file extension is BAK
If uCase(b)="BAK" Then
'check if the database backups are older than 3 days
If DateDiff("d",itemFiles.DateCreated,Now()) >= 3 Then
'Delete any old BACKUP files to cleanup folder
fso.DeleteFile a
objFile.WriteLine "BACKUP FILE DELETED: " & a
End If
End If
Next
objFile.WriteLine
"================================================================" & VBCRLF &
VBCRLF
objFile.Close
Set objFile = Nothing
Set fso = Nothing
Set folder = Nothing
Set files = Nothing
Bước 3 : tạo tệp bat kết hợp T-SQL Script và VBScript.
Chúng ta cần tạo tệp BAT để kết hợp cả 2 script vừa tạo trên.Nội dung của tệp bat thực hiện
dựa trên sqlcmd.exe.Save tệp BAT này tại : E:\SQL_Backup\scripts\databaseBackup.cmd
REM Run TSQL Script to backup databases
sqlcmd -S<INSTANCENAME>-E -i"E:\SQL_Backup\scripts\backupDB.sql" REM Run
database backup cleanup script
E:\SQL_Backup\scripts\deleteBAK.vbs
Bước 4 : tạo tác vụ backup định kì với Windows Task Cheduler.
Khi chứng thực Windows để chạy script T-SQL,sử dụng tài khoản Windows
là db_backupoperator (đây là tài khoản sử dụng cho mọi database)
Mở "Scheduled Tasks"
Click Add Scheduled Task
Mở "E:\SQL_Backup\scripts" folder và click databaseBackup.cmd
Chọn thời gian định kì cần backup.
Nhập tài khoản db_backupoperator vào.
Kết thúc quá trình tạo tác vụ backup định kì.