Delete files older then n days (VBS)

Here is a VBS script to delete all file older then 10 days in d:\backup.

Set the active constraint to “True” if you want to delete the files.

 

Const Active = False
Const sSource = "d:\backup"
Const MaxAge = 10 'days
Const Recursive = True

Checked = 0
Deleted = 0

Set oFSO = CreateObject("Scripting.FileSystemObject")
if active then verb = "Deleting """ Else verb = "Old file: """
CheckFolder oFSO.GetFolder(sSource)

WScript.echo
if Active then verb = " file(s) deleted" Else verb = " file(s) would be
deleted"
WScript.Echo Checked & " file(s) checked, " & Deleted & verb

Sub CheckFolder (oFldr)
For Each oFile In oFldr.Files
Checked = Checked + 1
If DateDiff("D", oFile.DateLastModified, Now()) > MaxAge Then
Deleted = Deleted + 1
WScript.Echo verb & oFile.Path & """"
If Active Then oFile.Delete
End If
Next

if not Recursive then Exit Sub
For Each oSubfolder In oFldr.Subfolders
CheckFolder(oSubfolder)
Next
End Sub

Default Backup Path in SQL 2008

In the SQL Server 2008 setup you can now set the default backup location but in case you set it wrong or need to change it at later time the SSMS interface does not provide you with any options to do that. You can do the same thing as in 2005 …

Go to following key in Registry and put the new path in …

First we need to determine the instance Name; go to
[HKEY_LOCAL_MACHINE\Software\Microsoft\Microsoft SQL Server\Instance Names\SQL\]

Note down the value for the default instance usually MSSQL10.MSSQLSERVER (note they changed the naming convention of instance names from MSSQL.Instance# to MSSQL10.InstanceID which you enter in at install time).

Now go to …
[HKEY_LOCAL_MACHINE\Software\Microsoft\Microsoft SQL Server\MSSQL10.MSSQLSERVER\MSSQLServer\]

And change the value for BackupDirectory to the new value.

Now if you modify a Maintenance Plan it will grab the new value. You don’t need to restart server or services.

 

source: http://sqllearnings.blogspot.com/2009/03/default-backup-path-in-sql-2008.html

How to send email from a VBS file.

Local Email Server

This is the standard method. It assumes an SMTP email server is installed on your machine. This is the case on most web servers.

 Set objMessage = CreateObject("CDO.Message") 
 objMessage.Subject = "Subject"
 objMessage.Sender = "[email protected]"
 objMessage.To = "[email protected]"
 objMessage.TextBody = "iMacros script completed. Status = OK"
 objMessage.Send

Substitute your own email information and message text. You can insert this code into any script that requires a message to be sent.

Remote Email Server

This code shows you how to use a remotes server rather than the SMTP server on your own machine.

 Set objMessage = CreateObject("CDO.Message") 
 objMessage.Subject = "iMacros Message" 
 objMessage.From = "[email protected]" 
 objMessage.To = "[email protected]" 
 objMessage.TextBody = "iMacros script completed. Status = OK

 '==This section provides the configuration information for the remote SMTP server.
 '==Normally you will only change the server name or IP.
 objMessage.Configuration.Fields.Item _
 ("http://schemas.microsoft.com/cdo/configuration/sendusing") = 2 
 'Name or IP of Remote SMTP Server
 objMessage.Configuration.Fields.Item _
 ("http://schemas.microsoft.com/cdo/configuration/smtpserver") = "smtp.myserver.com"
 'Server port (typically 25)
 objMessage.Configuration.Fields.Item _
 ("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = 25  
 objMessage.Configuration.Fields.Update
 '==End remote SMTP server configuration section==

 objMessage.Send

Remote Email Server with Password

Sending a text email using authentication against a remote SMTP server. More and more administrators are restricting access to their servers to control spam or limit which users may utilize the server. This example shows you how to use basic authentication, the most commonly used authentication method, when the SMTP server you are using requires it.

This code is slightly more complex but not very difficult to understand or work with.

 Const cdoSendUsingPickup = 1 'Send message using the local SMTP service pickup directory. 
 Const cdoSendUsingPort = 2 'Send the message using the network (SMTP over the network). 

 Const cdoAnonymous = 0 'Do not authenticate
 Const cdoBasic = 1 'basic (clear-text) authentication
 Const cdoNTLM = 2 'NTLM

 Set objMessage = CreateObject("CDO.Message") 
 objMessage.Subject = "iMacros Status Message" 
 objMessage.From = """iMacros"" " 
 objMessage.To = "[email protected]" 
 objMessage.TextBody = "iMacros script completed. Status = OK"

 '==This section provides the configuration information for the remote SMTP server.

 objMessage.Configuration.Fields.Item _
 ("http://schemas.microsoft.com/cdo/configuration/sendusing") = 2 

 'Name or IP of Remote SMTP Server
 objMessage.Configuration.Fields.Item _
 ("http://schemas.microsoft.com/cdo/configuration/smtpserver") = "mail.your.com"

 'Type of authentication, NONE, Basic (Base64 encoded), NTLM
 objMessage.Configuration.Fields.Item _
 ("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate") = cdoBasic

 'Your UserID on the SMTP server
 objMessage.Configuration.Fields.Item _
  ("http://schemas.microsoft.com/cdo/configuration/sendusername") = "youruserid"

 'Your password on the SMTP server
 objMessage.Configuration.Fields.Item _
 ("http://schemas.microsoft.com/cdo/configuration/sendpassword") = "yourpassword"

 'Server port (typically 25)
 objMessage.Configuration.Fields.Item _
 ("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = 25 

 'Use SSL for the connection (False or True)
 objMessage.Configuration.Fields.Item _
 ("http://schemas.microsoft.com/cdo/configuration/smtpusessl") = False

 'Connection Timeout in seconds (the maximum time CDO will try to establish a connection to the SMTP   server)
 objMessage.Configuration.Fields.Item _
 ("http://schemas.microsoft.com/cdo/configuration/smtpconnectiontimeout") = 60

 objMessage.Configuration.Fields.Update

 '==End remote SMTP server configuration section==  

 objMessage.Send

Send email with MAPI

This solution assumes that Outlook or another email client with MAPI support is installed.

 Dim ToAddress
 Dim MessageSubject
 Dim MessageBody
 Dim MessageAttachment

 Dim ol, ns, newMail

 ToAddress = "Jim, Test"   ' change this...
 MessageSubject = "iMacros"
 MessageBody = "iMacros Status = OK"

 Set ol = WScript.CreateObject("Outlook.Application")
 Set ns = ol.getNamespace("MAPI")
 ns.logon "","",true,false
 Set newMail = ol.CreateItem(olMailItem)
 newMail.Subject = MessageSubject
 newMail.Body = MessageBody & vbCrLf

 ' validate the recipient, just in case...
 Set myRecipient = ns.CreateRecipient(ToAddress)
 myRecipient.Resolve
 If Not myRecipient.Resolved Then
 MsgBox "unknown recipient"
 Else
    newMail.Recipients.Add(myRecipient)
    newMail.Send
 End If

 Set ol = Nothing

Source: http://wiki.imacros.net/send-email.vbs

Error while installing SQL Server 2005 – Native Client cannot be found

When installing from the original disc’s of Microsoft SQL, the following error occured:

“An installation package for the product Microsoft SQL Server Native
Client cannot be found. Try the installation again using a valid copy of
the installation package ‘sqlncli.msi’”

To resolve this, use the add/Remove programs to deinstall the existing SQL Server Native Client installation.

After deinstalling this package, run the setup again and the problem is fixed.

Windows Live Mesh behind Proxy

Run Netsh Commands for WINHTTP to set proxy?
http://technet.microsoft.com/en-us/library/cc731131(WS.10).aspx

  1. client Start. In the search box, type
    Command, and then right-click on Command
    Prompt
    -> Run as Administrator
  2. in the Command prompt,
  3. type netsh winhttp set proxy myproxy (where
    myproxy should be your proxy server)
    and
    Enter OR type netsh winhttp import proxy source=ie and Enter
    (if you can browser Internet using IE without issue)
  4. click Start. In the search box, type
    Services, and then click Services
  5. find “Windows Live ID Sign-in Assistant” service
    and make sure it is running
  6. if not, make sure its “Startup Type” is set to “Automatic”, and start the
    service manually by right-click -> “Start
  7. find “WinHTTP Web Proxy Auto-Discovery Service
  8. right click on it -> All Tasks -> Restart
  9. run Mesh

How To Use the Symantec Endpoint Recovery Tool with the Latest Virus Definitions

  1. Using an unzipping utility, unzip the .jdb file into a new folder.

    Note: It is possible to use the built-in Windows unzip utility to unzip the .jdb file. To do so, change the file extension on the .jdb file to .zip, right-click the file, and click “Extract All…”.

  2. After the .jdb is uncompressed, place the folder on a removable storage device or in at the root of the infected computer’s hard drive so that the Symantec Endpoint Recovery Tool can access the definitions.
  3. Confirm that the infected computer boots from CD or removable media first.
    Refer to the computer’s manual for information on configuring the computer appropriately.
  4. Boot the infected computer from the SERT disc created in step 2.
  5. Click Continue loading Endpoint Recovery Tool
  6. Select a language and click OK.
  7. When presented with the Symantec Software License Agreement, click I Agree.
  8. If a network connection is detected, the Symantec Endpoint Recovery Tool attempts to download the latest virus definitions. If the computer is isolated from the network, or if it is unable to download definitions for any reason, click Browse for Virus Definitions, and browse to the folder to which you unzipped the virus definitions.
  9. Verify that the virus definitions have been loaded by looking in the lower right-hand corner of the screen. Virus definitions current as of should reflect the current date.
  10. Make sure that Save scan session information is checked.
    Saving the scan session allows you to undo any modifications made by the tool.
    If needed, you can change the location where the scan session information will be stored. To do so, click  Change location and select the preferred location.
  11. Click Start Scan.

 

Source: http://www.symantec.com/docs/TECH131732