Užitečné funkce

Zde jsou nejrůznější užitečné funkce zejména pro VBScript. Bez jakéhokoli řazení, tak jak jsem je napsal, tak jsou tady uloženy :-)

function getDNParam(aData,aParam)
cParamPos=InStr(aData,aParam&":")
if cParamPos>0 then
cParamEnd=InStr(cParamPos,aData,";")
if cParamEnd>0 then
getDNParam=Mid(aData,cParamPos+Len(aParam)+1,cParamEnd-(cParamPos+Len(aParam)+1))
end if
end if
end function

Function GetHTTPFile(strURL)
Dim objXML
Dim strHTTPResponse
Set objXML = CreateObject("Msxml2.ServerXMLHTTP.6.0")
objXML.setTimeouts 10000, 10000, 10000, 120000
Call objXML.Open("GET", strURL, False)
Call objXML.Send()
strHTTPResponse = objXML.responseText
Set objXML = Nothing
GetHTTPFile = strHTTPResponse
End Function

Function AlmostUniqueID()
Randomize
for iCtr = 1 to 10
sChar = Chr(Int((90 - 65 + 1) * Rnd) + 65)
sID = sID & sChar
Next
sID = sID & Month(Now) & Day(Now) & Year(Now) & Hour(Now) _
& Minute(Now) & Second(Now)
AlmostUniqueID = sID
End Function

function CurrentDir
Set WshShell = CreateObject("WScript.Shell")
CurrentDir = WshShell.CurrentDirectory
Set WshShell = Nothing
end function

function localComputerName
Set WshNetwork = CreateObject("WScript.Network")
localComputerName=WshNetwork.ComputerName
Set WshNetwork = nothing
end function

function localComputerDescription
HKLM = &H80000002
key = "SYSTEM\CurrentControlSet\Services\LanmanServer\Parameters"
ValueName = "srvcomment"
Set reg = GetObject("winmgmts:\\.\root\default:StdRegProv")
reg.GetStringValue HKLM, key, ValueName, value
if VarType(value) = vbNull Then value = "[empty]"
localComputerDescription=value
Set reg = nothing
end function

function getParam(aI,aT)
DIM tA
tA=Split(aT&" "," ")
if aI<=UBOUND(tA) then getParam=tA(aI-1) else getParam="" end if end function function ReadAndDeleteFirstLineFromFile(aFileName) set cFSO=CreateObject("Scripting.FileSystemObject") set cFile=cFSO.OpenTextFile(aFileName, 1, false) if not cFile.AtEndOfStream then ReadAndDeleteFirstLineFromFile=cFile.ReadLine set cNewFile=cFSO.CreateTextFile(aFileName&".new", 1, false) while not cFile.AtEndOfStream cNewFile.WriteLine cFile.ReadLine wend cNewFile.Close : set setNewFile = Nothing cFile.close : set cFile=Nothing cFSO.DeleteFile aFileName cFSO.MoveFile aFileName&".new",aFileName else cFile.close : set cFile=Nothing ReadAndDeleteFirstLineFromFile="" end if set cFSO=Nothing end function

Napsat komentář

Vaše e-mailová adresa nebude zveřejněna. Vyžadované informace jsou označeny *

*