Dllcall autoit partially getting results - autoit

I am having problem with the following code in autoit.
it is suppose to list all printers available in my system and the curresponding papernames supported by each printer.
but am getting only the printer names ans series of '0s' which is suppose to be the papernames
#include <Debug.au3>
#include <String.au3>
Const $DC_BINS = 6
Const $DC_BINNAMES = 12
Const $DC_PAPERNAMES = 16
Const $DC_PAPERS = 2
Const $DC_PAPERSIZE = 3
Dim $BinNameList
$objWMIService = ObjGet("winmgmts:{impersonationLevel=impersonate}!\\.\root\cimv2")
$colInstalledPrinters = $objWMIService.ExecQuery ("Select Name, PortName from Win32_Printer")
For $objPrinter In $colInstalledPrinters
$result = DllCall("winspool.drv", "long", "DeviceCapabilitiesA", "str", $objPrinter.Name, "str", $objPrinter.PortName, "int", $DC_PAPERS, "str", Chr(0), "long", 0)
$s_struct = ""
_DebugSetup ($s_struct)
$s_struct=_StringRepeat("0", $result[0]*64)
;$s_struct = StringTrimRight($s_struct, 1)
$struct = DllStructCreate($s_struct)
$result2 = DllCall("winspool.drv", "long", "DeviceCapabilitiesA", "str", $objPrinter.Name, "str", $objPrinter.PortName, "int", $DC_PAPERNAMES, "ptr", DllStructGetPtr($struct), "long", 0)
_DebugOut ( $objPrinter.Name)
For $i = 0 To $result[0]-1
_DebugOut (DllStructGetData($struct, $i))
Next
$struct = 0
Next

