Page 1 of 1 1
Topic Options
#193091 - 2009-03-23 08:50 PM Uninstalling Limewire - First Script
erikpd Offline
Fresh Scripter

Registered: 2009-03-17
Posts: 5
Loc: Washington, DC
Hello, I am completely new to scripting, however I am trying to write uninstall scripts to run out of Desktop Authority for my workplace. After doing as much reading as I could I took a crack at one and would like to know if I did correctly even on the most remedial level. I used Kixtarter v4.10.0 to write it. I basically followed the initial prompts in Kixtarter and then coded what I thought I'd need. The script is below:

;*************************************************************************
; Script Name: Limewire Removal
; Author: Erik Dunbar
; Date: 3/23/2009
; Description:
;*************************************************************************

;Script Options
$SO=SETOPTION("Explicit", "ON")
$SO=SETOPTION("NoMacrosInStrings", "ON")
$SO=SETOPTION("NoVarsInStrings", "ON")
BREAK ON

Shell "C:\Program Files\LimeWire\uninstall.exe"
$=SetFocus ("LimeWire 5.1.2 Uninstall")
$=SendKeys (N)
$=SendKeys (U)
$=SendKeys (F)

Top
#193092 - 2009-03-23 09:08 PM Re: Uninstalling Limewire - First Script [Re: erikpd]
Glenn Barnas Administrator Offline
KiX Supporter
*****

Registered: 2003-01-28
Posts: 4396
Loc: New Jersey
Welcome!

Seems like it will work OK.. Couple of comments that will make future scripting a tad smoother..

"SendKeys" is a function. There should not be a space between the function name and the "(". Kix is forgiving, but other languages aren't, so it's better to be a bit more strict when you're learning. Compare the SendKeys and SETOPTION lines.

"C:\Program Files" should (like many other system parameters) be referred to by the appropriate system variable - "%PROGRAMFILES%\path..." - this will work anywhere..

My personal preference - use single quotes in Kix - makes it easier to embed double quotes into Shell commands, since DOS commands require double quotes.

Be consistent in how you specific commands / functions..
thiscommand / thatfunction
ThisCommand / ThatFunction
THISCOMMAND / THATFUNCTION

It's all about readability. I even ID my varnames - $LocalVar vs $GLOBALVAR vs $_FunctionVar.

Break on might come first, right after what Lonk refers to as "the mumble" - the things you write at the top to ID your script/author/version etc.. ;\)

Glenn

PS - you'd get a passing grade in my class - these are minor things - more suggestions to develop your own style, which will help you to read and support them in the future.
_________________________
Actually I am a Rocket Scientist! \:D

Top
#193120 - 2009-03-24 02:27 PM Re: Uninstalling Limewire - First Script [Re: Glenn Barnas]
erikpd Offline
Fresh Scripter

Registered: 2009-03-17
Posts: 5
Loc: Washington, DC
Hi Glenn,

Thanks for the reply and helpful advice. I am having a couple additional problems though. Using the Debug feature in Kixtarter I ran the script normally. It launches the uninstall wizard and sets the focus, but then I get an error. I believe I'm doing something wrong in the SendKeys coding. As a test I wrote a quick script tht would launch notepad and send some keystrokes to see if they type out, but that didn't work either. The error reads as follows:

ERROR: undefined variable []!
Script C:\DAToolKit\Limewire Removal.kix
Line : 15

My SendKeys coding looks like this:

$=SendKeys(N)
$=SendKeys(U)
$=SendKeys(F)

I've also tried some variations with ENTER, and not capitalizing the key I send. I'm stumped, any thoughts? Thanks!

Erik

Top
#193121 - 2009-03-24 02:43 PM Re: Uninstalling Limewire - First Script [Re: erikpd]
Glenn Barnas Administrator Offline
KiX Supporter
*****

Registered: 2003-01-28
Posts: 4396
Loc: New Jersey
Ah - missed that.

When you use "$" as a var and an error occurs, the var-name is blank!

You did not DIM the $ var prior to the first SendKeys call. Also, you should place the characters you're sending inside of quotes, since they are strings.

Since both vars are used to capture the Return Code and will not be examined, I'd use a generic $RC for both of them - just Dim it first!

Glenn
_________________________
Actually I am a Rocket Scientist! \:D

Top
#193137 - 2009-03-24 11:52 PM Re: Uninstalling Limewire - First Script [Re: Glenn Barnas]
NTDOC Administrator Offline
Administrator
*****

