topbanner_forum
  *

avatar image

Welcome, Guest. Please login or register.
Did you miss your activation email?

Login with username, password and session length
  • Friday April 19, 2024, 5:11 pm
  • Proudly celebrating 15+ years online.
  • Donate now to become a lifetime supporting member of the site and get a non-expiring license key for all of our programs.
  • donate

Author Topic: AutoHotKey SUCKS! --- Or at least I can't make it work  (Read 8497 times)

Rover

  • Master of Smilies
  • Charter Member
  • Joined in 2005
  • ***
  • Posts: 632
    • View Profile
    • Donate to Member
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.
Insert Brilliant Sig line here

jgpaiva

  • Global Moderator
  • Joined in 2006
  • *****
  • Posts: 4,727
    • View Profile
    • Donate to Member
Re: AutoHotKey SUCKS! --- Or at least I can't make it work
« Reply #1 on: May 31, 2006, 07:30 PM »
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

  • Master of Smilies
  • Charter Member
  • Joined in 2005
  • ***
  • Posts: 632
    • View Profile
    • Donate to Member
Re: AutoHotKey SUCKS! --- Or at least I can't make it work
« Reply #2 on: May 31, 2006, 07:54 PM »
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
Insert Brilliant Sig line here

rjbull

  • Charter Member
  • Joined in 2005
  • ***
  • default avatar
  • Posts: 3,199
    • View Profile
    • Donate to Member
Re: AutoHotKey SUCKS! --- Or at least I can't make it work
« Reply #3 on: June 01, 2006, 05:12 AM »
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.

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

  • Charter Member
  • Joined in 2006
  • ***
  • Posts: 1,837
    • View Profile
    • Donate to Member
Re: AutoHotKey SUCKS! --- Or at least I can't make it work
« Reply #4 on: June 01, 2006, 05:34 AM »
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.

rjbull

  • Charter Member
  • Joined in 2005
  • ***
  • default avatar
  • Posts: 3,199
    • View Profile
    • Donate to Member
Re: AutoHotKey SUCKS! --- Or at least I can't make it work
« Reply #5 on: June 01, 2006, 06:05 AM »
I'd say AWK has been superseeded by perl.

I know that Perl is now much more trendy, but, as I see it, AWK is simpler, and as long as it does what you need, it's easier to learn and quicker to be productive with.

I agree that debugging AHK is difficult.

Thompson Automation's AWK comes with a debugger - written in Thomson Automation AWK   :o

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.

I don't disagree, but the remarkable thing is just how many (vaguely) similar macro-type automation programs there are for Windows.  AutoIt, AHK, Macro Express, PowerPro, Macro Tools Works, the new version of PTFB, AceMacro, Keytext... the list goes on and on.

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.

AWK seems really designed for serial input, one line equals one record.  You can use getline calls to read other files, but if you need to access several files at one time, maybe Perl is better.


Gerome

  • Charter Honorary Member
  • Joined in 2006
  • ***
  • Posts: 154
    • View Profile
    • Get my Freestyle Basic Script Language + compiler!
    • Donate to Member
Re: AutoHotKey SUCKS! --- Or at least I can't make it work
« Reply #6 on: June 05, 2006, 10:01 AM »
Try FBSL, it'll be for sure easier at this kinda stuff
Yours,
(¯`·._.·[Gerome GUILLEMIN]·._.·´¯)
http://www.fbsl.net [FBSL Author]
http://gedd123.free.fr/FBSLv3.zip [FBSL Help file]
(¯`·._.·[If you need help... just ask]·._.·´¯)