Check this out: http://msdn.microsoft.com/en-us/library/aa394363(v=vs.85).aspx
Example that uses just WMI:
#include <Array.au3>
$objWMIService = ObjGet("winmgmts:{impersonationLevel=impersonate}!\\.\root\cimv2")
$colInstalledPrinters = $objWMIService.ExecQuery ("Select * from Win32_Printer",Default,48)
For $objPrinter In $colInstalledPrinters
$arr = $objPrinter.PrinterPaperNames
_ArrayDisplay($arr, $objPrinter.Name)
Next
Or try this which prints the actual paper names (run in SciTE so you can see the output from ConsoleWrite):
Const $DC_PAPERS = 2
Const $DC_PAPERSIZE = 3
Const $DC_PAPERNAMES = 16
$objWMIService = ObjGet("winmgmts:{impersonationLevel=impersonate}!\\.\root\cimv2")
$colInstalledPrinters = $objWMIService.ExecQuery ("Select Name, PortName from Win32_Printer")
For $objPrinter In $colInstalledPrinters
$result = DllCall("winspool.drv", "long", "DeviceCapabilitiesA", "str", $objPrinter.Name, "str", $objPrinter.PortName, "int", $DC_PAPERS, "str", Chr(0), "long", 0)
$s_struct = ""
$s_struct2 = ""
For $i = 1 To $result[0]
$s_struct = $s_struct & "char[64];"
Next
For $i = 1 To $result[0]
$s_struct2 &= "long x;long y;"
Next
$s_struct = StringTrimRight($s_struct, 1)
$s_struct2 = StringTrimRight($s_struct2, 1)
$j = 1
$struct = DllStructCreate($s_struct)
$pointStruct = DllStructCreate($s_struct2)
$result2 = DllCall("winspool.drv", "long", "DeviceCapabilitiesA", "str", $objPrinter.Name, "str", $objPrinter.PortName, "int", $DC_PAPERNAMES, "ptr", DllStructGetPtr($struct), "long", 0)
$result3 = DllCall("winspool.drv", "long", "DeviceCapabilitiesA", "str", $objPrinter.Name, "str", $objPrinter.PortName, "int", $DC_PAPERSIZE, "ptr", DllStructGetPtr($pointStruct), "long", 0)
ConsoleWrite($objPrinter.Name & " on Port: " & $objPrinter.PortName & #CRLF)
For $i = 1 To $result[0]
ConsoleWrite(DllStructGetData($struct, $i) & " (" & DllStructGetData($pointStruct, $j) & "mm x " & DllStructGetData($pointStruct, $j + 1) & "mm)" & #CRLF)
$j += 2
Next
$struct = 0
$pointStruct = 0
Next

Related

How to validate Google Recaptcha 2.0 server side in ASP Classic?

I need help to implement the answer Google Recaptcha 2.0.
I've tried a few ways to recover the response after sending the form but not consigui get the answer True.
Follows the example I'm trying:
<%#LANGUAGE=VBSCRIPT%>
<%
Option Explicit
%>
<html>
<head>
<script src="https://www.google.com/recaptcha/api.js" async defer></script>
</head>
<body>
<%
If Request.ServerVariables("REQUEST_METHOD") = "POST" Then
Dim recaptcha_secret, sendstring, objXML
' Secret key
recaptcha_secret = "xxxxxxxxxxsec"
sendstring = "https://www.google.com/recaptcha/api/siteverify?secret=" & recaptcha_secret & "&response=" & Request.form("g-recaptcha-response")
Set objXML = Server.CreateObject("MSXML2.ServerXMLHTTP")
objXML.Open "GET", sendstring, False
objXML.Send
Response.write "<br><h3>Response: " & objXML.responseText & "</h3><br>"
Set objXML = Nothing
END If
%>
<form method="post" action="">
<!-- Site key -->
<div class="g-recaptcha" data-sitekey="xxxxxxxxxx"></div>
<br />
<input type="submit" value="Try">
</form>
</body>
</html>
How do I implement a way to check that Recaptcha were marked?
finally found it after so many search i found it
first i use this asp class https://github.com/zhennanzhuce/js/blob/master/js/ueditor/1.4.3/asp/ASPJson.class.asp
then to validate the response i use this
result = (objXML.responseText)
Set oJSON = New aspJSON
oJSON.loadJSON(result)
Set objXML = Nothing
success = oJSON.data("success")
if success = "True" then
action = "go to next page"
else
action = ""
end if
now the used code is :
<%#LANGUAGE=VBSCRIPT%>
<%
Option Explicit
%>
<html>
<head>
<script src="https://www.google.com/recaptcha/api.js" async defer></script>
</head>
<body>
<!-- #include file="aspJSON.asp"-->
<%
If Request.ServerVariables("REQUEST_METHOD") = "POST" Then
Dim recaptcha_secret, sendstring, objXML
' Secret key
recaptcha_secret = "XXXCCCXXXX"
sendstring = "https://www.google.com/recaptcha/api/siteverify?onload=onloadCallback&render=explicit&secret=" & recaptcha_secret & "&response=" & Request.form("g-recaptcha-response")
Set objXML = Server.CreateObject("MSXML2.ServerXMLHTTP")
objXML.Open "GET", sendstring, False
objXML.Send
dim result, oJSON, success, action, errorCapatcha, errorMsg
result = (objXML.responseText)
Set oJSON = New aspJSON
oJSON.loadJSON(result)
Set objXML = Nothing
success = oJSON.data("success")
if success = "True" then
action = "go to next page"
else
action = "do nothing"
end if
END If
%>
<form method="post" action="">
<!-- Site key -->
<div class="g-recaptcha" data-sitekey="XXXXXXXXX"></div>
<br />
<input type="submit" value="Try">
</form>
</body>
Many Thanks to Lankymart, Leonardo Duarte
First download json.asp https://github.com/tugrul/aspjson
insert in page
<script language="javascript" runat="server" src="json2.asp"></script>
in return do so
If success(objXML.responseText) = True Then
Response.write "success"
Elseif success(objXML.responseText) = False Then
Response.write "failure"
End If
call the function to get the json
Function success(result)
Set motor = JSON.parse(result)
success = motor.success
Set motor = Nothing
End Function
There is a better way and stand alone captcha for ASP instead google captcha. You don't need to add JSON function.
Here is the code:
On your submit page, add:
Type the number bellow:<br>
<input type=text name="captchacode" value="" size=5 maxlength=5><br/>
<img id="imgCaptcha" src="captcha.asp" /><br />
Refresh<br/>
<script language="Javascript">
function RefreshImage(valImageId) {
var objImage = document.images[valImageId];
if (objImage == undefined) {
return;
}
var now = new Date();
objImage.src = objImage.src.split('?')[0] + '?x=' + now.toUTCString();
}
</script>
Insert the function bellow to your asp file:
'*******************************************************
function TestCaptcha(byval valSession, byval valCaptcha)
'*******************************************************
dim tmpSession
valSession = Trim(valSession)
valCaptcha = Trim(valCaptcha)
if (valSession = vbNullString) or (valCaptcha = vbNullString) then
TestCaptcha = false
else
tmpSession = valSession
valSession = Trim(Session(valSession))
Session(tmpSession) = vbNullString
if valSession = vbNullString then
TestCaptcha = false
else
valCaptcha = Replace(valCaptcha,"i","I")
if StrComp(valSession,valCaptcha,1) = 0 then
TestCaptcha = true
else
TestCaptcha = false
end if
end if
end if
end function
Save the code bellow to captcha.asp:
<%#LANGUAGE="VBSCRIPT"%>
<%
'ASP Security Image Generator v4.0 - 13/July/2008
'Generate images to make a CAPTCHA test
'© 2006-2007 Emir Tüzül. All rights reserved.
'http://www.tipstricks.org
'This program is free software; you can redistribute it and/or
'modify it under the terms of the Common Public License
'as published by the Open Source Initiative OSI; either version 1.0
'of the License, or any later version.
'This program is distributed in the hope that it will be useful,
'but WITHOUT ANY WARRANTY; without even the implied warranty of
'MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
'Common Public License for more details.
'*[null pixel]Numbers[repeat count], #[text]Numbers[repeat count], &[row reference]number[referenced row index]
'First row [font height, chars...]
'Following rows [char width, pixel maps...]
FontMap = Array(_
split("13,A,B,C,D,E,F,G,H,I,J,K,L,M,N,O,P,Q,R,S,T,U,V,W,X,Y,Z,0,1,2,3,4,5,6,7,8,9",",") ,_
split("14,*5#4*5,*4#6*4,&2,&2,*3#3*2#3*3,&5,*2#4*2#4*2,*2#3*4#3*2,*2#10*2,*1#12*1,*1#3*6#3*1,&11,#3*8#3",",") ,_
split("11,#8*3,#10*1,#3*4#3*1,&3,&3,&1,&2,#3*4#4,#3*5#3,&9,&8,&2,#9*2",",") ,_
split("11,*4#6*1,*2#9,*1#4*4#2,*1#3*6#1,#3*8,&5,&5,&5,&5,&4,&3,&2,&1",",") ,_
split("12,#8*4,#10*2,#3*4#4*1,#3*5#3*1,#3*6#3,&5,&5,&5,&5,&4,&3,&2,&1",",") ,_
split("9,#9,&1,#3*6,&3,&3,#8*1,&6,&3,&3,&3,&3,&1,&1",",") ,_
split("9,#9,&1,#3*6,&3,&3,&1,&1,&3,&3,&3,&3,&3,&3",",") ,_
split("13,*4#7,*2#11,*1#4*5#3,*1#3*8#1,#3,#3,#3*4#6,&7,#3*7#3,*1#3*6#3,*1#5*4#3,&2,&1",",") ,_
split("11,#3*5#3,&1,&1,&1,&1,#11,&6,&1,&1,&1,&1,&1,&1",",") ,_
split("7,#7,#7,*2#3,&3,&3,&3,&3,&3,&3,&3,&3,&1,&1",",") ,_
split("8,*2#6,&1,*5#3,&3,&3,&3,&3,&3,&3,&3,*4#4,#7,#6",",") ,_
split("12,#3*5#4,#3*4#4,#3*3#4,#3*2#4,#3*2#3,#3*1#3,#7,#8,&5,#3*3#3,#3*4#3,#3*5#3,&1",",") ,_
split("9,#3,#3,#3,#3,#3,#3,#3,#3,#3,#3,#3,#9,#9",",") ,_
split("13,#3*7#3,#4*5#4,&2,#5*3#5,&4,#6*1#6,#3*1#2*1#2*1#3,#3*1#5*1#3,#3*2#3*2#3,&9,#3*7#3,&11,&11",",") ,_
split("11,#4*4#3,#5*3#3,&2,#6*2#3,&4,#3*1#3*1#3,&6,#3*2#6,&8,#3*3#5,&10,#3*4#4,#3*5#3",",") ,_
split("13,*4#5,*2#9,*1#4*3#4,*1#3*5#3,#3*7#3,&5,&5,&5,&5,&4,&3,&2,&1",",") ,_
split("10,#8,#9,#3*3#4,#3*4#3,&4,&4,&3,&2,#7,#3,#3,#3,#3",",") ,_
split("13,*3#6,*2#8,*1#3*4#3,*1#2*6#2,#2*8#2,&5,&5,#2*4#1*3#2,#2*4#2*2#2,*1#2*4#4,&3,*2#10,*3#6*2#2",",") ,_
split("12,#8,#9,#3*4#3,&3,&3,#3*3#4,&2,&1,#3*2#4,#3*3#3,&3,#3*4#4,#3*5#4",",") ,_
split("11,*3#6,*1#9,#4*4#2,#3*6#1,#4,#8,&2,*3#8,*7#4,#1*7#3,#3*4#4,#10,*1#7",",") ,_
split("11,#11,&1,*4#3,&3,&3,&3,&3,&3,&3,&3,&3,&3,&3,&3",",") ,_
split("11,#3*5#3,&1,&1,&1,&1,&1,&1,&1,&1,&1,#4*3#4,*1#9,*3#5",",") ,_
split("14,#3*8#3,*1#3*6#3,&2,*1#3*5#4,*2#3*4#3,&5,*3#3*2#3,&7,&7,*4#6,&10,&10,*5#4",",") ,_
split("17,#3*4#3*4#3,&1,#3*3#5*3#3,*1#3*2#2*1#2*2#3,&4,*1#3*1#3*1#3*1#3,&6,*1#3*1#2*3#2*1#3,&8,*2#5*3#5,&10,*2#4*5#4,&12",",") ,_
split("14,#4*6#4,*1#4*4#4,*2#4*2#4,*3#3*2#3,*3#8,*4#6,*5#4,&6,&5,&4,&3,&2,&1",",") ,_
split("13,#4*5#4,*1#3*5#3,*2#3*3#3,*2#4*1#4,*3#3*1#3,*3#7,*4#5,*5#3,&8,&8,&8,&8,&8",",") ,_
split("10,#10,&1,*6#4,*5#4,*5#3,*4#3,*3#4,*3#3,*2#3,*1#4,#4,&1,&1",",") ,_
split("10,*3#4*3,*1#8*1,*1#3*2#3*1,#3*4#3,&4,&4,&4,&4,&4,&4,&3,&2,&1",",") ,_
split("9,*3#3*3,&1,#6*3,&3,*3#3*3,&5,&5,&5,&5,&5,&5,#9,&12",",") ,_
split("10,*1#6*3,#8*2,#2*3#4*1,#1*5#3*1,*6#3*1,&5,*5#3*2,*4#4*2,*3#4*3,*2#4*4,*1#4*5,#10,&12",",") ,_
split("11,*1#8*2,#10*1,#3*5#3,#1*7#3,*7#3*1,*3#6*2,*3#7*1,*7#4,*8#3,&4,#3*4#4,&2,*1#7*3",",") ,_
split("12,*6#4*2,*5#5*2,&2,*4#2*1#3*2,*3#3*1#3*2,*2#3*2#3*2,*1#3*3#3*2,#3*4#3*2,#12,&9,*7#3*2,&11,&11",",") ,_
split("11,*1#10,&1,*1#3*7,&3,*1#8*2,*1#9*1,*7#4,*8#3,&8,#1*7#3,#3*4#3*1,#10*1,*1#7*3",",") ,_
split("11,*4#6*1,*2#8*1,*1#4*6,*1#3*7,#3*1#5*2,#10*1,#3*4#4,#3*5#3,&8,&8,*1#3*3#3*1,*1#9*1,*3#5*3",",") ,_
split("11,#11,&1,*7#4,*7#3*1,*6#4*1,*6#3*2,*5#3*3,*4#4*3,*4#3*4,*3#4*4,*3#3*5,*2#3*6,*1#4*6",",") ,_
split("11,*2#7*2,*1#9*1,#3*4#4,#3*5#3,#4*3#3*1,*1#8*2,&1,*1#3*1#5*1,&4,&4,#4*3#4,&2,*2#6*3",",") ,_
split("11,*3#5*3,*1#9*1,*1#3*3#3*1,#3*5#3,&4,&4,#4*4#3,*1#10,*2#5*1#3,*7#3*1,*6#4*1,*1#8*2,*1#6*4",",") _
)'Previous row must end with _
'#Begin ColorMap
const BmpColorMap = "dffeff000c851700eceeee006c363600da644a00"
ColorMap = Array(_
split("00,01,01,03",",") ,_
split("02,03,03,01",",") ,_
split("00,04,04,02",",") _
)'End ColorMap
'#Auto calculated variables
dim ImageWidth, ImageHeight, arrTextWidth(), TextHeight, LeftMargin, arrTopMargin(), CursorPos
dim BmpEndLine, BColor, TColor, NColor
dim i, j, k, x, y
'#Editable consts and variables
dim Bitmap(40,200) '[Height,Width]
const CodeLength = 5 'Secure code length (Max:8)
const CodeType = 0 '0[Random numbers], 1[Random chars and numbers], 2[Fake word]
const CharTracking = 35 'Set the tracking between two characters
const RndTopMargin = true 'Randomize top margin every character
const NoiseEffect = 0 '0[none], 1[sketch], 2[random foreground lines], 3[random background lines], 4[1 and 3 (Recommed maximum NoiseLine=4)]
const NoiseLine = 3 'Low values make easy OCR, high values decrease readability
const MinLineLength = 6 'Minimum noise line length
const SessionName = "ASPCAPTCHA" 'Where store your secure code
'#Subroutines and functions
'*****************************
function CreateGUID(valLength)
'*****************************
if CodeType = 1 then
strValid = "A0B1C2D3E4F5G6H7I8J9K8L7M6N5O4P3Q2R1S0T1U2V3W4X5Y6Z7"
else
strValid = "0516273849"
end if
tmpGUID = vbNullString
tmpChr = vbNullString
Randomize(Timer)
for cGUID=1 to valLength
do
tmpChr = Mid(strValid, Int(Rnd(1) * Len(strValid)) + 1, 1)
loop while CStr(tmpChr) = CStr(Right(tmpGUID,1))
tmpGUID = tmpGUID & tmpChr
Next
CreateGUID = tmpGUID
end function
'***************************
function FakeWord(valLength)
'***************************
arrChars = Array("AEIOU", "BCDFGHJKLMNPQRSTVWXYZ")
cVowel = 0
cConsonant = 0
tmpWord = vbNullString
Randomize(Timer)
for cWord=1 to valLength
if (cWord=2) or ((valLength > 1) and (cWord = valLength)) then
ixChars = 1-ixChars
elseif (cVowel < 2) and (cConsonant < 2) then
ixChars = Int(Rnd(1) * 2)
elseif (cVowel < 2) then
ixChars = 0
elseif (cConsonant < 2) then
ixChars = 1
end if
Pattern = arrChars(ixChars)
tmpWord = tmpWord & Mid(Pattern, Int(Rnd(1) * Len(Pattern)) + 1, 1)
if ixChars = 0 then
cVowel = cVowel + 1
cConsonant = 0
else
cVowel = 0
cConsonant = cConsonant + 1
end if
next
FakeWord = tmpWord
end function
'**********************************
function RndInterval(valMin,valMax)
'**********************************
Randomize(Timer)
RndInterval = Int(((valMax - valMin + 1) * Rnd()) + valMin)
end function
'**************************
function GetCharMap(valChr)
'**************************
dim i, j
j = 0
for i=1 to UBound(FontMap(0))
if CStr(FontMap(0)(i)) = CStr(valChr) then
j = i
exit for
end if
next
if j > 0 then
GetCharMap = FontMap(j)
else
GetCharMap = Array(0)
end if
end function
'************************************************
sub WriteCanvas(byval valChr, byval valTopMargin)
'************************************************
dim i, j, k, curPos, tmpChr, arrChrMap, strPixMap, drawPixel, pixRepeat
'find char map
arrChrMap = GetCharMap(valChr)
if UBound(arrChrMap) < 1 then
exit sub
end if
for i=1 to UBound(arrChrMap)
'get pixel map active line
strPixMap = arrChrMap(i)
if Left(strPixMap,1) = "&" then
j = Mid(strPixMap,2)
if (IsNumeric(j) = true) then
strPixMap = arrChrMap(CInt(j))
else
strPixMap = vbNullString
end if
end if
strPixMap = Trim(strPixMap)
'drawing pixel
curPos = CursorPos
drawPixel = false
pixRepeat = vbNullString
for j=1 to Len(strPixMap)
tmpChr = Mid(strPixMap,j,1)
if (IsNumeric(tmpChr) = true) and (j < Len(strPixMap)) then
pixRepeat = pixRepeat & tmpChr
else
'end pixel map?
if IsNumeric(tmpChr) = true then
pixRepeat = pixRepeat & tmpChr
end if
'draw pixel
if (drawPixel = true) and (IsNumeric(pixRepeat) = true) then
for k=1 to CInt(pixRepeat)
curPos = curPos + 1
Bitmap((valTopMargin + i),curPos) = TColor
next
elseif IsNumeric(pixRepeat) = true then
curPos = curPos + CInt(pixRepeat)
end if
'what is new command?
if tmpChr = "#" then
drawPixel = true
else
drawPixel = false
end if
pixRepeat = vbNullString
end if
next
next
end sub
'*******************************
sub PrepareBitmap(valSecureCode)
'*******************************
dim i, j
'image dimensions
ImageWidth = UBound(Bitmap,2)
ImageHeight = UBound(Bitmap,1)
'char and text width
redim arrTextWidth(CodeLength)
arrTextWidth(0) = 0
for i=1 to CodeLength
arrTextWidth(i) = CInt(GetCharMap(Mid(secureCode,i,1))(0))
arrTextWidth(0) = arrTextWidth(0) + arrTextWidth(i)
next
arrTextWidth(0) = arrTextWidth(0) + ((CodeLength - 1) * CharTracking)
'text height
TextHeight = CInt(FontMap(0)(0))
'left margin
LeftMargin = Round((ImageWidth - arrTextWidth(0)) / 2)
'top margin
redim arrTopMargin(CodeLength)
arrTopMargin(0) = Round((ImageHeight - TextHeight) / 2)
if RndTopMargin = true then
for i=1 to CodeLength
arrTopMargin(i) = RndInterval(Int(arrTopMargin(0) / 2),(arrTopMargin(0) + Round(arrTopMargin(0) / 2)))
next
else
for i=1 to CodeLength
arrTopMargin(i) = arrTopMargin(0)
next
end if
'color selection
i = RndInterval(0,UBound(ColorMap))
BColor = ColorMap(i)(0)
NColor = ColorMap(i)(1)
TColor = ColorMap(i)(2)
'Apply background effect
if NoiseEffect = 3 then
AddNoise()
end if
'write text
for i=1 to CodeLength
'calculate cursor pos
CursorPos = 0
for j=(i-1) to 1 step -1
CursorPos = CursorPos + arrTextWidth(j) + CharTracking
next
CursorPos = LeftMargin + CursorPos
'write active char
WriteCanvas Mid(secureCode,i,1),arrTopMargin(i)
next
end sub
'***********************************
sub DrawLine(x0, y0, x1, y1, valClr)
'***********************************
'Reference from Donald Hearn and M. Pauline Baker, Computer Graphics C Version
dim m, b, dx, dy
if (NoiseEffect = 4) and (Bitmap(y0,x0) = TColor) then
clrNoise = vbNullString
else
clrNoise = valClr
end if
Bitmap(y0,x0) = clrNoise
dx = x1 - x0
dy = y1 - y0
if Abs(dx) > Abs(dy) then
m = (dy / dx)
b = y0 - (m * x0)
if dx < 0 then
dx = -1
else
dx = 1
end if
do while x0 <> x1
x0 = x0 + dx
if (NoiseEffect = 4) and (Bitmap(Round((m * x0) + b),x0) = TColor) then
clrNoise = vbNullString
else
clrNoise = valClr
end if
Bitmap(Round((m * x0) + b),x0) = clrNoise
loop
elseif dy <> 0 then
m = (dx / dy)
b = x0 - (m * y0)
if dy < 0 then
dy = -1
else
dy = 1
end if
do while y0 <> y1
y0 = y0 + dy
if (NoiseEffect = 4) and (Bitmap(y0,Round((m * y0) + b)) = TColor) then
clrNoise = vbNullString
else
clrNoise = valClr
end if
Bitmap(y0,Round((m * y0) + b)) = clrNoise
loop
end if
end sub
'*************
sub AddNoise()
'*************
dim median, i, j, x0, y0, x1, y1, dx, dy, dxy
if NoiseEffect = 1 then
clrNoise = vbNullString
else
clrNoise = NColor
end if
for i=1 to NoiseLine
x0 = RndInterval(1,ImageWidth)
y0 = RndInterval(1,ImageHeight)
x1 = RndInterval(1,ImageWidth)
y1 = RndInterval(1,ImageHeight)
'Check minimum line length
dx = Abs(x1 - x0)
dy = Abs(y1 - y0)
median = Round(Sqr((dx * dx) + (dy * dy))/2)
if median < MinLineLength then
dxy = MinLineLength - median
if x1 < x0 then
dx = -1
else
dx = 1
end if
if y1 < y0 then
dy = -1
else
dy = 1
end if
for j=1 to dxy
if ((x1 + dx) < 1) or ((x1 + dx) > ImageWidth) or ((y1 + dy) < 1) or ((y1 + dy) > ImageHeight) then
exit for
end if
x1 = x1 + dx
y1 = y1 + dy
next
end if
'Draw noise line
DrawLine x0,y0,x1,y1,clrNoise
next
end sub
'*****************************************************************
function FormatHex(byval valHex,byval fixByte,fixDrctn,valReverse)
'*****************************************************************
fixByte = fixByte * 2
tmpLen = Len(valHex)
if fixByte > tmpLen then
tmpFixHex = String((fixByte - tmpLen),"0")
if fixDrctn = 1 then
valHex = valHex & tmpFixHex
else
valHex = tmpFixHex & valHex
end if
end if
if valReverse = true then
tmpHex = vbNullString
for cFrmtHex=1 to Len(valHex) step 2
tmpHex = Mid(valHex,cFrmtHex,2) & tmpHex
next
FormatHex = tmpHex
else
FormatHex = CStr(valHex)
end if
end function
'******************
sub SendHex(valHex)
'******************
for cHex = 1 to Len(valHex) step 2
Response.BinaryWrite ChrB(CByte("&H" & Mid(valHex,cHex,2)))
next
end sub
'***************
sub SendBitmap()
'***************
if (ImageWidth mod 4) <> 0 then
BmpEndLine = String((4-(ImageWidth mod 4))*2,"0")
else
BmpEndLine = vbNullString
end if
BmpInfoHeader = Array("28000000","00000000","00000000","0100","0800","00000000","00000000","120B0000","120B0000","00000000","00000000")
BmpInfoHeader(1) = FormatHex(Hex(ImageWidth),4,0,true)
BmpInfoHeader(2) = FormatHex(Hex(ImageHeight),4,0,true)
BmpInfoHeader(6) = FormatHex(Hex((ImageHeight * ImageWidth) + (ImageHeight * (Len(BmpEndLine) / 2))),4,0,true)
BmpInfoHeader(9) = FormatHex(Hex(Len(BmpColorMap)/8),4,0,true)
BmpInfoHeader(10) = BmpInfoHeader(9)
BmpHeader = Array("424D","00000000","0000","0000","00000000")
BmpHeader(1) = FormatHex(Hex((Len(Join(BmpHeader,"")) / 2) + (Len(Join(BmpInfoHeader,"")) / 2) + (Len(BmpColorMap) / 2) + (ImageHeight * ImageWidth) + (ImageHeight * (Len(BmpEndLine) / 2))),4,0,true)
BmpHeader(4) = FormatHex(Hex((Len(Join(BmpHeader,"")) / 2) + (Len(Join(BmpInfoHeader,"")) / 2) + (Len(BmpColorMap) / 2)),4,0,true)
Response.Clear
Response.Buffer = True
Response.ContentType = "image/bmp"
Response.AddHeader "Content-Disposition", "inline; filename=captcha.bmp"
Response.CacheControl = "no-cache"
Response.AddHeader "Pragma", "no-cache"
Response.Expires = -1
SendHex(Join(BmpHeader,""))
SendHex(Join(BmpInfoHeader,""))
SendHex(BmpColorMap)
for y=ImageHeight to 1 step -1
for x=1 to ImageWidth
tmpHex = Bitmap(y,x)
if tmpHex = vbNullString then
SendHex(BColor)
else
SendHex(tmpHex)
end if
next
SendHex(BmpEndLine)
next
Response.Flush
end sub
'#Generate captcha
if CodeType < 2 then
secureCode = CreateGUID(CodeLength)
else
secureCode = FakeWord(CodeLength)
end if
Session(SessionName) = secureCode
PrepareBitmap(secureCode)
if (NoiseEffect > 0) and (NoiseEffect <> 3) then
AddNoise()
end if
SendBitmap()
%>
Before process, validate the captcha:
<%
if not TestCaptcha("ASPCAPTCHA", request("captchacode")) then
response.write "Captcha error!"
response.end
end if
response.write "Captcha OK"
'... process...
%>

Error in textConnection(): all connections are in use

I have read most of the posts concerning an error of this type but neither applies to my case. I am new in R, working on an assignment for school based on Nolan and Lang's book Data Science Case Studies in R. I am working on using stats to identify spam, url for the code can be found here, which require working with files from http://spamassassin.apache.org/old/publiccorpus/ (which are pretty big)
Now the problem I am facing is the following (just posting the chunks of code where I have encountered the issue):
sampleSplit = lapply(sampleEmail, splitMessage)
processHeader = function(header)
{
# modify the first line to create a key:value pair
header[1] = sub("^From", "Top-From:", header[1])
headerMat = read.dcf(textConnection(header), all = TRUE)
headerVec = unlist(headerMat)
dupKeys = sapply(headerMat, function(x) length(unlist(x)))
names(headerVec) = rep(colnames(headerMat), dupKeys)
return(headerVec)
}
headerList = lapply(sampleSplit,
function(msg) {
processHeader(msg$header)} )
contentTypes = sapply(headerList, function(header)
header["Content-Type"])
names(contentTypes) = NULL
contentTypes
hasAttach = grep("^ *multi", tolower(contentTypes))
hasAttach
boundaries = getBoundary(contentTypes[ hasAttach ])
boundaries
boundary = boundaries[9]
body = sampleSplit[[15]]$body
bString = paste("--", boundary, sep = "")
bStringLocs = which(bString == body)
bStringLocs
eString = paste("--", boundary, "--", sep = "")
eStringLoc = which(eString == body)
eStringLoc
diff(c(bStringLocs[-1], eStringLoc))
### This code has mistakes in it - and we fix them later!
processAttach = function(body, contentType){
boundary = getBoundary(contentType)
bString = paste("--", boundary, "$", sep = "")
bStringLocs = grep(bString, body)
eString = paste("--", boundary, "--$", sep = "")
eStringLoc = grep(eString, body)
n = length(body)
if (length(eStringLoc) == 0) eStringLoc = n + 1
if (length(bStringLocs) == 1) attachLocs = NULL
else attachLocs = c(bStringLocs[-1], eStringLoc)
msg = body[ (bStringLocs[1] + 1) : min(n, (bStringLocs[2] - 1),
na.rm = TRUE)]
if ( eStringLoc < n )
msg = c(msg, body[ (eStringLoc + 1) : n ])
if ( !is.null(attachLocs) ) {
attachLens = diff(attachLocs, lag = 1)
attachTypes = mapply(function(begL, endL) {
contentTypeLoc = grep("[Cc]ontent-[Tt]ype", body[ (begL + 1) : (endL - 1)])
contentType = body[ begL + contentTypeLoc]
contentType = gsub('"', "", contentType )
MIMEType = sub(" *Content-Type: *([^;]*);?.*", "\\1", contentType)
return(MIMEType)
}, attachLocs[-length(attachLocs)], attachLocs[-1])
}
if (is.null(attachLocs)) return(list(body = msg, attachInfo = NULL) )
else return(list(body = msg,
attachDF = data.frame(aLen = attachLens,
aType = attachTypes,
stringsAsFactors = FALSE)))
}
bodyList = lapply(sampleSplit, function(msg) msg$body)
attList = mapply(processAttach, bodyList[hasAttach],
contentTypes[hasAttach],
SIMPLIFY = FALSE)
lens = sapply(attList, function(processedA)
processedA$attachDF$aLen)
head(lens)
attList[[2]]$attachDF
body = bodyList[hasAttach][[2]]
length(body)
body[35:45]
processAttach = function(body, contentType){
n = length(body)
boundary = getBoundary(contentType)
bString = paste("--", boundary, sep = "")
bStringLocs = which(bString == body)
eString = paste("--", boundary, "--", sep = "")
eStringLoc = which(eString == body)
if (length(eStringLoc) == 0) eStringLoc = n
if (length(bStringLocs) <= 1) {
attachLocs = NULL
msgLastLine = n
if (length(bStringLocs) == 0) bStringLocs = 0
} else {
attachLocs = c(bStringLocs[ -1 ], eStringLoc)
msgLastLine = bStringLocs[2] - 1
}
msg = body[ (bStringLocs[1] + 1) : msgLastLine]
if ( eStringLoc < n )
msg = c(msg, body[ (eStringLoc + 1) : n ])
if ( !is.null(attachLocs) ) {
attachLens = diff(attachLocs, lag = 1)
attachTypes = mapply(function(begL, endL) {
CTloc = grep("^[Cc]ontent-[Tt]ype", body[ (begL + 1) : (endL - 1)])
if ( length(CTloc) == 0 ) {
MIMEType = NA
} else {
CTval = body[ begL + CTloc[1] ]
CTval = gsub('"', "", CTval )
MIMEType = sub(" *[Cc]ontent-[Tt]ype: *([^;]*);?.*", "\\1", CTval)
}
return(MIMEType)
}, attachLocs[-length(attachLocs)], attachLocs[-1])
}
if (is.null(attachLocs)) return(list(body = msg, attachDF = NULL) )
return(list(body = msg,
attachDF = data.frame(aLen = attachLens,
aType = unlist(attachTypes),
stringsAsFactors = FALSE)))
}
readEmail = function(dirName) {
# retrieve the names of files in directory
fileNames = list.files(dirName, full.names = TRUE)
# drop files that are not email
notEmail = grep("cmds$", fileNames)
if ( length(notEmail) > 0) fileNames = fileNames[ - notEmail ]
# read all files in the directory
lapply(fileNames, readLines, encoding = "latin1")
}
processAllEmail = function(dirName, isSpam = FALSE)
{
# read all files in the directory
messages = readEmail(dirName)
fileNames = names(messages)
n = length(messages)
# split header from body
eSplit = lapply(messages, splitMessage)
rm(messages)
# process header as named character vector
headerList = lapply(eSplit, function(msg)
processHeader(msg$header))
# extract content-type key
contentTypes = sapply(headerList, function(header)
header["Content-Type"])
# extract the body
bodyList = lapply(eSplit, function(msg) msg$body)
rm(eSplit)
# which email have attachments
hasAttach = grep("^ *multi", tolower(contentTypes))
# get summary stats for attachments and the shorter body
attList = mapply(processAttach, bodyList[hasAttach],
contentTypes[hasAttach], SIMPLIFY = FALSE)
bodyList[hasAttach] = lapply(attList, function(attEl)
attEl$body)
attachInfo = vector("list", length = n )
attachInfo[ hasAttach ] = lapply(attList,
function(attEl) attEl$attachDF)
# prepare return structure
emailList = mapply(function(header, body, attach, isSpam) {
list(isSpam = isSpam, header = header,
body = body, attach = attach)
},
headerList, bodyList, attachInfo,
rep(isSpam, n), SIMPLIFY = FALSE )
names(emailList) = fileNames
invisible(emailList)
}
Everything runs fine right up to:
emailStruct = mapply(processAllEmail, fullDirNames,
isSpam = rep( c(FALSE, TRUE), 3:2))
emailStruct = unlist(emailStruct, recursive = FALSE)
sampleStruct = emailStruct[ indx ]
save(emailStruct, file="emailXX.rda")
I get the error Error in textConnection(header) : all connections are in use, therefore it doesn't recognize "emailStruct", which I need later on. I seriously don't know how to overcome it so that I can continue with the rest of the code, which requires some of these variables to work.
When you run textConnection() you are opening a text connection, but you are never closing it. Try closing it explicitly after you read from it
read.dcf(tc<-textConnection(header), all = TRUE)
close(tc)

run-time error '5' maps.googleapis.com/maps/api/distancematrix

Yesterday, I ran the following script in excel and it worked, but now it throws an error:
(run-time error '5' )
in the line:
Distance = Mid(Distance, InStr(1, Distance, ">") + 1, InStr(1, Distance, " ") - InStr(1, Distance, ">") - 1)
Sub Поиск_ближайшего_СБС()
Set Points = Worksheets("Точки")
Set SBS = Worksheets("СБС")
Dim Cordinate11, Cordinate12, Cordinate21, Cordinate22 As String
i = 2
Do While SBS.Cells(i, 1) <> Empty
Rows_of_SBS = i
i = i + 1
Loop
i = 2
Do While Cells(i, 1) <> Empty
Dist = 1000
Cordinate21 = Points.Cells(i + 1, 3)
Cordinate22 = Points.Cells(i + 1, 4)
For j = 2 To Rows_of_SBS
Cordinate11 = SBS.Cells(j, 2)
Cordinate12 = SBS.Cells(j, 3)
Set IE = CreateObject("InternetExplorer.Application")
IE.Visible = False
With IE
.Navigate "http://maps.googleapis.com/maps/api/distancematrix/xml?origins=" _
& Cordinate11 & ",+" & Cordinate12 _
& "&destinations=" _
& Cordinate21 & ",+" & Cordinate22 _
& "&mode=driving&language=ru&sensor=false"
Do While .Busy
DoEvents
Loop
For Each MyTable In .Document.getElementsByTagName("text")
Distance = MyTable.innertext
Next
Distance = Mid(Distance, InStr(1, Distance, ">") + 1, InStr(1, Distance, " ") - InStr(1, Distance, ">") - 1)
If CDbl(Distance) < Dist Then
Dist = CDbl(Distance) s = j
End If
End With
IE.Quit
Set EI = Nothing
Next j
Points.Cells(i + 1, 5) = Dist
Points.Cells(i + 1, 6) = SBS.Cells(s, 1)
i = i + 1
Loop
End Sub
'

Convert Cheat Engine base address

I found a memory address and used Cheat Engine's pointer scan to get referring pointers. To use it in a script I need a base address, which is [game.exe+009274]. How to convert this to an address for use in AutoIt script?
I use NomadMemory.au3 UDF.
I have written 2 function some time ago. One to load all the modules loaded with the process and one to get the base address of the module you need.
Both might be handy here.
Local $iPID = WinGetProcess("app.exe")
Local $sLoadedModules = _ProcessGetLoadedModules($iPID)
Local $My_dll = _MemoryModuleGetBaseAddress($iPID, "My.dll")
For $i = 0 To UBound($sLoadedModules) - 1
ConsoleWrite($sLoadedModules[$i] & #LF) ; find your process here
Next
ConsoleWrite($My_dll & #LF)
Func _ProcessGetLoadedModules($iPID)
Local Const $PROCESS_QUERY_INFORMATION = 0x0400
Local Const $PROCESS_VM_READ = 0x0010
Local $aCall, $hPsapi = DllOpen("Psapi.dll")
Local $hProcess, $tModulesStruct
$tModulesStruct = DllStructCreate("hwnd [200]")
Local $SIZEOFHWND = DllStructGetSize($tModulesStruct) / 200
$hProcess = _WinAPI_OpenProcess(BitOR($PROCESS_QUERY_INFORMATION, $PROCESS_VM_READ), False, $iPID)
If Not $hProcess Then Return SetError(1, 0, -1)
$aCall = DllCall($hPsapi, "int", "EnumProcessModules", "ptr", $hProcess, "ptr", DllStructGetPtr($tModulesStruct), "dword", DllStructGetSize($tModulesStruct), "dword*", "")
If $aCall[4] > DllStructGetSize($tModulesStruct) Then
$tModulesStruct = DllStructCreate("hwnd [" & $aCall[4] / $SIZEOFHWND & "]")
$aCall = DllCall($hPsapi, "int", "EnumProcessModules", "ptr", $hProcess, "ptr", DllStructGetPtr($tModulesStruct), "dword", $aCall[4], "dword*", "")
EndIf
Local $aReturn[$aCall[4] / $SIZEOFHWND]
For $i = 0 To UBound($aReturn) - 1
$aCall = DllCall($hPsapi, "dword", "GetModuleFileNameExW", "ptr", $hProcess, "ptr", DllStructGetData($tModulesStruct, 1, $i + 1), "wstr", "", "dword", 65536)
$aReturn[$i] = $aCall[3]
Next
_WinAPI_CloseHandle($hProcess)
DllClose($hPsapi)
Return $aReturn
EndFunc ;==>_ProcessGetLoadedModules
Func _MemoryModuleGetBaseAddress($iPID, $sModule)
If Not ProcessExists($iPID) Then Return SetError(1, 0, 0)
If Not IsString($sModule) Then Return SetError(2, 0, 0)
Local $PSAPI = DllOpen("psapi.dll")
Local $hProcess
Local $PERMISSION = BitOR(0x0002, 0x0400, 0x0008, 0x0010, 0x0020)
If $iPID > 0 Then
Local $hProcess = DllCall("kernel32.dll", "ptr", "OpenProcess", "dword", $PERMISSION, "int", 0, "dword", $iPID)
If $hProcess[0] Then
$hProcess = $hProcess[0]
EndIf
EndIf
Local $Modules = DllStructCreate("ptr[1024]")
Local $aCall = DllCall($PSAPI, "int", "EnumProcessModules", "ptr", $hProcess, "ptr", DllStructGetPtr($Modules), "dword", DllStructGetSize($Modules), "dword*", 0)
If $aCall[4] > 0 Then
Local $iModnum = $aCall[4] / 4
Local $aTemp
For $i = 1 To $iModnum
$aTemp = DllCall($PSAPI, "dword", "GetModuleBaseNameW", "ptr", $hProcess, "ptr", Ptr(DllStructGetData($Modules, 1, $i)), "wstr", "", "dword", 260)
If $aTemp[3] = $sModule Then
DllClose($PSAPI)
Return Ptr(DllStructGetData($Modules, 1, $i))
EndIf
Next
EndIf
DllClose($PSAPI)
Return SetError(-1, 0, 0)
EndFunc ;==>_MemoryModuleGetBaseAddress

Autoit Controlsend to child window

I have from 1-6 commandprompts in a window. When they weren't in the window, I could use controlsend fine.
Code:
$GUI2 = GUICreate("Consoles", 1020, 600, 1282, 300, BitOR($WS_MINIMIZEBOX, $WS_SYSMENU, $WS_CAPTION, $WS_CLIPCHILDREN, $WS_POPUP, $WS_POPUPWINDOW, $WS_GROUP, $WS_BORDER, $WS_CLIPSIBLINGS))
$hwnd00 = WinGetHandle("Consoles")
If GUICtrlRead($Bungee) = 1 Then
$BungeeServer = Run("java -Xmx512M -jar " & '"' & $file0 & "\BungeeCord.jar" & '"', $file0, $Hide)
If Not ProcessWait($BungeeServer) = 0 Then
WinSetTitle("C:\Windows\system32\java.exe", "", "Bungee")
WinSetTitle("C:\WINDOWS\SYSTEM32\java.exe", "", "Bungee")
Global $hwnd0 = WinGetHandle("Bungee")
EndIf
EndIf
If GUICtrlRead($server1) = 1 Then
$1 = Run("java " & $chosen & " -jar " & '"' & $file1 & '"' & "\minecraft_server.jar", $file1, $Hide)
If Not ProcessWait($1) = 0 Then
WinSetTitle("C:\Windows\system32\java.exe", "", "Server1")
WinSetTitle("C:\WINDOWS\SYSTEM32\java.exe", "", "Server1")
Global $hwnd1 = WinGetHandle("Server1")
EndIf
EndIf
If GUICtrlRead($server2) = 1 Then
$2 = Run("java " & $chosen & " -jar " & '"' & $file2 & '"' & "\minecraft_server.jar", $file2, $Hide)
If Not ProcessWait($2) = 0 Then
WinSetTitle("C:\Windows\system32\java.exe", "", "Server2")
WinSetTitle("C:\WINDOWS\SYSTEM32\java.exe", "", "Server2")
Global $hwnd2 = WinGetHandle("Server2")
EndIf
EndIf
If GUICtrlRead($server3) = 1 Then
$3 = Run("java " & $chosen & " -jar " & '"' & $file3 & '"' & "\minecraft_server.jar", $file3, $Hide)
If Not ProcessWait($3) = 0 Then
WinSetTitle("C:\Windows\system32\java.exe", "", "Server3")
WinSetTitle("C:\WINDOWS\SYSTEM32\java.exe", "", "Server3")
Global $hwnd3 = WinGetHandle("Server3")
EndIf
EndIf
If GUICtrlRead($server4) = 1 Then
$4 = Run("java " & $chosen & " -jar " & '"' & $file4 & '"' & "\minecraft_server.jar", $file4, $Hide)
If Not ProcessWait($4) = 0 Then
WinSetTitle("C:\Windows\system32\java.exe", "", "Server4")
WinSetTitle("C:\WINDOWS\SYSTEM32\java.exe", "", "Server4")
Global $hwnd4 = WinGetHandle("Server4")
EndIf
EndIf
If GUICtrlRead($server5) = 1 Then
$5 = Run("java " & $chosen & " -jar " & '"' & $file5 & '"' & "\minecraft_server.jar", $file5, $Hide)
If Not ProcessWait($5) = 0 Then
WinSetTitle("C:\Windows\system32\java.exe", "", "Server5")
WinSetTitle("C:\WINDOWS\SYSTEM32\java.exe", "", "Server5")
Global $hwnd5 = WinGetHandle("Server5")
EndIf
EndIf
_WinAPI_SetWindowLong($hwnd0, $GWL_EXSTYLE, $WS_EX_MDICHILD)
_WinAPI_SetParent($hwnd0, $GUI2)
_WinAPI_SetWindowLong($hwnd1, $GWL_EXSTYLE, $WS_EX_MDICHILD)
_WinAPI_SetParent($hwnd1, $GUI2)
_WinAPI_SetWindowLong($hwnd2, $GWL_EXSTYLE, $WS_EX_MDICHILD)
_WinAPI_SetParent($hwnd2, $GUI2)
_WinAPI_SetWindowLong($hwnd3, $GWL_EXSTYLE, $WS_EX_MDICHILD)
_WinAPI_SetParent($hwnd3, $GUI2)
_WinAPI_SetWindowLong($hwnd4, $GWL_EXSTYLE, $WS_EX_MDICHILD)
_WinAPI_SetParent($hwnd4, $GUI2)
_WinAPI_SetWindowLong($hwnd5, $GWL_EXSTYLE, $WS_EX_MDICHILD)
_WinAPI_SetParent($hwnd5, $GUI2)
WinMove($hwnd0, "", 0, 0, 340, 300)
WinMove($hwnd1, "", 340, 0, 340, 300)
WinMove($hwnd2, "", 680, 0, 340, 300)
WinMove($hwnd3, "", 0, 300, 340, 300)
WinMove($hwnd4, "", 340, 300, 340, 300)
WinMove($hwnd5, "", 680, 300, 340, 300)
Earlier I used this: ControlSend("Server1", "", $hwnd1, 'stop' & '{ENTER}')
One line for each of the windows. How can I send information to them when they are in the parent window(Even if the parent window is hidden)?
This command allows the window search routines to search child windows as well as top-level windows.
Opt("WinSearchChildren", 1) ;0=no, 1=search children also
0 = Only search top-level windows (default)
1 = Search top-level and child windows

Resources