venerdì 30 ottobre 2009

vbscript : Automated Email sending

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 = "Example CDO Message" 
objMessage.From = "blabla@gmail.com" 
objMessage.To = "blabla@gmail.com" 
objMessage.TextBody = "This is some sample message text." 

'==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.gmail.com"


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

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

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

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

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

'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

in riferimento a: g - Cerca con Google (visualizza su Google Sidewiki)

vbscript That list pc network connections

strComputer = "."
Set objWMIService = GetObject("winmgmts:" _
& "{impersonationLevel=impersonate}!\\" & strComputer & _
"\root\microsoft\homenet")

Set colItems = objWMIService.ExecQuery("Select * from HNet_Connection")

For Each objItem in colItems
Wscript.Echo "GUID: " & objItem.GUID
Wscript.Echo "Is LAN Connection: " & objItem.IsLANConnection
Wscript.Echo "Name: " & objItem.Name
Wscript.Echo "Phone Book Path: " & objItem.PhoneBookPath
Next

in riferimento a: g - Cerca con Google (visualizza su Google Sidewiki)

Google XMPP gTalk Notifier

Example :
package com.vincenzoamoruso.notifier;

import java.util.logging.Logger;

import com.google.appengine.api.xmpp.JID;
import com.google.appengine.api.xmpp.Message;
import com.google.appengine.api.xmpp.MessageBuilder;
import com.google.appengine.api.xmpp.SendResponse;
import com.google.appengine.api.xmpp.XMPPService;
import com.google.appengine.api.xmpp.XMPPServiceFactory;


public class XMPPNotifier {
private static final Logger log = Logger.getLogger(XMPPNotifier.class.getName());

public boolean sendXMPP(String toID,String Message,boolean tryByMail){
JID jid = new JID(toID);
String msgBody = Message;
Message msg = new MessageBuilder()
.withRecipientJids(jid)
.withBody(msgBody)
.build();
boolean messageSent = false;
XMPPService xmpp = XMPPServiceFactory.getXMPPService();
if (xmpp.getPresence(jid).isAvailable()) {
SendResponse status = xmpp.sendMessage(msg);
messageSent = (status.getStatusMap().get(jid) == SendResponse.Status.SUCCESS);
}
if (!messageSent) {
System.out.println("Non Inviato");
log.warning("Non Inviato");
}
return messageSent;
}
}

in riferimento a: g - Cerca con Google (visualizza su Google Sidewiki)

Formatting Date in JSP

1) Import classes in JSP Page
<%@ page import="java.text.DateFormat" %>
<%@ page import="java.text.SimpleDateFormat" %>

2) Inizialize object and define date format
DateFormat formatter = new SimpleDateFormat("dd/MM/yyyy");

3) Format date value
"<%=formatter.format(new Date()) %>"

in riferimento a: g - Cerca con Google (visualizza su Google Sidewiki)

Formatting Date JSP

1) Import classes in JSP Page
<%@ page import="java.text.DateFormat" %>
<%@ page import="java.text.SimpleDateFormat" %>

2) Inizialize object and define date format
DateFormat formatter = new SimpleDateFormat("dd/MM/yyyy");

3) Format date value
"<%=formatter.format(new Date()) %>"

in riferimento a: g - Cerca con Google (visualizza su Google Sidewiki)

Wincheck Online on Google AppEngine

sabato 24 ottobre 2009

Available memory from Vbs