Registered: 2000-07-28
Posts: 11623
Loc: CA
The user can very easily stop, or prevent this type of script from working correctly. You would probably be better off creating your own uninstaller that removes the data and registry entries on your own that way a user could not easily stop it.
Top
#193138 - 2009-03-25 01:16 AM Re: Uninstalling Limewire - First Script [Re: NTDOC]
Glenn Barnas Administrator Offline
KiX Supporter
*****

Registered: 2003-01-28
Posts: 4396
Loc: New Jersey
Yup, but baby steps, Doc.. ;\)

"First script", so let's get it working, and then work on making it better, bullet-um-resistant, and robust.

G-
_________________________
Actually I am a Rocket Scientist! \:D

Top
#193188 - 2009-03-26 05:49 PM Re: Uninstalling Limewire - First Script [Re: Glenn Barnas]
erikpd Offline
Fresh Scripter

Registered: 2009-03-17
Posts: 5
Loc: Washington, DC
Hi Guys,

I spent a couple of days researching the Dim command, and have come to one blatant conclusion, I'm in way over my head! \:\) Seriously though I just don't get it. I admit I have never had any formal training in programming, so I don't have the "vocabulary" to speak about it intelligently.

Glenn, to address the Dim command, the program I wrote, with modifications as suggested (at least the ones I understood), is below. I do want to say though that I'm not trying to get anyone to do my homework, I'm just trying to get a grasp for this stuff.

Doc, as for what you suggested about user interruption, I don't think that will be a concern. I intend to run this script from ScriptLogic, and I have the options to hide the screen output. Our user's are pretty well trained so they won't even touch the computer until that logon script completes. In short, they won't be the wiser or even have the ability to interrupt it. Obviously I intend to do considerable testing of any of these scripts I write before I implement them system-wide though.

I know from my research that my uninstall script is pretty novice by the other examples I've seen out there, but for me as long as it accomplishes the goal I'll be satisfied with that.

As mentioned, my code is below. Please tell me where I'm screwing up and I'll get it right. It's still on the SendKeys functions that are tripping me up. Thanks!

;Script Options
$SO=SETOPTION("Explicit", "ON")
$SO=SETOPTION("NoMacrosInStrings", "ON")
$SO=SETOPTION("NoVarsInStrings", "ON")
BREAK ON

Shell '%PROGRAMFILES%\Limewire\uninstall.exe'
Do Sleep 1 Until $=SetFocus('LimeWire') = 0
DIM $RC
$RC=SendKeys('N')
$RC=SendKeys('U')
$RC=SendKeys('F')

Top
#193189 - 2009-03-26 06:03 PM Re: Uninstalling Limewire - First Script [Re: erikpd]
Lonkero Administrator Offline
KiX Master Guru
*****

Registered: 2001-06-05
Posts: 22346
Loc: OK
$=SetFocus
_________________________
!

download KiXnet

Top
#193191 - 2009-03-26 06:57 PM Re: Uninstalling Limewire - First Script [Re: Lonkero]
Glenn Barnas Administrator Offline
KiX Supporter
*****

Registered: 2003-01-28
Posts: 4396
Loc: New Jersey
CODE TAGS!!! ;\)

[ code ] your code goes here... [ /code ] <- but no spaces in the tags!

 Code:
; my prog - what it does
; date - me!

BREAK ON

; Declare variables first
Dim $Rc                   ; Used to trap return codes
Dim $Cmd                  ; command string used for SHELL

; set Script Options to enforce good habits
$Rc = SetOption("Explicit", "ON")
$Rc = SetOption("NoMacrosInStrings", "ON")
$Rc = SetOption("NoVarsInStrings", "ON")

; launch the uninstaller
$Cmd = '%PROGRAMFILES%\Limewire\uninstall.exe'
'Running ' $Cmd ?
Shell $Cmd

; wait for the window to open and then set focus
Do
  Sleep 1
Until SetFocus('LimeWire') = 0
; Can't use $=Setfocus() = 0 - you either assign the var, or test the result
; Classik Koding:
; LVal = RVal
;  where RVal is a value, variable, or result of a function
; RVal is processed first and the result assigned to LVal

; send keystrokes to the active program
$Rc = SendKeys('N')
$Rc = SendKeys('U')
$Rc = SendKeys('F') 

See the comments to explain Lonk's typically terse response. ;\) \:D

Glenn
_________________________
Actually I am a Rocket Scientist! \:D

