Sign in to follow this  
Followers 0
ksmith247

Still a n00b

7 posts in this topic

I feel pretty dumb posting such a simple script but damned if I can make it work.

$Path = "C:\Patches"
$reg = "HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\"

If Not FileExists(RegRead($reg & "KB925902", "")) Then
    RunWait(@ComSpec & " /c " & $Path & "\17\WindowsXP-KB925902-x86-ENU.exe /quiet /passive /norestart")
EndIf

If Not FileExists(RegRead($reg & "KB931261", "")) Then
    RunWait(@ComSpec & " /c " & $Path & "\19\WindowsXP-KB931261-x86-ENU.exe /quiet /passive /norestart")
EndIf

...etc. There are a few other patches but you get the idea. The problem is I can't get it to NOT run. I am trying to avoid reinstalling the patches on previously patched machines. I started using c:\windows\$NtUninstallKB925902$ (for example) but that wouldn't work. Thinking it was an issue reading the hidden folders I moved on to using the registry.

I am missing something simple here and as long as you are willing to help I will take any and all flames. :)


Support bacteria; it's the only culture most people have.LxP's Learning to Script with AutoIt 3 - Excellent starting placeVolly's Links Page - Links to cool and useful scriptsAutoIt Wrappers - Valuater's AutoIt Wrappers post. Lots of good stuff.Support AutoIt - Make a donation here; I did.[size="2"]#include <Guinness.pint>[/size]

Share this post


Link to post
Share on other sites



$Path = "C:\Patches"
$reg = "HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\"
$testKB925902 = StringTrimRight(StringTrimLeft(RegRead($reg & "KB925902", "UninstallString"), 1), 1)
$testKB931261 = StringTrimRight(StringTrimLeft(RegRead($reg & "KB931261", "UninstallString"), 1), 1)
If Not FileExists($testKB925902) Then
    RunWait(@ComSpec & " /c " & $Path & "\17\WindowsXP-KB925902-x86-ENU.exe /quiet /passive /norestart")
EndIf

If Not FileExists($testKB931261) Then
    RunWait(@ComSpec & " /c " & $Path & "\19\WindowsXP-KB931261-x86-ENU.exe /quiet /passive /norestart")
EndIf

That should do what you want

Share this post


Link to post
Share on other sites

OR

$Path = "C:\Patches"
$reg = "HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\"
$value = "UninstallString"
RegRead($reg & "KB925902", $value)
If @error <> 0 Then
    RunWait(@ComSpec & " /c " & $Path & "\17\WindowsXP-KB925902-x86-ENU.exe /quiet /passive /norestart")
EndIf
RegRead($reg & "KB931261", $value)
If @error <> 0 Then
    RunWait(@ComSpec & " /c " & $Path & "\19\WindowsXP-KB931261-x86-ENU.exe /quiet /passive /norestart")
EndIf

But I like the first one better, just in case the @error is set by anything else

Share this post


Link to post
Share on other sites

Thanks danwilli. I will give that a go. Any thoughts on why the original code would not work? It seemed pretty foolproof to me. I had never seen stringtrim before (learn something new every day). From what I can see you are removing the " from the beginning and end of the UninstallString value. Why would that matter?


Support bacteria; it's the only culture most people have.LxP's Learning to Script with AutoIt 3 - Excellent starting placeVolly's Links Page - Links to cool and useful scriptsAutoIt Wrappers - Valuater's AutoIt Wrappers post. Lots of good stuff.Support AutoIt - Make a donation here; I did.[size="2"]#include <Guinness.pint>[/size]

Share this post


Link to post
Share on other sites

The reason it didn't work is because you were reading the Default value of the keys, which is generally blank. Thus, in your conditional statement, you were effectively saying "If {blank file name} doesn't exist then...". FileExists("") = False, and that is why your RunWait commands always ran.

For example:

if Not FileExists("") Then
    MsgBox(0, "debug", "Hi there.")
EndIf

will show the messagebox.

This is a case where using the debug commands in Scite to test the value of the registry key you were reading would have helped. Debugging to console has shown me lots of times that what I think I'm doing isn't really what I am doing! :)


BlueBearrOddly enough, this is what I do for fun.

Share this post


Link to post
Share on other sites

Ahhh... Ok. In my mind I was looking for the existence of the key, not reading a value but the "" was reading the actual value of default. RTFM.

For future reference is there a way to look for the existence of a key?


Support bacteria; it's the only culture most people have.LxP's Learning to Script with AutoIt 3 - Excellent starting placeVolly's Links Page - Links to cool and useful scriptsAutoIt Wrappers - Valuater's AutoIt Wrappers post. Lots of good stuff.Support AutoIt - Make a donation here; I did.[size="2"]#include <Guinness.pint>[/size]

Share this post


Link to post
Share on other sites

#7 ·  Posted (edited)

You can test @error - it will equal 1 if the key doesn't exist. Here is an example:

$test1 = RegRead("HKLM\Software\Microsoft", "")
ConsoleWrite('Test 1 = "' & $test1 & '"; Test1 @error = ' & @error & @LF)
$test2 = RegRead("HKLM\Software\SomeNonexistentComputerCompany", "")
ConsoleWrite('Test 2 = "' & $test2 & '"; Test2 @error = ' & @error & @LF)

This returns this result (in the Scite console):

Test 1 = ""; Test1 @error = -1

Test 2 = ""; Test2 @error = 1

Edited by bluebearr

BlueBearrOddly enough, this is what I do for fun.

Share this post


Link to post
Share on other sites

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 account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0