Enable input language programatically on Windows 7

785 views Asked by At

I'm writing a windows installer for an application that depends on spanish input language being enabled which is not default on Windows 7. Is there a way I can programatically detect if Spanish input language is enabled on the host machine running Win 7 and enable it if it's not?

2

There are 2 answers

0
Michael On

You may read the default or set as default a language through Windows registry, here is the link to the key and the language codes: http://www.windowsitpro.com/article/configuration/where-in-the-registry-is-the-language-setting-for-each-user-stored-

If for example you wish to use python to set the registry here is an example:

            from _winreg import *

            print r"*** Reading from SOFTWARE\Microsoft\Windows\CurrentVersion\Run ***"
            aReg = ConnectRegistry(None,HKEY_LOCAL_MACHINE)

            aKey = OpenKey(aReg, r"SOFTWARE\Microsoft\Windows\CurrentVersion\Run") 
            for i in range(1024):                                           
                try:
                    n,v,t = EnumValue(aKey,i)
                    print i, n, v, t
                except EnvironmentError:                                               
                    print "You have",i," tasks starting at logon..."
                    break          
            CloseKey(aKey)                                                  

            print r"*** Writing to SOFTWARE\Microsoft\Windows\CurrentVersion\Run ***"
            aKey = OpenKey(aReg, r"SOFTWARE\Microsoft\Windows\CurrentVersion\Run", 0, KEY_WRITE)
            try:   
               SetValueEx(aKey,"MyNewKey",0, REG_SZ, r"c:\winnt\explorer.exe") 
            except EnvironmentError:                                          
                print "Encountered problems writing into the Registry..."
            CloseKey(aKey)

            CloseKey(aReg)    
2
Vikram On