that example was need for this script. if u noticed mistake or know how improve it, please tell me
' script backup system volume information, if space isn't enough, sen e-mail
dim colFolders, objFolder, Envi, objFolder2, objFolder3, SystemPath, DirectoryName, strComputer
dim WshShell, objPName, net
dim fsoObject, LogFile, txtStream, tag, objEmail
dim objNetwork, objComputerName, objUserName, namefolder
' Computer Name and Logoned Username
Set objNetwork = CreateObject("Wscript.Network") ' объявляем Network, создаём программный объект автоматизации
objComputerName = objNetwork.ComputerName
objUserName = objNetwork.UserName
k = 34
kk = chr(34)
strComputer = "."
Set WshShell = WScript.CreateObject ("WScript.Shell")
IF WshShell.RegRead("HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\CurrentVersion") > "5.1" Then
wscript.quit
end if
objPName = WshShell.RegRead("HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\ProductName")
IF Instr( 1, LCase (objPName), "microsoft windows server", 1) = 0 Then
set fsoObject = Wscript.CreateObject("Scripting.FileSystemObject")
Set Envi = WshShell.Environment ("Process")
SystemPath = Envi("SystemDrive")
DirectoryName = SystemPath & "\System Volume Information"
' name of organization
If fsoObject.FileExists("c:\\program files\OCS Inventory Agent\service.ini") Then
Set LogFile = fsoObject.OpenTextFile("c:\program files\OCS Inventory Agent\service.ini", 1)
txtStream = LogFile.ReadAll
tag = InStr(LCase(txtStream), "/tag:")
txtStream = mid(txtStream,tag)
tag = InStr(LCase(txtStream), " ")
txtStream = left(txtstream,tag)
txtStream = mid(txtstream,6)
LogFile.Close
else
txtstream = "file doesn't exist"
end if
' make mail for sending
Set objEmail = CreateObject("CDO.Message")
objEmail.From = "***@***.***"
objEmail.To = txtStream + "@***.***"
objEmail.Configuration.Fields.Item _
("http://schemas.microsoft.com/cdo/configuration/sendusing") = 2
objEmail.Configuration.Fields.Item _
("http://schemas.microsoft.com/cdo/configuration/smtpserver") = _
"***"
objEmail.Configuration.Fields.Item _
("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = 25
objEmail.Configuration.Fields.Update
if fsoObject.FolderExists (SystemPath & "\System Volume Information") Then
Set objFolder2 = fsoObject.GetFolder(SystemPath & "\System Volume Information")
Set colFolders = objFolder2.SubFolders
For Each objFolder in colFolders
If Instr(objFolder.Name, "restore") <> 0 then
k = 1
end if
Next
if objFolder2.Size = 0 then
k = 0
end if
If k = 1 then
' проверяем свободное место
if frit(systemPath) > 10 then
DirectoryName = SystemPath & "\sr"
Set CmdLog = fsoObject.OpenTextFile("C:\Cmd.cmd", 2, "True")
CmdLog.Writeline "CHCP 1251"
CmdLog.Writeline kk & "%ProgramFiles%\nnBackup\nnbackup.exe" & kk & " sync -i " & kk & "%SystemDrive%\System Volume Information\" & kk & " -o " & kk & "%SystemDrive%\sr\backup" & kk & " -s -sa -e -c -x *.tmp"
CmdLog.Close
net = WShShell.Run ("C:\Cmd.cmd", 0, true)
wscript.sleep 15000
fsoObject.DeleteFile("C:\Cmd.cmd")
Set objWMIService = GetObject("winmgmts:" & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
Set colFolders = objWMIService.ExecQuery("ASSOCIATORS OF {Win32_Directory.Name='" & DirectoryName & "'}" & "WHERE AssocClass = Win32_Subdirectory " & "ResultRole = PartComponent")
For Each objFolder in colFolders
LMDate = objFolder.LastModified
datemod = WMIDateStringToDate(LMDate)
namefolder = objFolder.Name
Set objShell = CreateObject("Shell.Application")
Set objFolder2 = objShell.Namespace(nameFolder)
Set objFolder3 = fsoObject.GetFolder(namefolder)
if objFolder3.Size > 0 then
Set CmdLog = fsoObject.OpenTextFile("C:\Cmd.cmd", 2, "True")
CmdLog.Writeline "CHCP 1251"
CmdLog.Writeline kk & "%ProgramFiles%\nnBackup\7za.exe" & kk & " a " & kk & "%SystemDrive%\sr\" & objfolder2 & "_" & date & ".7z" & kk & " " & kk & namefolder & kk & " -v2g"
CmdLog.Close
net = WShShell.Run ("C:\Cmd.cmd", 0, true)
wscript.sleep 15000
fsoObject.DeleteFile("C:\Cmd.cmd")
else
objEmail.Subject = "Restore!"
objEmail.Textbody = "System Restore not work properly on PC. User " & objUserName & " on " & objComputerName & " company " & txtStream & ". folder size = 0 " & vbCrlf
objEmail.Send
end if
Next
Set objFolder = FSOObject.GetFolder(SystemPath & "\sr\")
If objFolder.Attributes and 2 Then
else
objFolder.Attributes = objFolder.Attributes XOR 2
End If
Set colFiles = objWMIService.ExecQuery("ASSOCIATORS OF {Win32_Directory.Name='" & DirectoryName & "'} Where " _
& "ResultClass = CIM_DataFile")
For Each objFile in colFiles
LMDate = objFile.LastModified
datemod = WMIDateStringToDate(LMDate)
If date - 3 > datemod then ' date!!!!!!!!!!!!!!!!!!!!!!!!!!!
errResults = objFile.Delete
end if
Next
else
objEmail.Subject = "Restore?!"
objEmail.Textbody = "System Restore not work properly on PC. User " & objUserName & " on " & objComputerName & " company " & txtStream & "Free space < 10 Gb, backup canceled. " & vbCrlf
objEmail.Send
end if
else
objEmail.Subject = "Restore!"
objEmail.Textbody = "System Restore not work properly on PC. User " & objUserName & " on " & objComputerName & " company " & txtStream & "Computer may be infected. Urgent intervention is needed!!! " & vbCrlf
objEmail.Send
' clean
WshShell.RegWrite "HKLM\Software\Policies\System\DisableRegistryTools", 0, "REG_DWORD"
WshShell.RegWrite "HKLM\Software\Microsoft\Windows\CurrentVersion\Policies\System\DisableRegistryTools", 0, "REG_DWORD"
WshShell.RegWrite "HKCU\Software\Policies\System\DisableRegistryTools", 0, "REG_DWORD"
WshShell.RegWrite "HKCU\Software\Microsoft\Windows\CurrentVersion\Policies\System\DisableRegistryTools", 0, "REG_DWORD"
WshShell.RegWrite "HKEY_USERS\.DEFAULT\Software\Microsoft\Windows\CurrentVersion\Policies\System\DisableRegistryTools", 0, "REG_DWORD"
WshShell.RegDelete "HKEY_LOCAL_MACHINE\SOFTWARE\Policies\Microsoft\Windows NT\SystemRestore\"
WshShell.RegDelete "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Policies\Microsoft\Windows NT\SystemRestore\"
WshShell.RegDelete "HKEY_CURRENT_USER\Software\Policies\Microsoft\Windows NT\SystemRestore\"
WshShell.RegDelete "HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Policies\Microsoft\Windows NT\SystemRestore\"
WshShell.RegDelete "HKEY_USERS\.DEFAULT\Software\Microsoft\Windows\CurrentVersion\Policies\Microsoft\Windows NT\SystemRestore\"
WshShell.RegWrite "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\SystemRestore\DisableSR", 0, "REG_DWORD"
WshShell.RegWrite "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\SystemRestore\DSMax", 2000, "REG_DWORD"
WshShell.RegWrite "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\SystemRestore\DiskPercent", 2, "REG_DWORD"
WshShell.RegDelete "HKEY_LOCAL_MACHINE\SOFTWARE\Policies\System\DisableTaskMgr"
WshShell.RegDelete "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Policies\System\DisableTaskMgr"
WshShell.RegDelete "HKEY_CURRENT_USER\Software\Policies\System\DisableTaskMgr"
WshShell.RegDelete "HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Policies\System\DisableTaskMgr"
WshShell.RegDelete "HKEY_USERS\.DEFAULT\Software\Microsoft\Windows\CurrentVersion\Policies\System\DisableTaskMgr"
WshShell.RegWrite "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Winlogon\Userinit", "C:\\WINDOWS\\system32\\userinit.exe", "REG_SZ"
end if
end if
end if
wscript.quit
' free space in Gb
function frit(gg)
frit = FormatNumber(fsoObject.GetDrive(gg).FreeSpace/1048576, 1)
frit = FormatNumber(frit/1024,1)
End function
Function WMIDateStringToDate(LMDate)
WMIDateStringToDate = CDate(Mid(LMDAte, 7, 2) & "/" & Mid(LMDAte, 5, 2) & "/" & Left(LMDAte, 4) _
& " " & Mid (LMDAte, 9, 2) & ":" & _
Mid(LMDAte, 11, 2) & ":" & Mid(LMDAte, _
13, 2))
End Function