[Tutor] Linear programming - is it bad?

Danny Yoo dyoo at hkn.eecs.berkeley.edu
Tue Aug 10 02:22:21 CEST 2004



> We can capture the thing that's pretty constant within all those blocks as
> a function.  Something like:
>
> ###
> def queryForValue(reg, name):
>     try:
>         values = QueryValueEx(reg, name)
>         return values[0]
>     except WindowsError:
>         print "Error:", name, "string missing from registry:",
>         print "creating an empty string."
>         nothing = SetValueEx(reg,name,0,REG_SZ,"0")
>         return "0"
> ###


Hi Eric,


Ack!  I didn't see that the default values for all but the AutoAdminLogon
were the empty string, and not zero.  Let me fix this.

###
def queryForValue(reg, name, defaultValue=""):
    try:
        values = QueryValueEx(reg, name)
        return values[0]
    except WindowsError:
        print "Error:", name, "string missing from registry:",
        print "creating default value:", defaultValue
        nothing = SetValueEx(reg, name, 0, REG_SZ, defaultValue)
        return "0"

regusername = queryForValue(reg, "DefaultUserName")
regusername = queryForValue(reg, "DefaultUserName")
regpassword = queryForValue(reg, "DefaultPassword")
regdomain = queryForValue(reg, "DefaultDomainName")
regautolog = queryForValue(reg, "AutoAdminLogon", "0")
###

Sorry for goofing up like that; I should have paid closer attention to
your code.



More information about the Tutor mailing list