ATTENTION: You are viewing a page formatted for mobile devices; to view the full web page, click HERE.

Other Software > Developer's Corner

AutoHotKey SUCKS! --- Or at least I can't make it work

(1/2) > >>

Rover:
Alright AHK fans, I tried, I really did.  I used Autoit 2.0 for automating some stuff a few years ago.  When I saw some of the cool things going on around DC with AHK, I thought I'd try to solve my little problem using it.
I am now going to have to rewrite it, in something a little more .... reliable, documented, debuggable!

All I wanted to do was parse a few strings, do some case statements and exec a couple of apps with parameters. 

Here is the actual, psudocode spec: 

Execute ipconfig | find "IP Address" > c:\ipaddr.txt
Execute %cmdspec$ /c type c:\zenworks\smbiosdump.log | find "Serial Numer" > c:\serno.txt

Read the first line of c:\ipaddr.txt  (IP Address .......... :  10.91.185.20)
Extract the 3'rd octet (185 in this case)

Read the first line of c:\serno.txt   (Serial Number:               'BX43299')
Extract the Serial Number (sans single quotes)

Based on the ip address 3'rd octet, assign a 3 letter building code
IP 182 -185 Code = MSW
IP 187 -189 Code = MSS
etc.

Use the Code and IP to create a unique PC name:
PCNAME=MSW-BX43299

Using that name execute a few commands
exec c:\program files\zenworks\zwsreg -unreg
exec c:\program files\zenworks\zwsreg -workstation PCNAME
exec c:\windows\system32\wsname.exe /N:PCNAME
exec c:\windows\system32\ipconfig /registerdns


THAT'S IT.  No Earth shattering discoveries here.  I will paste my final attempt at AHK for you review.  You can correct my thinking, etc.  I have moved on.  For the record, this is the butchered version that I was debugging with.  I finally gave up on trying to exec the first 2 commands from within AHK and created a 2 line .cmd file to deal with it.  The Run/Runwait commands WOULD NOT execute these statements.  Grrr...

Here's the ugly code
--- ---FileReadLine, ipline, C:\ipaddr.txt, 1
FileReadLine, sernoline, C:\SerNo.txt, 1

; I don't think any of this part works. 
; Stupid ass way to run functions... what's wrong with ipaddr := stringtrimleft, ipaddr, pos

colon := ":"
StringGetPos, pos, ipline, %colon% ; started as IP Address ....: 10.91.10.20
StringTrimLeft,ipaddr,ipline,%pos% ; should leave 10.91.10.20

StringGetPos, pos, ipaddr, .   ; should find the first .
StringTrimLeft,ipline,ipaddr,%pos% ; and leave 91.10.20
StringTrimLeft,ipaddr, ipline, 1

StringGetPos, pos, ipaddr, .   
StringTrimLeft,ipline,ipaddr,pos   ; leaving 10.20
StringTrimLeft,ipaddr,ipline,1

StringGetPos, pos, ipaddr, .   ; find the .
StringLeft,ipline,ipaddr,%pos%     ; copy from left ... 10.
StringLeft,ipaddr,ipline,1
StringTrimRight,locationkey,ipaddr,1  ; kill the . leaving 10 in locatinkey

location := "none"
if locationkey between 213 and 215 location := "mse"
if locationkey between 217 and 219 location := "mss"
if locationkey between 209 and 211 location := "msw"
if locationkey between 233 and 235 location := "bes"
if locationkey between 221 and 223 location := "ges"
if locationkey between 229 and 231 location := "hes"
if locationkey between 225 and 227 location := "jes"
if locationkey between 237 and 239 location := "res"
if locationkey between 181 and 183 location := "les"
if location = "none" location := "lhs".

; can't get the damn thing to trim the crap before the  first '

StringGetPos, pos, sernoline, '
StringTrimLeft, serno, sernoline, %pos%
StringTrimRight, sernol, serno, 1
StringTrimLeft, serno, sernol, 1

sernolen := strlen(serno)
if (sernolen < 5) {
msgbox "Invalid Serial Number"
exit 1
}

wsname := location . "-" . serno
; insert high quality debugging device
msgbox %wsname%
runwait, c:\program files\novell\zenworks\zwsreg.exe -unreg, ,hide
runwait, c:\program files\novell\zenworks\zwsreg.exe -workstation %wsname%, ,hide
runwait, c:\windows\system32\wsname.exe /N:%wsname%, ,hide
runwait, c:\windows\system32\ipconfig /registerdns, ,hide




 :down: :down: :down: Boo.

jgpaiva:
Damn rover.. You don't sound very happy  :(
Parsing stuff in ahk isn't easy. Command line interaction isn't either.

But you code looks almost complete.
I can't do it right now (i'm too sleepy, it'd take me the whole night), but in the morning, i hope i can read what you've made.

(maybe you could post at the forums of ahk, there's more skilled people there)

Rover:
I should probably state for the record, I'm not terribly upset or unhappy.... I would have used my  :mad: face if I were.  I'm just disappointed.  :-\

I'm in the process of writing this in the manly language of Pascal, becuase 1) I know it well, and 2) I'll be done it another 20 mins or so. 

I'd pick another language, like Ruby or Python to experiment with, but this is for a real job and I need it compiled.  It will run on ~3,000 PC's as they get re-imaged this month.

I am willing to review and discuss the AHK code for better enlightenment of the group  :P

rjbull:
I'm in the process of writing this in the manly language of Pascal

[...]

I'd pick another language, like Ruby or Python to experiment with, but this is for a real job and I need it compiled.
-Rover (May 31, 2006, 07:54 PM)
--- End quote ---

For parsing command lines, my first thought would be AWK, made for the job and readily available in numerous free implementations.  AWK has been a very useful tool for me.  If you really need it compiled, though, your options are relatively limited, as most versions are interpreters (run with a batch file?).  Nonetheless Thompson Automation Software make a compilable AWK, though they don't actively sell it any more (it isn't clear whether they passively sell it, as it were).  Mortice Kern Systems (MKS) also sell a compilable AWK.  More on the AWK faq and good quick introduction and links at Eric Pement's AWK page


urlwolf:
I'd say AWK has been superseeded by perl. ActiveState has a distribution for win that may have a perl2exe component, can't remember.

I agree that debugging AHK is difficult. It really feels like a hack that should have been created by the people that created the OS, not reverse-engineered by a group of brave programmers. Considering how we get info (e.g., windows spy), and how inconsistent windows applications are (e.g., naming windows, responding to actions, etc), it is almost a miracle that AHK exists. And it is difficult to debug, of course.

But for your task, I'd take perl. You are basically doing system calls to other processes and pasting their output together by reading particular parts of files. That's what perl was created for.

Navigation

[0] Message Index

[#] Next page

Go to full version