Jump to content
Sign in to follow this  
emendelson

Get LPT port addresses via AutoIt?

Recommended Posts

emendelson

The Windows device manager lists two addresses for any LPT port installed on the computer. These addresses are not listed in the registry, but it seems that WMI calls can get them.

I am working on a script that will use those two addresses, but I don't have enough AutoIt knowledge to know how to find them. I've searched the forums and the net without success. Could any of the experts here suggest the code that can return the two memory addresses of a specified LPT port?

Thanks for any and all help.

Share this post


Link to post
Share on other sites
water

You could have a look at the Example Scripts forum and search for "ScriptoMatic". This script lets you search for all kind of information using WMI and generates AutoIt code for you.


My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (2018-06-01 - Version 1.4.9.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2018-09-01 - Version 1.3.4.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
PowerPoint (2017-06-06 - Version 0.0.5.0) - Download - General Help & Support
Excel - Example Scripts - Wiki
Word - Wiki
 
Tutorials:

ADO - Wiki

 

Share this post


Link to post
Share on other sites
emendelson

Extremely useful advice. Thank you. I was able to use ScriptoMatic to get the key in the registry that contains the information about the parallel port, but the next step seems to be more difficult.

After querying WMI for the parallel port registry info it returned the PNP device ID, in this form:

ACPIPNP04014&1FE41AC6&0

That's easy to translate into a read-registry call to:

HKEY_LOCAL_MACHINESYSTEMCurrentControlSetEnumACPIPNP04014&1fe41ac6&0Control

which contains the key

AllocConfig

Now, AllocConfig is binary data in REG_RESOURCE_LIST format that looks like the linked image file below. The two addresses I want are two bytes each, at 001a and 002a, which are 0378 and 0778. So my next question is:

Does AutoIt have a way to extract those two addresses from the binary data? I see that RegRead can read dWord data, but I'm not sure it knows how to read REG_RESOURCE_LIST, and I don't understand how to extract these four bytes from the dWord data. It's probably obvious to experienced scripters, but I'm sorry to say it's not obvious to me, so any help would be gratefully received.

EDIT: I see that the question above has been raised elsewhere in the forum, but I don't see any easy answers so far.

EDIT: Here's the linked image:

Posted Image

Edited by emendelson

Share this post


Link to post
Share on other sites
water

When you search the forum for "REG_RESOURCE_LIST" you'll get a lot of hits.

One of them is the This UDF seems to be able to handle "REG_RESOURCE_LIST" entries.


My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (2018-06-01 - Version 1.4.9.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2018-09-01 - Version 1.3.4.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
PowerPoint (2017-06-06 - Version 0.0.5.0) - Download - General Help & Support
Excel - Example Scripts - Wiki
Word - Wiki
 
Tutorials:

ADO - Wiki

 

Share this post


Link to post
Share on other sites
emendelson

Thank you for that link to a very useful UDF. I actually had tried that UDF, but it creates an array with a list of the key names and the type of key that each one is. So, in my case, it tells me that the key AllocConfig is in the form REG_RESOURCE_LIST.

What I hoped I could do in AutoIt is extract the contents of the value of the AllocConfig key and then extract the two numbers that I need from that value.

I also tried the script in message 5 here:

And then I looked further down in the script, and saw that the reg command can do the job, so all I need to do is this:

RunWait (@ComSpec & ' /c reg query "HKLMSYSTEMCurrentControlSetEnumACPIPNP04014&1fe41ac6&0Control" /v AllocConfig > c:tempoutput.reg')

and then parse the output file.

I also see from other posts that I can capture the output as a variable, like this:

#include <Constants.au3>
Local $regdata = Run (@ComSpec & ' /c reg query "HKLMSYSTEMCurrentControlSetEnumACPIPNP04014&1fe41ac6&0Control" /v AllocConfig', @SystemDir, @SW_HIDE, $STDERR_CHILD + $STDOUT_CHILD)
Local $line
While 1
    $line = StdoutRead($regdata)
    If @error Then ExitLoop
    MsgBox(0, "STDOUT read:", $line)
WEnd
While 1
    $line = StderrRead($regdata)
    If @error Then ExitLoop
    MsgBox(0, "STDERR read:", $line)
WEnd
MsgBox(0, "Debug", "Exiting...")

And the next problem seems to be to parse the resulting data.

Thank you again for pointing me toward the solution to this!

Share this post


Link to post
Share on other sites
water

Glad to be of service :D


My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (2018-06-01 - Version 1.4.9.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2018-09-01 - Version 1.3.4.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
PowerPoint (2017-06-06 - Version 0.0.5.0) - Download - General Help & Support
Excel - Example Scripts - Wiki
Word - Wiki
 
Tutorials:

ADO - Wiki

 

Share this post


Link to post
Share on other sites
emendelson

EDIT - I've revised this script, but it still works inconsistently, because the second of the two addresses (the ecp address) seems to be different places in the binary data on different systems, and I can't figure out the pattern. This is at least a start. Any advice on fixing it (or making it work on systems with more than one port) would be welcome.

I've now figured out (I think) how to find the port addresses for a system with one parallel port. What I can't figure out (because I have only parallel port on my system) is how to make it work on a system with two or three (or more) parallel ports - though I only need to test LPT1 through LPT3. Here is my very messy and amateurish code as it stands now. Any help that anyone can give on making it find addresses for more than one port would be very good to have!

; get port addresses for a printer port

#include <Constants.au3>

Dim $outString, $regData, $line, $startString, $addNum, $winOS
Dim $regDigits, $byte1, $byte2, $byte3, $byte4
Dim $objItem, $devName, $devID

$wbemFlagReturnImmediately = 0x10
$wbemFlagForwardOnly = 0x20
$colItems = ""
$strComputer = "localhost"

$OutputTitle = ""
$Output = ""
$OutputTitle &= "Computer: " & $strComputer & @CRLF
$objWMIService = ObjGet("winmgmts:" & $strComputer & "rootCIMV2")
$colItems = $objWMIService.ExecQuery("SELECT * FROM Win32_ParallelPort", "WQL", _
$wbemFlagReturnImmediately + $wbemFlagForwardOnly)

If IsObj($colItems) Then
Local $Object_Flag = 0
For $objItem In $colItems
$Object_Flag = 1
$devName = $objItem.Name
$devID = $objItem.PNPDeviceID
Next
EndIf

$regData = Run(@ComSpec & ' /c reg query "HKLMSYSTEMCurrentControlSetEnum' & $devID _
& 'Control" /v AllocConfig', @SystemDir, @SW_HIDE, $STDERR_CHILD + $STDOUT_CHILD)

$outString = ""
While 1
$line = StdoutRead($regData)
If @error Then ExitLoop
$outString = $outString & $line
WEnd
;~ While 1
;~   $line = StderrRead($regdata)
;~   If @error Then ExitLoop
;~ $errString = $line
;~ WEnd

; MsgBox(0,'', $outString)
$file = FileOpen("d:temp.txt", 2)
FileWrite($file, $outString)
FileClose($file)

$startString = (StringInStr($outString, "0100"))
$regDigits = StringTrimLeft($outString, Int($startString))

$byte1 = StringMid($regDigits, 50, 2)
$byte2 = StringMid($regDigits, 48, 2)

;~ $winOS = @OSVersion
;~ If ($winOS = "WIN_XP") OR ($winOS = "WIN_XPe") Then
;~ $byte3num = 82
;~ $byte4num = 80
;~ Else
;~ $byte3num = 82
;~ $byte4num = 80
;~ EndIf
;~ ; MsgBox(0,'', $winOS)

$byte3num = 82
$byte4num = 80


$byte3 = StringMid($regDigits, $byte3num, 2)
$byte4 = StringMid($regDigits, $byte4num, 2)

MsgBox(0, "", $devName & " addresses: " & $byte1 & $byte2 & " " & $byte3 & $byte4)
Edited by emendelson

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

×