Top
#193193 - 2009-03-26 07:04 PM Re: Uninstalling Limewire - First Script [Re: Glenn Barnas]
Glenn Barnas Administrator Offline
KiX Supporter
*****

Registered: 2003-01-28
Posts: 4396
Loc: New Jersey
BTW - this is very basic. You should probably check for errors launching the uninstaller command, and the loop will wait forever. You might want to terminate the loop after some period if it doesn't launch. Something like:
 Code:
$TimeToDie = @TICKS + 60000 ; 60 seconds from now
While @TICKS < $TimeToDie And SetFocus('Limewire')
  Sleep 1
Loop
If @TICKS > $TimeToDie
  'failed to launch uninstaller!' ?
  Exit 1
EndIf
This adds 60,000 msecs to the current TICKS value (# of ms since system boot). When the TICKS exceeds the TimeToDie, the loop ends. If Ticks exceeds TimeToDie after the loop, we know it failed, so announce the failure and die. Otherwise, send the keystrokes and uninstall the puppy.

These are things that will make your script more robuse, and more tolerant of unattended operation. They aren't requirements for basic testing.

Glenn
_________________________
Actually I am a Rocket Scientist! \:D

Top
#193194 - 2009-03-26 07:05 PM Re: Uninstalling Limewire - First Script [Re: Glenn Barnas]
Allen Administrator Online   shocked
KiX Supporter
*****

Registered: 2003-04-19
Posts: 4545
Loc: USA
LOL...

 Quote:
; date - me!


I knew the korg was a lot of things.... but a hook up site?

Top
#193195 - 2009-03-26 07:06 PM Re: Uninstalling Limewire - First Script [Re: Allen]
Glenn Barnas Administrator Offline
KiX Supporter
*****

Registered: 2003-01-28
Posts: 4396
Loc: New Jersey
So much for geek humor..
_________________________
Actually I am a Rocket Scientist! \:D

Top
#193196 - 2009-03-26 07:13 PM Re: Uninstalling Limewire - First Script [Re: Glenn Barnas]
Allen Administrator Online   shocked
KiX Supporter
*****

Registered: 2003-04-19
Posts: 4545
Loc: USA
Your most concise response thus far... ;\)
Top
#193197 - 2009-03-26 07:14 PM Re: Uninstalling Limewire - First Script [Re: Allen]
Glenn Barnas Administrator Offline
KiX Supporter
*****

Registered: 2003-01-28
Posts: 4396
Loc: New Jersey
terse, actually. ;\)
_________________________
Actually I am a Rocket Scientist! \:D

Top
#193199 - 2009-03-26 08:37 PM Re: Uninstalling Limewire - First Script [Re: Glenn Barnas]
erikpd Offline
Fresh Scripter

Registered: 2009-03-17
Posts: 5
Loc: Washington, DC
Thanks for all that help, and for providing all the code. I followed all your instructions and now it works great!

However, just for fun and my own education I went back to my original code and made a couple of edits just to see for myself how far off I really was. Below is what I came up with. And it works as it should, the uninstaller runs successfully and closes itself at the end. (I even got my code tags in there this time Glenn \:\) )

 Code:
;*************************************************************************
;  Script Name:   Limewire 5.1.2 Removal
;  Author:        Erik Dunbar
;  Date:          3/23/2009
;  Description:   Script to silently automate the uninstall wizard of Limewire. Should prevent user interaction.
;*************************************************************************
 
DIM $Rc

;Script Options
$SO=SETOPTION("Explicit", "ON")
$SO=SETOPTION("NoMacrosInStrings", "ON")
$SO=SETOPTION("NoVarsInStrings", "ON")
BREAK ON

Shell "%PROGRAMFILES%\Limewire\uninstall.exe"
Do Sleep 1 Until SetFocus("LimeWire 5.1.2 Uninstall") = 0
$Rc=SendKeys(N)
$Rc=SendKeys(U)
Sleep 2
$Rc=SendKeys(F)


Although I think I understand why the additional coding and formatting are necessary. It's for clarity and error checking right?

One of the ones I don't fully get is the Dim $Cmd part. Is it bad to just run the SHELL command as I did in my inital coding?

The $TimeToDie command is really cool, I just tested that. That will come in really handy as I test the broader implementation.

I also noticed you inserted spaces around the '=' in the code, again just a clarity thing?

Lastly, below is the final code I was planning on using. I hope it meets with approval! Any comments please let me know, this has been a lot of fun so far.

 Code:
