Coding4ever’s Blog

Just coding… coding… and coding… because coding should be fun :)

Merubah Setting Regional and Language Options via Aplikasi

| Comments

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 :D 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

1
HKEY_CURRENT_USER\Control Panel\International

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

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
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 :

1
2
3
4
Public Sub Main()
    Call setDefRegionalSetting
    'TODO : tampilkan form utama
End Sub

Selamat mencoba :)

Comments