emendelson Posted September 30, 2012 Share Posted September 30, 2012 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. Link to comment Share on other sites More sharing options...
water Posted September 30, 2012 Share Posted September 30, 2012 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 (NEW 2022-02-19 - Version 1.6.1.0) - Download - General Help & Support - Example Scripts - WikiExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example ScriptsOutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - WikiOutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - DownloadOutlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - WikiPowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - WikiTask Scheduler (NEW 2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki Standard UDFs:Excel - Example Scripts - WikiWord - Wiki Tutorials:ADO - WikiWebDriver - Wiki Link to comment Share on other sites More sharing options...
emendelson Posted September 30, 2012 Author Share Posted September 30, 2012 (edited) 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&0That's easy to translate into a read-registry call to:HKEY_LOCAL_MACHINESYSTEMCurrentControlSetEnumACPIPNP04014&1fe41ac6&0Controlwhich contains the keyAllocConfigNow, 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: Edited September 30, 2012 by emendelson Link to comment Share on other sites More sharing options...
water Posted September 30, 2012 Share Posted September 30, 2012 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 (NEW 2022-02-19 - Version 1.6.1.0) - Download - General Help & Support - Example Scripts - WikiExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example ScriptsOutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - WikiOutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - DownloadOutlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - WikiPowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - WikiTask Scheduler (NEW 2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki Standard UDFs:Excel - Example Scripts - WikiWord - Wiki Tutorials:ADO - WikiWebDriver - Wiki Link to comment Share on other sites More sharing options...
emendelson Posted September 30, 2012 Author Share Posted September 30, 2012 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! Link to comment Share on other sites More sharing options...
water Posted September 30, 2012 Share Posted September 30, 2012 Glad to be of service My UDFs and Tutorials: Spoiler UDFs:Active Directory (NEW 2022-02-19 - Version 1.6.1.0) - Download - General Help & Support - Example Scripts - WikiExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example ScriptsOutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - WikiOutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - DownloadOutlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - WikiPowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - WikiTask Scheduler (NEW 2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki Standard UDFs:Excel - Example Scripts - WikiWord - Wiki Tutorials:ADO - WikiWebDriver - Wiki Link to comment Share on other sites More sharing options...
emendelson Posted September 30, 2012 Author Share Posted September 30, 2012 (edited) 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!expandcollapse popup; 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 October 1, 2012 by emendelson Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now