Home > Visual Basic > Merubah setting Regional and Language Options via aplikasi

Merubah setting Regional and Language Options via aplikasi

October 18, 2010

Pada kasus-kasus tertentu ada program yang error gara-gara pengaruh setting Regional and Language Options, misal ada yg 100% jalan klo diset ke English tapi malah error klo diset ke Indonesian atau sebaliknya.

Dan pada artikel ini saya akan share bagaimana caranya merubah setting Regional and Language Options ke English (United States) secara paksa😀 setiap aplikasi kita dijalankan.

Modalnya juga murah cukup dengan memanfaatkan beberapa fungsi API untuk mengakses registry windows.

Sebelum kita bercoding ria ada baiknya kita mengetahui dimana lokasi penyimpanan Setting Regional and Language Options di registry windows.

Dibawah ini adalah lokasi penyimpanannya

HKEY_CURRENT_USER\Control Panel\International

Oke kita langsung saja tambahkan sebuah modul kemudian copas kode berikut :

Option Explicit

Private Declare Function RegCloseKey Lib "advapi32.dll" (ByVal hKey As Long) As Long
Private Declare Function RegCreateKey Lib "advapi32.dll" Alias "RegCreateKeyA" (ByVal hKey As Long, ByVal lpSubKey As String, phkResult As Long) As Long
Private Declare Function RegSetValueEx Lib "advapi32.dll" Alias "RegSetValueExA" (ByVal hKey As Long, ByVal lpValueName As String, ByVal Reserved As Long, ByVal dwType As Long, lpData As Any, ByVal cbData As Long) As Long
Private Declare Function GetLocaleInfo Lib "kernel32" Alias "GetLocaleInfoA" (ByVal Locale As Long, ByVal LCType As Long, ByVal lpLCData As String, ByVal cchData As Long) As Long

Private Const HKEY_CURRENT_USER = &H80000001
Private Const LOCALE_SENGCOUNTRY     As Long = &H1002 '  English name of country
Private Const LOCALE_USER_DEFAULT    As Long = &H400
Private Const REGIONAL_SETTING       As String = "United States"
Private Const REG_SZ = 1 ' Unicode nul terminated string

Private Sub saveToWindowsRegistry(hKey As Long, strPath As String, strValue As String, strData As String)
    Dim ret As Long

    On Error Resume Next

    'Create a new key
    RegCreateKey hKey, strPath, ret
    'Save a string to the key
    RegSetValueEx ret, strValue, 0, REG_SZ, ByVal strData, Len(strData)
    'close the key
    RegCloseKey ret
End Sub

Private Function getInfoRegionalSettings(ByVal lInfo As Long) As String
    Dim buffer As String, ret As String

    On Error Resume Next

    buffer = String$(256, 0)
    ret = GetLocaleInfo(LOCALE_USER_DEFAULT, lInfo, buffer, Len(buffer))
    If ret > 0 Then
        getInfoRegionalSettings = Left$(buffer, ret - 1)
    Else
        getInfoRegionalSettings = ""
    End If
End Function

