20 February 2015

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()