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...
Boo.
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
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










face if I were. I'm just disappointed. 


