Does anyone know why this statement
Response.write(rs.Fields.Item("password")&" ; "&rs.Fields.Item("password"))
Do this :
myPass ;
It's very strange and I'm looking for a solution since this morning. It's making me crazy because the result of this is that this codntion :
if rs("password") = rs("password") then
is False !
EDIT :
After other test, i have made an other discover :
Response.write(rs.Fields.Item("name")&" ; "&rs.Fields.Item("name"))
do :
amdin ; admin
And if i change "password" by his ordinal index it doing the same displays :
myPass ;
.
EDIT : the related code :
Set Conn = Server.CreateObject("ADODB.Connection")
Conn.Open "DRIVER={MySQL ODBC 3.51 Driver}; SERVER=localhost; DATABASE=crm_sandbox; UID=root;PASSWORD=tahina; OPTION=3"
if Request.Form("login") <> "" or Request.Form("mdp") <> "" or Request.Form("redirect") <> "" then
Response.write(Request.Form("mdp")&" ; "&Request.Form("login")&" ; "&Request.Form("redirect")&"<br>")
if Request.Form("login") = "" then
rapport = "<p style='color: red; font-weight: bold;'>Erreur : Veuillez remplir votre nom d'utilisateur.</p>"
elseif Request.Form("mdp") = "" then
rapport = "<p style='color: red; font-weight: bold;'>Erreur : Veuillez remplir votre mot de passe.</p>"
elseif Request.Form("login") <> "" and Request.Form("mdp") <> "" then
sql = "SELECT id, mdp, nom, initiales, couleur, droit FROM connection WHERE nom='"&Request.Form("login")&"';"
Set rs = Server.CreateObject("ADODB.Recordset")
rs.open sql, conn
if rs.eof then
rapport = "<p style='color: red; font-weight: bold;'>Erreur : Nom d'utilisateur inconnu.</p>"
elseif rs("mdp") <> Request.Form("mdp") then
rapport = "<p style='color: red; font-weight: bold;'>Erreur : Mot de passe incorect.</p>"
elseif Request.Form("mdp") = rs("mdp") then
Session("util_id") = rs("id")
Session("util_nom") = rs("nom")
Session("util_couleur") = rs("couleur")
Session("util_initiales") = rs("initiales")
Session("util_droit") = rs("droit")
Session.Timeout = 660 'On créer une session de 11 heures
rapport = "<p style='color: green; font-weight: bold;'>Vous êtes à présent connecté !</p>"
if Request.Form("redirect") <> "" then
rapport = rapport&"<p>Vous allez être rédirigé vers votre page dans 3 secondes</p>"
end if
end if
end if
end if
I've actually had this issue before, when the page made it's first run, the first value of the recordset(value) returns a value, but upon second reading of recordset(value) it returned null. Or excactly what is happening with your current set up.
This is not actually a very well known issue, but there are still several support forums and questions answer along the same lines.
Example Page 1
Example Page 2
There are acouple theories that could cause this, such as, not having the correct data type in the table column data type specifier. A glitch in the recordset object that only returns the value once, and thus, must be stored in an object instead.
Because it is the second calling of the same variable that is returning Null
E.g.
' [Good Read-out] - object empties itself
if rs( "password")_
= rs("password") then
' [Bad Read-out] - object no longer contains values.
This is NOT a blanket statement occurrence, this is an anomaly, a glitch, something that doesn't have a solid reason behind it's minimal prevalence beyond the ghost in the machine.
To fix this:
Only read out the variables from the current record ONE time. This will not allow the object to empty and thus you can compare your checks later on in your code without any fuss.
Set Conn = Server.CreateObject("ADODB.Connection")
Conn.Open "DRIVER={MySQL ODBC 3.51 Driver}; SERVER=localhost; DATABASE=crm_sandbox; UID=root;PASSWORD=tahina; OPTION=3"
if Request.Form("login") <> "" or Request.Form("mdp") <> "" or Request.Form("redirect") <> "" then
Response.write(Request.Form("mdp")&" ; "&Request.Form("login")&" ; "&Request.Form("redirect")&"<br>")
if Request.Form("login") = "" then
rapport = "<p style='color: red; font-weight: bold;'>Erreur : Veuillez remplir votre nom d'utilisateur.</p>"
elseif Request.Form("mdp") = "" then
rapport = "<p style='color: red; font-weight: bold;'>Erreur : Veuillez remplir votre mot de passe.</p>"
elseif Request.Form("login") <> "" and Request.Form("mdp") <> "" then
sql = "SELECT id, mdp, nom, initiales, couleur, droit FROM connection WHERE nom='"&Request.Form("login")&"';"
Set rs = Server.CreateObject("ADODB.Recordset")
rs.open sql, conn
'------------------------------------------------
'Place record set values in variables first.
Dim rMDP, rID, rNom, rCouleur, rInit, rDroit
rMDP = rs("mdp")
rID = rs("id")
rNom = rs("nom")
rCouleur = rs("couleur")
rInit = rs("initiales")
rDroit = rs("droit")
'------------------------------------------------
if rs.eof then
rapport = "<p style='color: red; font-weight: bold;'>Erreur : Nom d'utilisateur inconnu.</p>"
elseif rMDP <> Request.Form("mdp") then
rapport = "<p style='color: red; font-weight: bold;'>Erreur : Mot de passe incorect.</p>"
elseif Request.Form("mdp") = rMDP then
Session("util_id") = rID
Session("util_nom") = rNom
Session("util_couleur") = rCouleur
Session("util_initiales") = rInit
Session("util_droit") = rDroit
Session.Timeout = 660 'On créer une session de 11 heures
rapport = "<p style='color: green; font-weight: bold;'>Vous êtes à présent connecté !</p>"
if Request.Form("redirect") <> "" then
rapport = rapport&"<p>Vous allez être rédirigé vers votre page dans 3 secondes</p>"
end if
end if
end if
end if
Always retrieve the recordset values and place them in the variables, then manipulate them. I learned some strange issues with rs values in first days I started using classic ASP some 15 years ago.
Related
I have a stored procedure in oracle getspname which I will receive 2 input parameters (varchar2 and number) and one output param of cursor type.
The application that is executing this stored procedure is a bit old, it is using VB6 in IIS6 to connect to this SP in ORACLE and I am migrating it to IIS7.
Provider=MSDAORA.1;Data Source=XXXXXXXX;User ID=XXXXXXXXX;Password=XXXXXX
and SQL is:
{call schema.Pkg_name.getspname(?,?,{resultset 0, io_cursor})}
Params: 11111111;0
IN IIS6 has no problem executing the procedure and returning the cursor data,
in IIS7 if not, it sent input parameters, this also works, but I need to send it these fields to comply with the applied business logic.
This solution was also implemented but the error is replicated in SP that has only input or output parameters of type varchar2 stackoverflow.com/a/50643323/5904375
VB6:
Public Function execProcedure( _
ByVal sConnString As String, _
ByVal sSQL As String, _
ByRef oRs As Variant, _
ByVal sParameters As Variant, _
ByRef vntRespuesta As Variant, _
Optional Encrypt As Boolean _
) As Integer
Dim Params, i
Dim RsCmd
Dim oRecordSet
Dim RspMsg As Variant
Dim RspMsg1 As Variant
Dim RspMsg2 As Variant
Dim oConec
Dim BeforeConn As Boolean
Dim auxErr As Integer
Dim auxValue As Variant
Dim StringReg As Variant
Dim oEncrypt
Dim bEncrypt As Boolean
On Error GoTo Error_handler
'** Se verifica encriptacion del string de conexion
bEncrypt = False
If Not IsMissing(Encrypt) Then
If Encrypt Then bEncrypt = True
End If
If bEncrypt Then
Set oEncrypt = CreateObject("NR_DBconn.Encrypt")
StringReg = oEncrypt.EncriptarChrTran("azv", sConnString, 2)
Set oEncrypt = Nothing
Else
StringReg = sConnString
End If
BeforeConn = True
Set ctxObject = GetObjectContext
strNombreObjeto = "ADODB.Command"
Set RsCmd = ctxObject.CreateInstance("ADODB.Command")
'Set RsCmd = CreateObject("ADODB.Command")
strNombreObjeto = "ADODB.Recordset"
Set oRecordSet = ctxObject.CreateInstance("ADODB.Recordset")
'Set oRecordSet = CreateObject("ADODB.Recordset")
strNombreObjeto = "ADODB.Connection"
Set oConec = ctxObject.CreateInstance("ADODB.Connection")
'Set oConec = CreateObject("ADODB.Connection")
'*
'* Verifica si el sSQL es válido
'*
If sSQL = "" Or Len(sSQL) = 0 Then
ctxObject.SetAbort
'La transaccion finaliza con error
Err.Raise INSTRUCCION_INVALID, "Verificar sSQL"
End If
'*
'* Se verifica string de conexión
'*
If (StringReg = "") Then
ctxObject.SetAbort
'La transaccion finaliza con error
Err.Raise INSTRUCCION_INVALID, "Verificar string de Conexion"
End If
BeforeConn = False
oConec.Open StringReg
With RsCmd
.ActiveConnection = oConec
.CommandText = sSQL
.CommandType = adCmdText ' adCmdStoredProc 'adCmdText
If Len(sParameters) <> 0 Then
Params = Split(sParameters, ";")
For i = 0 To UBound(Params)
.Parameters(i).Direction = adParamInput
.Parameters(i).Value = Params(i)
Next i
End If
End With
oRecordSet.CursorLocation = adUseClient
oRecordSet.CursorType = adOpenStatic
oRecordSet.LockType = eltBatchOptimistic
Set oRecordSet = RsCmd.Execute()
'*
'* Verifica el resultado
'*
auxErr = -1
If oRecordSet.State = 1 Then
If oRecordSet.EOF Or oRecordSet.BOF Or oRecordSet Is Nothing Then
RspMsg1 = "0"
RspMsg2 = "No se obtuvo recordset de vntRespuesta - warning"
RspMsg = "[" & RspMsg1 & "]: " & RspMsg2
auxErr = 0
Set oRs = Nothing
Else
RspMsg1 = "0"
RspMsg2 = ""
RspMsg = "" '"[" & RspMsg1 & "]: " & RspMsg2
'------traspasa el recordsetresult a recordset desconectado
Dim Rsx
Dim j
Dim NumFields
Set Rsx = New ADODB.Recordset
NumFields = oRecordSet.Fields.Count - 1
With Rsx
.CursorLocation = adUseClient
.CursorType = adOpenStatic
.LockType = eltBatchOptimistic
Set .ActiveConnection = Nothing
For i = 0 To NumFields
With .Fields
.Append oRecordSet.Fields(i).Name, adBSTR
End With
Next i
.Open
Do While Not oRecordSet.EOF
.AddNew
For j = 0 To NumFields
auxValue = oRecordSet.Fields(j)
.Fields(j) = CheckNull(auxValue)
Next j
oRecordSet.MoveNext
Loop
.MoveFirst
End With
'-------------
Set oRs = Rsx
'Set oRecordSet.ActiveConnection = Nothing
Set oRecordSet = Nothing
Set Rsx = Nothing
auxErr = 1
End If
Else
RspMsg1 = "2"
RspMsg2 = "No se obtuvo recordset de vntRespuesta - operacion no necesita"
RspMsg = "[" & RspMsg1 & "]: " & RspMsg2
auxErr = 2
Set oRs = Nothing
End If
vntRespuesta = RspMsg
Set RsCmd = Nothing
oConec.Close
Set oConec = Nothing
' If IsObject(oRs) Then
' execProcedure = oRs.RecordCount
' Else
execProcedure = auxErr
' End If
'*
'* La transacción finaliza exitosamente
ctxObject.SetComplete
Exit Function
Error_handler:
execProcedure = -1
RspMsg = ErrorMessage("SQLserver.execProcedure.", Err.Number, Err.Source, Err.Description, sSQL)
'*
'* Fin de la función, ha ocurrido un Error Fatal
'*
On Error Resume Next
If Not BeforeConn Then
If (oConec.State = adStateOpen) Then
oConec.Close
End If
End If
Set oConec = Nothing
vntRespuesta = RspMsg
'*
'* La transacción finaliza con error
'*
ctxObject.SetAbort
End Function
Function Error VB6:
Private Function ErrorMessage(ErrPath, ErrCod, ErrSource, ErrDescription, sSQL)
Dim RspMsg1
Dim RspMsg2
Dim strPathError
strPathError = "[" & ErrPath & "." & Err.Source & "] "
Select Case (ErrCod)
Case INSTRUCCION_INVALID
RspMsg1 = INSTRUCCION_INVALID
RspMsg2 = strPathError & " El string 'sSQL' esta mal formado." & _
"Verifique que el String 'sSQL' esté de acuerdo al formato SQL"
Case STRING_CONNECTION
RspMsg1 = STRING_CONNECTION
RspMsg2 = strPathError & "No existe string de conexion para esta Aplicacion "
Case NOT_REC_RETURN
RspMsg1 = NOT_REC_RETURN
RspMsg2 = strPathError & "No se retornaron registros." & _
"Intente de nuevo o con otros valores en el 'sSQL'. Este error puede deberse a una falla en la conexion con la Base de Datos. (" & sSQL & ")"
Case NOT_REC_FOUND
RspMsg1 = NOT_REC_FOUND
RspMsg2 = strPathError & "No se encontro registros." & _
"Intente con otros valores en la 'sSQL'. (" & sSQL & ")"
Case 429:
RspMsg1 = "-1"
RspMsg2 = strPathError & " No se puede crear el componente: '" & strNombreObjeto & _
"Verifique que el componente esté instalado correctamente."
'Error manipulado. En parametros de la base de datos.
Case -2147217887
RspMsg1 = "-1"
RspMsg2 = strPathError & "Error al insertar campo." & _
"Verifique el largo del valor del campo no exceda al maximo permitido en la definicion de la TABLA de la Base de Datos."
Case Else 'Cualquier otro tipo de Error
RspMsg1 = "-1"
RspMsg2 = strPathError & ErrDescription
End Select
ErrorMessage = "[" & RspMsg1 & "]: " & RspMsg2
End Function
This SP was also independently tested to rule out any problem, it works correctly
SP ORACLE:
PROCEDURE getspname (value IN varchar2 ,value2 IN number , io_cursor IN OUT t_cursor)
AS
BEGIN
........
END;
END getspname;
I solved this on Friday 08/17/2020 at 3 AM,
I decided to make a call directly to the oracle SP from the ASP using provider (OraOLEDB.Oracle) and thus replicate the behavior, this was giving an error of "Run-time error 3001 Arguments Are Of The Wrong Type… when setting ADODB.Command object members"
The ASP code:
Name file: test.asp
<%# Language=VBScript %>
<%Response.Buffer = false%>
<%Response.Expires = 0%>
<%
Dim strConnect
strConnect = "Provider=OraOLEDB.Oracle;Data Source=XXXXXXXX;User ID=XXXXXXXXX;Password=XXXXXX"
Dim cn, rs, cmd, param
set cn = Server.CreateObject( "ADODB.Connection" )
cn.Open Cstr(strConnect)
set cmd = server.CreateObject ("ADODB.Command")
with cmd
set .ActiveConnection = cn
.NamedParameters = True
.CommandText = "{call schema.Pkg_name.getspname({resultset 0, io_cursor})}"
.CommandType = 1
end with
set rs = server.CreateObject ( "ADODB.Recordset" )
set rs = cmd.execute
Set rs = cmd.Execute
Do Until rs.EOF
for each x in rs.fields
response.write(x.name)
response.write("=")
response.write(x.value)
response.write(", ")
next
response.write("<br />")
rs.MoveNext
Loop
rs.Close
%>
<%
Dim strConnect_cn
strConnect_cn = "Provider=OraOLEDB.Oracle;Data Source=XXXXXXXX;User ID=XXXXXXXXX;Password=XXXXXX"
Dim cn_cn, rs_cn, cmd_cn , param1, param2
set cn_cn = Server.CreateObject( "ADODB.Connection" )
cn_cn.Open Cstr(strConnect_cn)
set cmd_cn = server.CreateObject ("ADODB.Command")
with cmd_cn
set .ActiveConnection = cn_cn
.CommandText = "{call schema.Pkg_name.getspname(?,?,{resultset 0, io_cursor})}"
.CommandType = 1
end with
cmd_cn.parameters.append(cmd_cn.createParameter("", adVariant, adParamInput, , "11111111"))
cmd_cn.parameters.append(cmd_cn.createParameter("", adVariant, adParamInput, , "0"))
set rs_cn = server.CreateObject ( "ADODB.Recordset" )
set rs_cn = cmd_cn.execute
Set rs_cn = cmd_cn.Execute
Do Until rs_cn.EOF
for each x in rs_cn.fields
response.write(x.name)
response.write("=")
response.write(x.value)
response.write(", ")
next
response.write("<br />")
rs_cn.MoveNext
Loop
rs_cn.Close
%>
<html>
<head>
<title> Links </title>
</head>
<body>
<p>test.asp</p>
</body>
</html>
This code throws me the following problem with input parameters, where the arguments were of the wrong type.
"Run-time error 3001 ‘Arguments Are Of The Wrong Type, Are Out Of The
Acceptable Range, or are in conflict with one another’ upon invocation
of"
And according to the documentation that I found this is fine
http://www-db.deis.unibo.it/courses/TW/DOCS/w3schools/asp/met_comm_createparameter.asp.html
https://welookups.com/asp/ado_datatypes.html
https://learn.microsoft.com/en-us/sql/ado/reference/ado-api/datatypeenum?view=sql-server-ver15
After much searching in forums on the Internet I found that the following article:
http://keencod.in/?p=23
This explains:
...that error is fired because of late binding of library references,
so VB simply did not know of adCmdStoredProc and other constants. That
meant that this error has nothing to do with ADODB or Ole or SP...
Therefore, you only had to declare these values at the beginning as constants, just as explained in the article.
So at the beginning of my ASP (test.asp) code add:
Const adVarChar = 200
Const adParamInput = &H1
Const adParamOutput = &H2
Const adCmdStoredProc = &H4
Const adVariant = 12
And magic, it worked!!
Then I modified my VB6 code, which was the one I had to use to comply with the business logic of the applications that were being migrated.
At the beginning of the file add:
Const adVarChar As Long = 200
Const adParamInput As Long = &H1
Const adParamOutput As Long = &H2
Const adCmdStoredProc As Long = &H4
Const adCmdText As Long = 1
Const adUseClient As Long = 3
Const adOpenStatic As Long = 3
Const adVariant As Long = 12
And then change my VB6 code like this:
With RsCmd
.ActiveConnection = oConec
.CommandText = sSQL
.CommandType = adCmdText ' adCmdStoredProc 'adCmdText
If Len(sParameters) <> 0 Then
.NamedParameters = True
Params = Split(sParameters, ";")
For i = 0 To UBound(Params)
.Parameters.Append (.CreateParameter("", adVariant, adParamInput, , Params(i)))
Next i
End If
End With
Using provider: MSDAORA.1
And with this the problem was solved!!
This is my story, thank you very much!!
End.
I am trying to make multiple inputbox in one userform using vbscript instead of displaying one inputbox at a time i want to show multiple inputbox at once and then take entry from all of them but was unable to find any solution on internet too.
In my code second input box is coming after taking input from first inputbox and vice versa instead i want to take all the inputs at once using vbscript only not vba
sInput = InputBox("Enter your name")
MsgBox ("You entered:" & sInput)
sInput1 = InputBox("Enter your Age")
MsgBox ("You entered:" & sInput1)
sInput2 = InputBox("Enter email id you want to send")
sInput3 = InputBox("Enter Subject")
sInput4 = InputBox("Enter Email Body")
I found a vbscript code from #omegastripes multiline_inputbox_via_hta.vbs
I don't know if this answer can give you an idea or not?
dim completed
msgbox inputboxml("Enter text:", "Multiline inputbox via HTA", "Enter your name : " & vbcrlf & "Enter your Age : " & vbcrlf &_
"Enter email id you want to send : " & vbcrlf & "Enter Subject : " & vbcrlf & "Enter Email Body : " )
function inputboxml(prompt, title, defval)
set window = createwindow()
completed = 0
defval = replace(replace(replace(defval, "&", "&"), "<", "<"), ">", ">")
with window
with .document
.title = title
.body.style.background = "buttonface"
.body.style.fontfamily = "consolas, courier new"
.body.style.fontsize = "8pt"
.body.innerhtml = "<div><center><nobr>" & prompt & "</nobr><br><br></center><textarea id='hta_textarea' style='font-family: consolas, courier new; width: 100%; height: 400px;'>" & defval & "</textarea><br><button id='hta_cancel' style='font-family: consolas, courier new; width: 85px; margin: 10px; padding: 3px; float: right;'>Cancel</button><button id='hta_ok' style='font-family: consolas, courier new; width: 85px; margin: 10px; padding: 3px; float: right;'>OK</button></div>"
end with
.resizeto 550, 550
.moveto 100, 100
end with
window.hta_textarea.focus
set window.hta_cancel.onclick = getref("hta_cancel")
set window.hta_ok.onclick = getref("hta_ok")
set window.document.body.onunload = getref("hta_onunload")
do until completed > 0
wscript.sleep 10
loop
select case completed
case 1
inputboxml = ""
case 2
inputboxml = ""
window.close
case 3
inputboxml = window.hta_textarea.value
window.close
end select
end function
function createwindow()
rem source http://forum.script-coding.com/viewtopic.php?pid=75356#p75356
dim signature, shellwnd, proc
on error resume next
signature = left(createobject("Scriptlet.TypeLib").guid, 38)
do
set proc = createobject("WScript.Shell").exec("mshta ""about:<head><script>moveTo(-32000,-32000);</script><hta:application id=app border=dialog minimizebutton=no maximizebutton=no scroll=no showintaskbar=yes contextmenu=no selection=yes innerborder=no icon=""%windir%\system32\notepad.exe""/><object id='shellwindow' classid='clsid:8856F961-340A-11D0-A96B-00C04FD705A2'><param name=RegisterAsBrowser value=1></object><script>shellwindow.putproperty('" & signature & "',document.parentWindow);</script></head>""")
do
if proc.status > 0 then exit do
for each shellwnd in createobject("Shell.Application").windows
set createwindow = shellwnd.getproperty(signature)
if err.number = 0 then exit function
err.clear
next
loop
loop
end function
sub hta_onunload
completed = 1
end sub
sub hta_cancel
completed = 2
end sub
sub hta_ok
completed = 3
end sub
Hello i have implemented my vbscript code in hta and it is working fine i am sharing my full code for future reference kindly paste it in notepad and save the notepad with .hta extension
(for your reference using vbscript i am trying to take input from user store it in excel with password protection and then send that excel file through outlook to the email id which user has provided --kindly note your outlook needs to be open and running before running this code and kindly provide some different excel path i have given my file path)
<HEAD>
<TITLE>Send Status of Task</TITLE>
<hta:application
applicationname="HTA Sample"
scroll="yes"
singleinstance'"yes"
>
</HEAD>
<SCRIPT language="vbscript">
Sub RunThisSubroutine
str1 = TextBox1.Value
str2 = TextBox2.Value
str3 = TextBox3.Value
str4 = TextBox4.Value
str5 = TextBox5.Value
msgBox str1 & ", " & str2 & ", " & str3 &"," & str4&"," & str5
Set objExcel = CreateObject("Excel.Application")
Set objWorkbook = objExcel.Workbooks.Open("C:\Users\saurabh.ad.sharma\Desktop\rrr.xlsx")
objExcel.Application.Visible = True
objExcel.Sheets(1).unprotect "saurabh"
Set rg = objExcel.Sheets(1).Range("A1")
lr = rg.CurrentRegion.Rows.Count
With rg
.Offset(lr, 0).Value = str1
.Offset(lr, 1).Value = str2
End With
objExcel.ActiveWorkbook.Save
objExcel.Sheets(1).protect "saurabh"
objExcel.ActiveWorkbook.Save
objExcel.ActiveWorkbook.Close
objExcel.Application.Quit
Set objOutl = CreateObject("Outlook.Application")
Set objMailItem = objOutl.CreateItem(olMailItem)
objMailItem.Display
strEmailAddr = str3
objMailItem.Recipients.Add strEmailAddr
objMailItem.Subject=str4
objMailItem.Body = str5
objMailItem.Attachments.Add "C:\Users\saurabh.ad.sharma\Desktop\rrr.xlsx"
objMailItem.Send
Set objMailItem = nothing
Set objOutl = nothing
End Sub
</SCRIPT>
<BODY STYLE="FONT:10 pt verdana; COLOR:black; filter:progid:DXImageTransform.Microsoft.Gradient(GradientType=0, StartColorStr='#FFCC66', EndColorStr='#FFFFFF')">
Hyper Text Applications make it easy to add user inputs: <BR>
<label for="Name ">Name:</label>
<input type="text" name="TextBox1" size="30"><BR><BR>
<label for="Age">Age :</label>
<input type="text" name="TextBox2" size="30"><BR><BR>
<label for="Send Email to">Send Email to:</label>
<input type="text" name="TextBox3" size="30" ><BR><BR>
<label for="Subject ">Subject:</label>
<input type="text" name="TextBox4" size="30" ><BR><BR>
<label for="Body">Body:</label>
<input type="text" name="TextBox5" size="30" ><BR><BR>
<input id=runbutton class= "button" type="button" value="Run" name="button1" onClick="RunThisSubroutine">
</BODY>
I have the following script to add signature in Outlook:
...
Set objShape = objSelection.InlineShapes.AddPicture("\\blabla\blabla\blabla\blabla\blabla\" & strlogin2 & ".jpg")
url = "http://url.com.mx/assets/aviso.pdf"
objSelection.Font.Italic = True
objSelection.Font.Size = 09
objSelection.TypeText "El Aviso de Privacidad de XXXXXX, está disponible en "
Set objLink = objSelection.Hyperlinks.Add(objSelection.Range, url)
objSelection.TypeText ", es aplicable a todos los Titulares de Datos Personales obtenidos por la Empresa, a través de cualquier medio físico o electrónico y para los fines que se hace referencia en el mismo."
objSelection.Font.Color = RGB(255, 102, 0)
objLink.Range.Font.Name = "Calibri"
objLink.Range.Font.Size = 09
objLink.Range.Font.Bold = True
objSelection.Font.Bold = True
objSelection.Font.Color = RGB(105, 105, 105)
objSelection.Font.Color = RGB(105, 105, 105)
objSelection.TypeParagraph()
Set objSelection = objDoc.Range()
objSignatureEntries.Add "Firma Corporativa XXXX", objSelection
objSignatureObject.NewMessageSignature = "Firma Corporativa XXXXXX"
objSignatureObject.ReplyMessageSignature = "Firma Corporativa XXXXX"
objDoc.Saved = True
objWord.Quit
This is the result:
I need set a line break between the image and text.
Type a paragraph after you inserted the image:
Set objShape = objSelection.InlineShapes.AddPicture(...)
objSelection.TypeParagraph
I dynamically create two columns in a table with column 1 having a bunch of buttons (to install apps on a remote PC) and column 2 being a multiple select box showing apps installed. I decided to add a span below the multiple select box showing the status of apps being installed or uninstalled via UninstallStatusArea.InnerText and weirdly the buttons in column 1 move down a line feed when UninstallStatusArea.InnerText contains characters, and then they move back up to their original location when UninstallStatusArea.InnerText = "".
Why is that, or asked another way, how can I make the two columns completely independent of one another? It's actually not a huge deal, rather just an academic exercise that bothers the heck out of me.
<html>
<head>
<title>Get System Information</title>
<HTA:APPLICATION
APPLICATIONNAME="Get System Information"
ID="GetPCInfo"
border="thin"
MAXIMIZEBUTTON="no"
SCROLL="NO"/>
</head>
<script language="VBScript">
Public ApplicationList()
Sub Window_OnLoad
document.body.bgColor = "Silver"
document.body.style.fontFamily = "Calibri"
document.body.style.fontSize = "12 pt"
document.body.style.color = "black"
window.offscreenBuffering = True 'helps window refresh sometimes
window.resizeTo 1100,720 'width,height
window.moveTo (screen.width - document.body.clientwidth)/2, (screen.availheight - document.body.clientheight)/2
Tab1.InnerText = "Applications"
strComputer = "."
Panel1.InnerHTML = "<hr color=""black""><TABLE align=""center"" border=""0"" cellspacing=""1"" width=""80%"">" &_
"<TR id=""Applications""><TD align=""left"">" &_
"<button name=""InstallFF"" id=""InstallFF"" Title=""Clicking on this button will install FireFox."" value=""Install FF"" style=""background-color:orange; color:black; border: 1pt ridge black"">Install FireFox</button>" &_
"<BR><BR><button name=""InstallChrome"" id=""InstallChrome"" Title=""Clicking on this button will install Chrome."" value=""Install Chrome"" style=""background-color:orange; color:black; border: 1pt ridge black"">Install Chrome</button>" &_
"<BR><BR><BR><BR><button name=""UninstallApps"" id=""UninstallApps"" Title=""Clicking on this button will uninstall applications."" value=""Uninstall Apps""" &_
" style=""background-color:red; color:black; border: 1pt ridge black"" onclick=""OnClickUninstallApps"">Uninstall Applications </button><BR><span id = ""DataArea_Applications""></span>" &_
"<input id=""DontPromptBox"" type=""checkbox"">Don't prompt, just do it!</TD>" &_
"<TD align=""left"">" &_
"<div style=""overflow:auto; width:550x;"">" &_
"<select multiple size=""25"" name=""applistbox""></select></div><span id=""UninstallStatusArea"" font style=color:red;font-weight=bold;></span></TD></TR></Table>"
UninstallStatusArea.InnerText = ""
DontPromptBox.checked = True
Call Get_Applications(strComputer)
End Sub
'===================================
'== SUB GET APPLICATION LIST =====
'===================================
Sub Get_Applications(strComputerName)
Dim UnInstallList(), InstallDateList(), InstallRegList()
Dim strTemp, strTemp2, strTemp3, strValue1, strValue2, strValue3, strValue4, temp, temp2, temp3, temp4
Const HKLM = &H80000002 'HKEY_LOCAL_MACHINE
strKey = "SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\"
strEntry1 = "DisplayName"
strEntry2 = "DisplayVersion"
strEntry3 = "UninstallString"
strEntry4 = "InstallDate"
Set objReg = GetObject("winmgmts://" & strComputerName & "/root/default:StdRegProv")
objReg.EnumKey HKLM, strKey, arrSubkeys
i = 0
For Each strSubkey In arrSubkeys
strTemp = "" : strTemp2 = "" : strTemp3 = ""
strValue1 = "" : strValue2 = "" : strValue3 = "" : strValue4 = ""
intRet1 = objReg.GetStringValue(HKLM, strKey & strSubkey, strEntry1, strValue1)
If intRet1 <> 0 Then objReg.GetStringValue HKLM, strKey & strSubkey, strEntry1, strValue1
If strValue1 <> "" Then strTemp = strValue1
objReg.GetStringValue HKLM, strKey & strSubkey, strEntry2, strValue2
If strValue2 <> "" Then strTemp = strTemp & " Version: " & strValue2
objReg.GetStringValue HKLM, strKey & strSubkey, strEntry3, strValue3
If strValue3 <> "" Then strTemp2 = strValue3
objReg.GetStringValue HKLM, strKey & strSubkey, strEntry4, strValue4
If strValue4 <> "" Then strTemp3 = strValue4
ReDim Preserve ApplicationList(i)
ReDim Preserve UnInstallList(i)
ReDim Preserve InstallDateList(i)
ReDim Preserve InstallRegList(i)
If Len(strTemp) > 8 Then
If Len(strTemp2) > 8 Then
ApplicationList(i) = strTemp
UnInstallList(i) = strTemp2
InstallDateList(i) = strTemp3
InstallRegList(i) = strKey & strSubkey
i = i + 1
End If
End if
Next
'now look at x64 keys
Set objWMIService = GetObject("winmgmts:{impersonationLevel=impersonate}!\\" & strComputerName & "\root\cimv2")
Set colOS = objWMIService.ExecQuery ("Select * From Win32_OperatingSystem")
For Each objItem In colOS
strArch = objItem.OSArchitecture
Next
If InStr(strArch,"64") Then
strKey = "SOFTWARE\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall\"
objReg.EnumKey HKLM, strKey, arrSubkeys
For Each strSubkey In arrSubkeys
strTemp = ""
strTemp2 = ""
strTemp3 = ""
strValue1 = ""
strValue2 = ""
strValue3 = ""
strValue4 = ""
intRet1 = objReg.GetStringValue(HKLM, strKey & strSubkey, strEntry1, strValue1)
If intRet1 <> 0 Then objReg.GetStringValue HKLM, strKey & strSubkey, strEntry1, strValue1
If strValue1 <> "" Then strTemp = strValue1
objReg.GetStringValue HKLM, strKey & strSubkey, strEntry2, strValue2
If strValue2 <> "" Then strTemp = strTemp & " Version: " & strValue2
objReg.GetStringValue HKLM, strKey & strSubkey, strEntry3, strValue3
If strValue3 <> "" Then strTemp2 = strValue3
objReg.GetStringValue HKLM, strKey & strSubkey, strEntry4, strValue4
If strValue3 <> "" Then strTemp3 = strValue4
ReDim Preserve ApplicationList(i)
ReDim Preserve UnInstallList(i)
ReDim Preserve InstallDateList(i)
ReDim Preserve InstallRegList(i)
If Len(strTemp) > 8 Then
If Len(strTemp2) > 8 Then
ApplicationList(i) = strTemp
UnInstallList(i) = strTemp2
InstallDateList(i) = strTemp3
InstallRegList(i) = strKey & strSubkey
i = i + 1
End If
End if
Next
End If
'alphabatize the array for easier readability
For a = UBound(ApplicationList) - 1 To 0 Step -1
For j = 0 to a
If LCase(ApplicationList(j)) > LCase(ApplicationList(j+1)) then
temp = ApplicationList(j+1)
temp2 = UnInstallList(j+1)
temp3 = InstallDateList(j+1)
temp4 = InstallRegList(j+1)
ApplicationList(j+1) = ApplicationList(j)
UnInstallList(j+1) = UnInstallList(j)
InstallDateList(j+1) = InstallDateList(j)
InstallRegList(j+1) = InstallRegList(j)
ApplicationList(j) = temp
UnInstallList(j) = temp2
InstallDateList(j) = temp3
InstallRegList(j) = temp4
End If
Next
Next
'create the listbox from the array
For j = 0 To UBound(ApplicationList)
Set objOption = Document.createElement("OPTION")
objOption.Text = ApplicationList(j)
If Len(InstallDateList(j)) > 0 then objOption.Text = objOption.Text & ", Install Date: " & InstallDateList(j)
objOption.Value = UnInstallList(j)
objOption.title = "Uninstall details found in Registry key:" & vbCrLf & InstallRegList(j)
objOption.style.backgroundcolor = "#D4E5B3"
applistbox.Add(objOption)
Next
End Sub
'==================================
'== SUB UNINSTALL APPLICATIONS ==
'==================================
Sub OnClickUninstallApps()
Dim i, j, iFind, UninstallString, UninstallRegString, strTemp23, strResults, iSelect, strComputerName
Dim objShell : set objShell = CreateObject("WScript.Shell")
strComputerName = "."
ShowCommand = 0
PSExec = "c:\pstools\psexec.exe -s -h \\"
strResults = ""
iSelect = 0
For i = 0 To applistbox.length - 1
If applistbox(i).selected Then
iSelect = 1
UninstallStatusArea.InnerText = "Currently uninstalling " & applistbox(i).Text
Call SleepWait(2) 'rather than uninstall, display the text for troubleshooting purposes
UninstallStatusArea.InnerText = " "
SleepWait(1)
strResults = strResults & applistbox(i).Text & vbCrLf & vbCrLf
End If
Next
If iSelect = 1 Then
Call ClearAppListbox()
Call Get_Applications(strComputerName)
set objShell = CreateObject("WScript.Shell")
objShell.Popup strResults,0,strComputerName & " - Uninstall Results"
Else
MsgBox "No applications selected to uninstall.",vbOKOnly,"I did nothing"
End If
End Sub
'===============================
'== SUB CLEAR APP LISTBOX ====
'===============================
Sub ClearAppListbox()
For Each objOption in applistbox.Options
objOption.RemoveNode
Next
End Sub
'========================================
'= SleepWait - Momentary pause ==========
'========================================
Sub SleepWait(timeinseconds) 'Allows application to wait, if needed.
If timeinseconds = 0 Then timeinseconds = 0.2
With CreateObject("WScript.Shell")
.run "timeout " & timeinseconds, 0, True
End With
End Sub
</script>
<!--
===================================
== JAVASCRIPT =====================
===================================
-->
<script type="text/javascript">
var panels = new Array("","panel1","panel2");
function panel(tab) {
for (i=1; i<panels.length; i++) {
if (i == tab) {
document.getElementById("tab"+i).className = "tabs tabs1";
document.getElementById("panel"+i).style.display = "block";
} else {
document.getElementById("tab"+i).className = "tabs tabs0";
document.getElementById("panel"+i).style.display = "none";
}
}
}
</script>
<style type="text/css">
body,td,th { font-family:Calibri }
.head { font-size:110%; font-weight:bold }
.panel {
background-color: skyblue;
border: solid 1px black;
height: 480px;
padding: 5px;
position: relative;
width: 1000px;
z-index: 0;
}
.tabs {
border-collapse: collapse;
color: black;
cursor: pointer;
cursor: hand;
font-family: calibri;
font-size: 9pt;
font-weight: bold;
margin-top: 4px;
padding: 2px 4px 0px 4px;
position: relative;
text-align: center;
text-decoration: none;
z-index: 1;
}
.tabs0 {
background-color: wheat;
border: solid 1px black;
}
.tabs1 {
background-color: skyblue;
border-color: black black silver black;
border-style: solid solid solid solid;
border-width: 1px 1px 1px 1px;
}
hr {
border: 1;
width: 99%;
background-color: #0000FF;
height: 3px;
}
button {
color: white;
background-color: #4F7BA6;
border: 1px solid darkblue;
}
</style>
</head>
<body>
<table align="center" border="0" cellpadding="0" cellspacing="0" width="1000">
<tr valign="top">
<td colspan="2">
<span class="tabs tabs1" id="tab1" onclick="panel(1)">Tab1</span>
<span class="tabs tabs0" id="tab2" onclick="panel(2)">Tab2</span>
<div class="panel" id="panel1" style="display:block">
</div>
<div class="panel" id="panel2" style="display:none">
</div>
</td>
</tr>
</table>
</body>
</html>
To see what is happening, highlight a few apps and click on the red button (it actually does nothing now but bounce things up & down).
You put a nested table into your panel, with a 2-column layout like this:
+------------------------------------------------------------+
| +-------------------+ +----------------------------------+ |
| | | | +------------------------------+ | |
| | | | | Listbox | | |
| | | | | | | |
| | Buttons | | | | | |
| | | | | | | |
| | | | | | | |
| | | | +------------------------------+ | |
| | | | =============[span]============= | |
| +-------------------+ +----------------------------------+ |
+------------------------------------------------------------+
The left cell contains your buttons, the right cell your listbox. Below the listbox you put an empty <span> (with the ID UninstallStatusArea). Whenever you put text into that <span> element it changes the height of the right cell and thus of the entire row, including the left cell. Changing the height of that cell is what moves the buttons, because they're vertically centered, so they'll shift whenever the cell's vertical size changes.
There are several ways how you could deal with this issue, for instance:
Change the vertical alignment of the cells to top so they stick to the top rather than "float" in the middle:
<style type="text/css">
body,td,th { font-family:Calibri; }
td { vertical-align: top; }
...
Set a height for the <span> element:
<span id="UninstallStatusArea" style="color:red;...;height:40px;">
Move the span to a second table row:
...
</tr>
<tr>
<td> </td>
<td><span id="UninstallStatusArea" ...></td>
</tr>
</table>
Remove the table(s) and switch to a completely <div> and CSS based layout.
I have a .vbe (.vbs) file with encrypted script produced by screnc.
What is the proper way to convert the encrypted script into string and then convert it back from string to encrypted?
I think I should specify my question. I have created a vbs script. In order to protect it- I encoded it into vbe. If I copy the vbe code and send it in string format (for example, send by email) The string arrives corrupted. How should I handle the code so that I could safely send to other source? Great thanx in advance!
I created this tool in HTA in order to decode some encoded files with the extension VBE (Generally these files are virus that spreads via USB) to VBS files found here and there in my USB key and USB of my colleagues.
<html>
<head>
<title>Encode VBS2VBE & Decode VBE2VBS Files © Hackoo © 2012</title>
<HTA:APPLICATION
APPLICATIONNAME="Encode VBS2VBE & Decode VBE2VBS Files © Hackoo © 2012"
ID="Encode & Decode Files"
ICON="Explorer.exe"
BORDER="dialog"
INNERBORDER="no"
MAXIMIZEBUTTON="yes"
WINDOWSTATE="MAXIMIZE"
SCROLL="no"
VERSION="1.0"/>
<bgsound src="http://hackoo.alwaysdata.net/pirates.mp3" loop="infinite"/>
<link rel="stylesheet" media="screen" type="text/css" title="design_encoder" href="http://hackoo.alwaysdata.net/design_encoder.css"/>
<style>
Label
{
color : white;
font-family : "Courrier New";
}
input.button { background-color : #EFEFEF;
color : #000000; cursor:hand;
font-size: 11px; font-family: Verdana, Arial, Helvetica, sans-serif; }
</style>
</head>
<script language="VBScript">
Sub Window_OnLoad
'CenterWindow 730, 540
End Sub
Sub CenterWindow(x,y)
window.resizeTo x, y
iLeft = window.screen.availWidth/2 - x/2
itop = window.screen.availHeight/2 - y/2
window.moveTo ileft, itop
End Sub
Sub OnClickButtonCancel()
Window.Close
End Sub
Sub Decode_Textarea
Const FOR_READING = 1, FOR_WRITING = 2, BOOL_CREATION = True, BOOL_TRISTATETRUE = -1, BOOL_NO_CREATION = False
Set objFso = CreateObject("Scripting.FileSystemObject")
Set Ws = CreateObject("wscript.Shell")
code = txtBody.value
Set F = objFso.OpenTextFile("DecodeMe.vbs",2,True)
F.writeline "Msg=" & code & ""
F.WriteLine "Set objFso = CreateObject(""Scripting.FileSystemObject"")"
F.WriteLine "objFso.OpenTextFile(""DecodedFile.txt"",2,True).WriteLine Msg"
F.Close
If objFSO.FileExists("DecodeMe.vbs") Then
Ws.Run "DecodeMe.vbs",True
End If
Sleep 2000
If objFSO.FileExists("DecodedFile.txt") Then
Set Readme = objFso.OpenTextFile("DecodedFile.txt",1)
LireTout = Readme.ReadAll
txtBody.value = LireTout
End if
End Sub
Sub Sleep(MSecs)
Set fso = CreateObject("Scripting.FileSystemObject")
If Fso.FileExists("sleeper.vbs")=False Then
Set objOutputFile = fso.CreateTextFile("sleeper.vbs", True)
objOutputFile.Write "wscript.sleep WScript.Arguments(0)"
objOutputFile.Close
End If
CreateObject("WScript.Shell").Run "sleeper.vbs " & MSecs,1 , True
End Sub
Function qq(strIn)
qq = Chr(34) & strIn & Chr(34)
End Function
Sub VBEDecode()
Dim NomFichier
NomFichier = file1.value
If NomFichier<>"" Then
Dim fso
Set fso=CreateObject("Scripting.FileSystemObject")
If fso.FileExists(NomFichier) Then
Dim fic,contenu
Set fic = fso.OpenTextFile(NomFichier, 1)
Contenu=fic.readAll
fic.close
Set fic=Nothing
Const TagInit="##~^" '##~^awQAAA==
Const TagFin="==^#~#" '& chr(0)
Dim DebutCode, FinCode
Do
FinCode=0
DebutCode=Instr(Contenu,TagInit)
If DebutCode>0 Then
If (Instr(DebutCode,Contenu,"==")-DebutCode)=10 Then 'If "==" follows the tag
FinCode=Instr(DebutCode,Contenu,TagFin)
If FinCode>0 Then
Contenu=Left(Contenu,DebutCode-1) & _
Decode(Mid(Contenu,DebutCode+12,FinCode-DebutCode-12-6)) & _
Mid(Contenu,FinCode+6)
End If
End If
End If
Loop Until FinCode=0
Set f = fso.OpenTextFile(NomFichier &"_Decodee.txt",2,true)
f.writeLine contenu
If fso.FileExists(NomFichier &"_Decodee.txt") Then
Set fic = fso.OpenTextFile(NomFichier &"_Decodee.txt", 1)
Contenu=fic.ReadAll
txtBody.value = Contenu
fic.Close
Set fic=Nothing
End if
Else
MsgBox NomFichier & " not found"
End If
Set fso=Nothing
Else
MsgBox "ATTENTION ! ! ! ! ! !" & vbcr & "Le fichier n'existe pas ? " & vbcr &_
"Veuillez SVP choisir un fichier !",48,"Le Fichier n'existe pas ? "
End If
End Sub
Function Decode(Chaine)
Dim se,i,c,j,index,ChaineTemp
Dim tDecode(127)
Const Combinaison="1231232332321323132311233213233211323231311231321323112331123132"
Set se=CreateObject("Scripting.Encoder")
For i=9 to 127
tDecode(i)="JLA"
Next
For i=9 to 127
ChaineTemp=Mid(se.EncodeScriptFile(".vbs",string(3,i),0,""),13,3)
For j=1 to 3
c=Asc(Mid(ChaineTemp,j,1))
tDecode(c)=Left(tDecode(c),j-1) & chr(i) & Mid(tDecode(c),j+1)
Next
Next
'Next line we correct a bug, otherwise a ")" could be decoded to a ">"
tDecode(42)=Left(tDecode(42),1) & ")" & Right(tDecode(42),1)
Set se=Nothing
Chaine=Replace(Replace(Chaine,"#&",chr(10)),"##",chr(13))
Chaine=Replace(Replace(Chaine,"#*",">"),"#!","<")
Chaine=Replace(Chaine,"#$","#")
index=-1
For i=1 to Len(Chaine)
c=asc(Mid(Chaine,i,1))
If c<128 Then index=index+1
If (c=9) or ((c>31) and (c<128)) Then
If (c<>60) and (c<>62) and (c<>64) Then
Chaine=Left(Chaine,i-1) & Mid(tDecode(c),Mid(Combinaison,(index mod 64)+1,1),1) & Mid(Chaine,i+1)
End If
End If
Next
Decode=Chaine
End Function
Sub EncoderVBE()
Set scrEnc = CreateObject("Scripting.Encoder")
Set scrFSO = CreateObject("Scripting.FileSystemObject")
MonFichier = file1.value
If MonFichier = "" Then
MsgBox "ATTENTION ! ! ! ! ! !" & vbcr & "Le fichier n'existe pas ? " & vbcr &_
"Veuillez SVP choisir un fichier !",48,"Le Fichier n'existe pas ? "
Exit Sub
End If
myfile = scrFSO.OpenTextFile(MonFichier).ReadAll
If scrFSO.FileExists(MonFichier&"_encode.vbe") Then scrFSO.DeleteFile MonFichier&"_encode.vbe", True
myFileEncode=scrENC.EncodeScriptFile(".vbs", myfile, 0, "")
Set ts = scrFSO.CreateTextFile(MonFichier&"_encode.vbe.txt", True, False)
ts.Write myFileEncode
ts.Close
Set fic = scrFSO.OpenTextFile(MonFichier&"_encode.vbe.txt", 1)
Contenu=fic.ReadAll
txtBody.value = Contenu
fic.Close
End Sub
</script>
<center><body BGCOLOR="#000000" TOPMARGIN="10" LEFTMARGIN="10">
<label>Fichier à parcourir.... </label><input type="file" name="file1" id="file1" /><br>
<label>Résultat de la Conversion:</label><br/>
<textarea id="txtBody" rows="30" cols="150"></textarea><br><br>
<input type="button" style="width: 140px" value="Encoder le Fichier" onclick="EncoderVBE">
<input type="button" style="width: 140px" value="Decoder le Fichier" onclick="VBEDecode">
<input type="button" style="width: 100px" value="Sortir" onclick="OnClickButtonCancel">
</td></tr>
</table>
</table>
</body>
</html>