;*************************************************************************
;  Script Name:   Limewire 5.1.2 Removal
;  Author:        Erik Dunbar
;  Date:          3/23/2009
;  Description:   Script to silently automate the uninstall wizard of Limewire. Should prevent user interaction.
;*************************************************************************
 
BREAK ON

; Declare variables first
Dim $Rc                   ; Used to trap return codes
Dim $Cmd                  ; command string used for SHELL
$TimeToDie = @TICKS + 60000 ; 60 seconds from now

; set Script Options to enforce good habits
$Rc = SetOption("Explicit", "ON")
$Rc = SetOption("NoMacrosInStrings", "ON")
$Rc = SetOption("NoVarsInStrings", "ON")

; launch the uninstaller
$Cmd = '%PROGRAMFILES%\Limewire\uninstall.exe'
'Running ' $Cmd ?
Shell $Cmd

While @TICKS < $TimeToDie And SetFocus('Limewire')
  Sleep 1
Loop
If @TICKS > $TimeToDie
  'failed to launch uninstaller!' ?
  Exit 1
EndIf

; send keystrokes to the active program
$Rc = SendKeys('N')
$Rc = SendKeys('U')
Sleep 2
$Rc = SendKeys('F')

Top
#193202 - 2009-03-26 08:52 PM Re: Uninstalling Limewire - First Script [Re: erikpd]
Glenn Barnas Administrator Offline
KiX Supporter
*****

Registered: 2003-01-28
Posts: 4396
Loc: New Jersey
It's really a matter of personal style.

Some young guys who still have good vision (only been staring at a monitor for 4-5 years, not 34 like me!) don't use spaces between the operators. For me, it helps keep the lines from running together. Also, the breaks allow me to double-click select a specific word and not a whole block.

I prefer the $Cmd = 'command string' for two reasons. For complex commands, I can "build" the string in small chunks, making it less error prone (especially when there's lots of quotes or parens). It also - as you saw - lets me display the command before it runs so I can make sure it's correct. I often comment-out the display of the $Cmd once I have it running properly.
 Code:
$Cmd='%COMSPEC% /c'
$Cmd = $Cmd + ' command'
$Cmd = $Cmd + ' arg "arg 2"'
for example.


Please test the TimeToDie logic thoroughly.. I threw that together without any testing based on something I use, but don't have access to right now.

The $SO and $RC in your original code serve the same purpose, so no need to define/use 2 different vars.. just a "sanity" thing. I'm also big on comments. A typical larger project has nearly a 1:1 ratio between comments and code.

Lastly, it won't make a huge difference, but I'd set the $TimeToDie value just before you begin the loop waiting for the command to launch, not before you launch the command. Otherwise you shortchange yourself a few milliseconds. ;\)

Glenn
_________________________
Actually I am a Rocket Scientist! \:D

Top
#196247 - 2009-10-05 02:54 AM Re: Uninstalling Limewire - First Script [Re: Glenn Barnas]
ADynes Offline
Starting to like KiXtart
*****

Registered: 2003-10-31
Posts: 184
Loc: Ohio
I know this is a old thread but I wrote a VB.net program and one of it's functions is to pull a "uninstall" list file off the server at start up, check for the existence of any app in the list in the uninstall registry key, then use that information to execute msiexec.exe with the GUID and the uninstall string along with the silent option. Works great. Pseudo code:

Get name of app to uninstall
Get a array of all the keys under HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall
Once you have the array check each key's "DisplayName" and see if it matches the app to uninstall
Once found get "UninstallString" string from that key
Execute the uninstall string. Tack on a "/quiet" to the end if needed.

I have this in a little VB function so I just pass a program name (entry as it appears in Add/Remove programs) to it and it uninstalls it. Pretty helpful.

-Allan
_________________________
Kixtarter - KiXtart Script Editor
http://www.AllanDynes.com/

Top
Page 1 of 1 1


Moderator:  Jochen, Allen, Radimus, Glenn Barnas, ShaneEP, Ruud van Velsen, Arend_, Mart 
Hop to:
Shout Box

Who's Online
1 registered (Allen) and 382 anonymous users online.
Newest Members
gespanntleuchten, DaveatAdvanced, Paulo_Alves, UsTaaa, xxJJxx
17864 Registered Users

Generated in 0.067 seconds in which 0.022 seconds were spent on a total of 13 queries. Zlib compression enabled.

Search the board with:
superb Board Search
or try with google:
Google
Web kixtart.org