Public Sub setDefRegionalSetting()
    If getInfoRegionalSettings(LOCALE_SENGCOUNTRY) <> REGIONAL_SETTING Then
        Call saveToWindowsRegistry(HKEY_CURRENT_USER, "Control Panel\International", "iCountry", "1")
        Call saveToWindowsRegistry(HKEY_CURRENT_USER, "Control Panel\International", "iCurrDigits", "2")
        Call saveToWindowsRegistry(HKEY_CURRENT_USER, "Control Panel\International", "iCurrency", "0")
        Call saveToWindowsRegistry(HKEY_CURRENT_USER, "Control Panel\International", "iDate", "0")
        Call saveToWindowsRegistry(HKEY_CURRENT_USER, "Control Panel\International", "iDigits", "2")
        Call saveToWindowsRegistry(HKEY_CURRENT_USER, "Control Panel\International", "iLZero", "1")
        Call saveToWindowsRegistry(HKEY_CURRENT_USER, "Control Panel\International", "iMeasure", "1")
        Call saveToWindowsRegistry(HKEY_CURRENT_USER, "Control Panel\International", "iNegCurr", "0")
        Call saveToWindowsRegistry(HKEY_CURRENT_USER, "Control Panel\International", "iTime", "0")
        Call saveToWindowsRegistry(HKEY_CURRENT_USER, "Control Panel\International", "iTLZero", "0")
        Call saveToWindowsRegistry(HKEY_CURRENT_USER, "Control Panel\International", "Locale", "00000409")
        Call saveToWindowsRegistry(HKEY_CURRENT_USER, "Control Panel\International", "s1159", "AM")
        Call saveToWindowsRegistry(HKEY_CURRENT_USER, "Control Panel\International", "s2359", "PM")
        Call saveToWindowsRegistry(HKEY_CURRENT_USER, "Control Panel\International", "sCountry", "United States")
        Call saveToWindowsRegistry(HKEY_CURRENT_USER, "Control Panel\International", "sCurrency", "$")
        Call saveToWindowsRegistry(HKEY_CURRENT_USER, "Control Panel\International", "sDate", "/")
        Call saveToWindowsRegistry(HKEY_CURRENT_USER, "Control Panel\International", "sDecimal", ".")
        Call saveToWindowsRegistry(HKEY_CURRENT_USER, "Control Panel\International", "sLanguage", "ENU")
        Call saveToWindowsRegistry(HKEY_CURRENT_USER, "Control Panel\International", "sList", ",")
        Call saveToWindowsRegistry(HKEY_CURRENT_USER, "Control Panel\International", "sLongDate", "dddd, MMMM dd, yyyy")
        Call saveToWindowsRegistry(HKEY_CURRENT_USER, "Control Panel\International", "sShortDate", "M/d/yyyy")
        Call saveToWindowsRegistry(HKEY_CURRENT_USER, "Control Panel\International", "sThousand", ",")
        Call saveToWindowsRegistry(HKEY_CURRENT_USER, "Control Panel\International", "sTime", ":")
        Call saveToWindowsRegistry(HKEY_CURRENT_USER, "Control Panel\International", "sTimeFormat", "h:mm:ss tt")
        Call saveToWindowsRegistry(HKEY_CURRENT_USER, "Control Panel\International", "iTimePrefix", "0")
        Call saveToWindowsRegistry(HKEY_CURRENT_USER, "Control Panel\International", "sMonDecimalSep", ".")
        Call saveToWindowsRegistry(HKEY_CURRENT_USER, "Control Panel\International", "sMonThousandSep", ",")
        Call saveToWindowsRegistry(HKEY_CURRENT_USER, "Control Panel\International", "iNegNumber", "1")
        Call saveToWindowsRegistry(HKEY_CURRENT_USER, "Control Panel\International", "sNativeDigits", "0123456789")
        Call saveToWindowsRegistry(HKEY_CURRENT_USER, "Control Panel\International", "NumShape", "1")
        Call saveToWindowsRegistry(HKEY_CURRENT_USER, "Control Panel\International", "iCalendarType", "1")
        Call saveToWindowsRegistry(HKEY_CURRENT_USER, "Control Panel\International", "iFirstDayOfWeek", "6")
        Call saveToWindowsRegistry(HKEY_CURRENT_USER, "Control Panel\International", "iFirstWeekOfYear", "0")
        Call saveToWindowsRegistry(HKEY_CURRENT_USER, "Control Panel\International", "sGrouping", "3;0")
        Call saveToWindowsRegistry(HKEY_CURRENT_USER, "Control Panel\International", "sMonGrouping", "3;0")
        Call saveToWindowsRegistry(HKEY_CURRENT_USER, "Control Panel\International", "sPositiveSign", "")
        Call saveToWindowsRegistry(HKEY_CURRENT_USER, "Control Panel\International", "sNegativeSign", "-")
        Call saveToWindowsRegistry(HKEY_CURRENT_USER, "Control Panel\International\Geo", "Nation", "244")
    End If
