20 February 2015

BosoTrigger

BosoTrigger.vbs:
Option Explicit

function sposta()
 
 dim oa
 dim fs
 dim filename

 set oa = WScript.Arguments
 set fs = createObject("Scripting.FileSystemObject")  
 
 filename = oa(0)
 fs.MoveFile filename, "C:\Users\francesco.bosetti\Dropbox\Download\"

 set fs = nothing
 set oa = nothing
 
end function

call sposta

BosoTrigger.bat:
"C:\WINDOWS\SYSTEM32\wscript.exe" "C:\Users\francesco.bosetti\Batch\BosoTrigger.vbs" %1

BosoDoubleClick.vbs

Versione 1:
- simula un "doppio click"
Option Explicit

dim wshShell
dim filePath

if wscript.arguments.count = 0 then
 MsgBox "Bad command or file name.", vbExclamation, wscript.ScriptName
 wscript.quit 
end if

filePath = wscript.arguments.item(0)


Set wshShell = CreateObject("WScript.Shell")

filePath = chr(34) & filePath & chr(34)

wshShell.Run filePath

Set wshShell = nothing

Versione 2:
- in funzione dell'estensione del file, fai cose diverse
- riorganizzazione del codice
Option Explicit
Option Explicit


sub doppioClick(filePath)

    dim wshShell

    Set wshShell = CreateObject("WScript.Shell")
    
    ' -- METTE GLI " SE MANCANO
    if Left(filePath, 1) <> Chr(34) then filePath = Chr(34) & filePath
    if Right(filePath, 1) <> Chr(34) then filePath = filePath & Chr(34)

    wshShell.Run filePath

    Set wshShell = nothing

end sub


function getUserPath()
    
    dim res
    dim wshShell
    
    Set wshShell = CreateObject("WScript.Shell")
    
    res = wshShell.ExpandEnvironmentStrings("%USERPROFILE%")
    
    Set wshShell = nothing

    getUserPath = res
    
end function


sub main()

    dim filePath
    dim fs
    dim s
    dim ext
    
        
    with wscript.arguments
        if .count = 0 then
         MsgBox "Bad command or file name.", vbExclamation, wscript.ScriptName
         wscript.quit
        end if

        filePath = .item(0)
    end with
    
    
    set fs = CreateObject("Scripting.FileSystemObject")
    ext = fs.GetExtensionName(filePath)


    select case LCase(ext)
        case "md", "markdown", "mdown", "mdwn", "mkd", "mkdn"
            s = chr(34) & getUserPath & "\Batch\OpenWithMdWiki.bat" & chr(34) & " " & chr(34) & filePath & chr(34)
            doppioClick s
            
        case else
            doppioClick filePath
       
    end select

end sub


main()

09 February 2015

When/Who did Auto Grow for the Database?

To test the script, you can created a dummy database, insert some rows so that auto growth is caused. Then check the report.

CREATE DATABASE [SQLAuth]
GO
ALTER DATABASE [SQLAuth] SET RECOVERY FULL
GO
BACKUP DATABASE [SQLAuth] TO DISK = 'NUL'
GO
USE [SQLAuth]
GO
CREATE TABLE PinalDave (Pinal INT ,Dave CHAR(8000))
GO
SET NOCOUNT ON
GO

DECLARE @i INT
SET @i = 1

WHILE @i < 10000
    BEGIN
        INSERT INTO PinalDave
        VALUES (1,'Pinal Dave')
        SET @i = @i + 1
    END
Here is the script to get the auto grow events which happened of database “SQLAuth”. Please change it as per database name in your environment
DECLARE @current_tracefilename VARCHAR(500);
DECLARE @0_tracefilename VARCHAR(500);
DECLARE @indx INT;
DECLARE @database_name SYSNAME;

SET @database_name = 'SQLAuth'

SELECT @current_tracefilename = path
FROM   sys.traces
WHERE  is_default = 1;

SET @current_tracefilename = REVERSE(@current_tracefilename);
SELECT @indx = PATINDEX('%\%', @current_tracefilename);
SET @current_tracefilename = REVERSE(@current_tracefilename);
SET @0_tracefilename = LEFT(@current_tracefilename, 
                       LEN(@current_tracefilename) - @indx) + '\log.trc';

SELECT  DatabaseName
       ,Filename
       ,(Duration / 1000) AS 'TimeTaken(ms)'
       ,StartTime
       ,EndTime
       ,(IntegerData * 8.0 / 1024) AS 'ChangeInSize MB'
       ,ApplicationName
       ,HostName
       ,LoginName
FROM   ::fn_trace_gettable(@0_tracefilename, DEFAULT) t
       LEFT JOIN sys.databases AS d 
           ON (d.NAME = @database_name)
WHERE  EventClass >= 92
   AND EventClass <= 95
   AND ServerName = @@servername
   AND DatabaseName = @database_name
   AND (d.create_date < EndTime)
ORDER BY t.StartTime DESC;
Trovato qui.