Available memory from Vbs
strComputer = "."
Set objWMIService = GetObject("winmgmts:\\" & strComputer &
"\root\CIMV2")
Set colCSItems = objWMIService.ExecQuery("SELECT * FROM
Win32_ComputerSystem")
For Each objCSItem In colCSItems 
WScript.Echo "Total Physical Memory: " &
objCSItem.TotalPhysicalMemory
Next
Set colOSItems = objWMIService.ExecQuery("SELECT * FROM
Win32_OperatingSystem")
For Each objOSItem In colOSItems 
WScript.Echo "Free Physical Memory: " &
objOSItem.FreePhysicalMemory 
WScript.Echo "Total Virtual Memory: " &
objOSItem.TotalVirtualMemorySize 
WScript.Echo "Free Virtual Memory: " &
objOSItem.FreeVirtualMemory 
WScript.Echo "Total Visible Memory Size: " &
objOSItem.TotalVisibleMemorySizeNext

Vbs starts Windows Services

This script start windows Service :

set myServices = GetObject("winmgmts:")
set myObject = myServices.Get("Win32_Service.Name='MSSQLSERVER'")
myObject.StartService()

IE vbs robot Browser - reading key in text file

Read text file named "Cerca.txt

On Error Resume Next
DO
Set fso = WScript.CreateObject("Scripting.FileSystemObject")
Set file = fso.OpenTextFile( "Cerca.txt", 1, False, 0)
Do While file.AtEndOfStream <> True
set objExplorer=WScript.CreateObject("InternetExplorer.Application","objExplorer_")
objExplorer.navigate2("http://www.google.it")
objExplorer.ToolBar = 0
objExplorer.StatusBar = 0
objExplorer.Left = 0
objExplorer.Top = 0
objExplorer.Visible = 1
Do Until
objExplorer.ReadyState=4
WScript.Sleep inti*100*Rnd()
Loop
objExplorer.Document.All.Item("q").Value = file.ReadLine
objExplorer.Document.All.Item("sa").Click
Do Until
objExplorer.ReadyState=4
WScript.Sleep inti*100*Rnd()
Loop
WScript.Sleep
inti*100*Rnd()
Loop
objExplorer.Quit
file.Close()
Set file=Nothing
Set fso=Nothing
inti = inti + 1
Loop Until inti = 1300
Wscript.Quit
 

Massive string in file sustitution by vbs script

Massive string in file sustitution by vbs script :


' Script per Sostituzione di massa stringhe in file

' Massive text in file substution

Set oFSO = CreateObject("Scripting.FileSystemObject")Set
objShell = WScript.CreateObject( "WScript.Shell" )
Set fOut = oFSO.CreateTextFile("StringInFileSubstitution.txt", True)
Dim FileName, Find,
ReplaceWith, FileContents, dFileContents, PathDir

Dim NomeP

Dim OutPut


'Modifica file nella cartella
Find = Inputbox ("Inserisci la stringa da cercare nei file","The Patcher","pippo")
ReplaceWith = Inputbox ("Inserisci la stringa da sostituire a " + Find ,"The Patcher","pippa")
PathDir = Inputbox ("Inserisci il path da cui partire","The
Patcher","C:\Test1")
DoStuff oFSO.GetFolder(PathDir).Path,Find,ReplaceWith

'Read text file

function Fix(FileName, Find, ReplaceWith)
'Read source text
fileFileContents = GetFile(FileName)
'replace all string In the source
filedFileContents = replace(FileContents, Find, ReplaceWith, 1, -1, 1)
'Compare source And result

if dFileContents <> FileContents
Then

'write result If different

WriteFile FileName, dFileContents
If Len(ReplaceWith) <> Len(Find) Then 'Can we
count n of replacements? fOut.WriteLine "DB " & FileName & "
file Fixed." fOut.WriteLine _ (
(Len(dFileContents) - Len(FileContents)) / (Len(ReplaceWith)-Len(Find)) ) &
_ " fixes Applied."

End

IfElse ' fOut.WriteLine "No
Fixes Applied to source file " & FileNameEnd If
End Function

'Read text file

function GetFile(FileName)

If FileName<>""
Then Dim FS, FileStream Set FS =
CreateObject("Scripting.FileSystemObject")

on error resume Next

Set FileStream = FS.OpenTextFile(FileName)

GetFile = FileStream.ReadAll End IfEnd Function
'Write string As a text file.

function WriteFile(FileName, Contents)

Dim OutStream, FS
on error resume Next

Set FS = CreateObject("Scripting.FileSystemObject")

Set OutStream = FS.OpenTextFile(FileName, 2, True)

OutStream.Write Contents

End

Function Sub DoStuff(sDir,Find,ReplaceWith)

fOut.WriteLine sDirSet

oDir = oFSO.GetFolder(sDir)
For Each i In oDir.Filesf=Fix(i.Path, Find, ReplaceWith)

Next
For Each i In oDir.SubFolders

DoStuff i.Path,Find,ReplaceWithNext
fOut.WriteLine ""'

For Each i In oDir.SubFolders'DoStuff i.Path'

Next

End Sub


domenica 4 ottobre 2009

RDP command Connect to Console session

mstsc 1 -v:server /F -console /admin