End Sub

Selanjutnya tinggal panggil prosedur setDefRegionalSetting diatas di prosedur Main :

Public Sub Main()
    Call setDefRegionalSetting
    'TODO : tampilkan form utama
End Sub

Selamat mencoba🙂

  1. Soka106
    October 20, 2010 at 12:49 am

    Artkel menarik, mengatasi permasalahan yg sering terjadi. Thx pak!

  2. October 20, 2010 at 8:40 am

    Oke sama2x

  3. afdoal
    October 30, 2010 at 8:06 am

    mas… minta tolong lagi😀
    permasalahannay dah tak kirim lewat email…
    tolong ya mas…..

    sebelumnya terima kasih banyak… ^_^

    • October 31, 2010 at 4:02 am

      Udah tak bales om

  4. eko
    March 4, 2011 at 1:07 pm

    mas kebetulan saya juga prog.vb6 mau tanya akses registry di windows 7 dg vb6 koq sulit ya tidak ada efeknya ketika merubah sebuah value di registry

    • March 4, 2011 at 10:34 pm

      Sy memang belum pernah coba langsung akses registry di win 7, tapi selama ini program sy yg diinstall di win 7 selalu berhasil mencatat lokasi instalasi di registry maupun menbaca nilai registrynya enggak ada masalah.

      Modul yg sy gunakan sama seperti contoh di atas.

      Mungkin masalahnya waktu jalanin programnya menggunakan login non administrator ???

  5. September 26, 2011 at 9:35 am

    Saya udah coba melakukan Copy – Paste pada Source Code tapi masih blon bisa..??

    Saya tambahan TextBox untuk mengetahui Setting tanggal = sehingga tau pake countri dari mana. msh gak bisa juga

    Tuluung donk Bro…

    MN
    (mnoer31@yahoo.com)

    • September 27, 2011 at 7:39 am

      Om cobanya di Win 7 ya? Klo iya memang belum sy coba untuk win 7😀

      Atw om cek sendiri aja nilai registry yg berubah pada saat mengganti setting regionalnya.

      Nilai key registrynya bisa dicek disini :

      HKEY_CURRENT_USER\Control Panel\International
      
  6. bagustuta
    February 7, 2012 at 10:54 am

    keren bro

    • February 7, 2012 at 11:56 am

      Ah yg benar om ?😀

  7. Ami
    March 23, 2013 at 1:15 am

    Om admin, bisa gak klw waktu user ganti perubahan tanggal program kita langsung ngedetect perubahaan itu, gmna ya om logic n’ coding ya …

  8. January 16, 2014 at 9:46 pm

    Om kalo mengubah ke Indonesia, source code di atas mana saja yang diubah? Matur nuwun

    • January 17, 2014 at 3:31 pm

      Nah ini om langkah-langkahnya :
      1. Ubah dulu regional setting om ke Indonesia
      2. Buka Registry Editor kemudian akses key “HKEY_CURRENT_USER\Control Panel\International”, nah disitukan keliatan apa saja nilai yg perlu dirubah untuk Indonesia.

      • January 20, 2014 at 4:43 pm

        Makasih banyak om.
        Untuk win8 ternyata harus saya tambahkan baris ini om
        Call saveToWindowsRegistry(HKEY_CURRENT_USER, “Control Panel\International”, “LocaleName”, “id-ID”)
        dan ketika saya buka di regedit horeee ternyata berhasill….
        Sekali lagi terimakasih om atas sharing ilmunya.

        • January 21, 2014 at 8:59 am

          Sippp manteb om🙂

  1. No trackbacks yet.
Comments are closed.
%d bloggers like this: