Lm th? no ? vi?t m?t DWORD ? ng k?

D?ch tiu ? D?ch tiu ?
ID c?a bi: 258262 - Xem s?n ph?m m bi ny p d?ng vo.
Bung t?t c? | Thu g?n t?t c?

TM T?T

i khi n l c?n thi?t ? ghi thng tin vo s? ng k?. Bi vi?t ny cho th?y lm th? no ? vi?t cc gi tr? REG_DWORD cho m?t phm t?o trong registry cho bi vi?t ny. N?u gi tr? b?n ang vi?t cha t?n t?i, b?n c?n ph?i thm n.

THNG TIN THM

QUAN TR?NG: Bi vi?t ny ch?a thng tin v? vi?c s?a ?i registry. Tr?c khi b?n ch?nh s?a registry, h?y ch?c ch?n ? tr? l?i n ln v ?m b?o r?ng b?n hi?u lm th? no ? khi ph?c s? ng k? n?u m?t v?n ? x?y ra. Thng tin v? lm th? no ? sao lu, khi ph?c v ch?nh s?a registry, nh?p vo s? bi vi?t sau ? xem bi vi?t trong c s? ki?n th?c Microsoft:
256986 M t? c?a Microsoft Windows Registry

C?NH BO: N?u b?n s? d?ng Registry Editor khng chnh xc, b?n c th? gy ra v?n ? nghim tr?ng m c th? yu c?u b?n ph?i ci ?t l?i h? i?u hnh c?a b?n. Microsoft khng th? ?m b?o r?ng b?n c th? gi?i quy?t v?n ? m k?t qu? t? vi?c s? d?ng Registry Editor khng chnh xc. S? d?ng Registry Editor nguy c c?a ring b?n.

Thng tin v? registry editor trong bi vi?t ny l dnh cho Microsoft Windows NT v Microsoft Windows 2000. N?u b?n ang ch?y Microsoft Windows 9 X, b?n c?n ph?i s? d?ng Regedit.exe thay v? Regedt32.exe.

CHU Y: Bi vi?t ny s? d?ng m?t kha registry m ?c t?o ra ch? cho m?c ch th? nghi?m v c?n xa khi b?n lm xong th? nghi?m.
  1. Khi ng Registry Editor (Regedt32.exe).
  2. Xc ?nh v? tr cc kha sau trong registry:
       HKEY_LOCAL_MACHINE\Software
    					
  3. Trn cc Ch?nh s?a tr?nh n, nh?p vo Thm phm, v sau thm sau registry Key:
       VfpREGTest
    					
  4. Trn cc Ch?nh s?a tr?nh n, nh?p vo Thm gi tr?, v sau thm gi tr? ng k? sau y:
       Value Name: MyDWORD
       Data Type:  REG_DWORD
       Value:      0
    					
  5. Thot kh?i Registry Editor.
  6. T? Visual FoxPro, t?o ra m?t chng tr?nh v nh?p vo o?n m? sau:
    #DEFINE HKEY_CLASSES_ROOT           -2147483648
    #DEFINE HKEY_CURRENT_USER           -2147483647
    #DEFINE HKEY_LOCAL_MACHINE          -2147483646
    #DEFINE HKEY_USERS                  -2147483645
    
    LOCAL nKey, cSubKey, cValue, nValueToWrite, lSuccess
    nKey = HKEY_LOCAL_MACHINE
    nValueToWrite = 1
    cSubKey = "Software\VfpREGTest"
    cValue = "MyDWORD"
    
    lSuccess = WriteRegDWORD(nKey, cSubKey, cValue, nValueToWrite)
    
    IF (lSuccess) THEN
       =MESSAGEBOX("Function Successful.")
    ELSE
       =MESSAGEBOX("Function Not Successful.")
    ENDIF
    
    FUNCTION WriteRegDWORD
       * This function writes a REG_DWORD to the registry. It will return .T.
       * if successful and .F. if it isn't successful.
       PARAMETERS  nKey, cSubKey, cValue,  nValueToWrite
       * nKey The root key to open. It can be any of the constants defined below.
       *#DEFINE HKEY_CLASSES_ROOT           -2147483648
       *#DEFINE HKEY_CURRENT_USER           -2147483647
       *#DEFINE HKEY_LOCAL_MACHINE          -2147483646
       *#DEFINE HKEY_USERS                  -2147483645
       *cSubKey The SubKey to open.
       *cValue The value that is going to be written.
       *nValueToWrite The value to write to the registry
    
       * Constants that are needed for Registry functions
       #DEFINE REG_DWORD   4
    
       * WIN 32 API functions that are used
       DECLARE Integer RegOpenKey IN Win32API ;
          Integer nHKey, String @cSubKey, Integer @nResult
       DECLARE Integer RegSetValueEx IN Win32API ;
          Integer hKey, String lpszValueName, Integer dwReserved,;
          Integer fdwType, String lpbData, Integer cbData
       DECLARE Integer RegCloseKey IN Win32API Integer nHKey
    
       * Local variables used
       LOCAL nErrCode          && Error Code returned from Registry functions
       LOCAL nKeyHandle        && Handle to Key that is opened in the Registry
       LOCAL lpdwValueType     && Type of Value that we are looking for.
       LOCAL lpbValue          && The data stored in the value
       LOCAL lpcbValueSize     && Size of the variable
       LOCAL lpdwReserved      && Reserved Must be 0
    
       * Initialize the variables
       nKeyHandle = 0
       lpdwReserved = 0           
       lpdwValueType = REG_DWORD
       lpcbValueSize = 4     && DWORD is 4 bytes
    
       lpbValue = LongToStr(nValueToWrite)
    
       nErrCode = RegOpenKey(nKey, cSubKey, @nKeyHandle)
       * If the error code isn't 0, then the key doesn't exist or can't be opened.
       IF (nErrCode # 0) THEN
          RETURN .F.
       ENDIF
    
       nErrCode=RegSetValueEx(nKeyHandle, cValue, lpdwReserved, lpdwValueType, lpbValue, lpcbValueSize)
       =RegCloseKey(nKeyHandle)
       IF (nErrCode # 0) THEN
          RETURN .F.
       ENDIF
    RETURN .T.
    
    FUNCTION LongToStr
    * This function converts a long to a string
       PARAMETERS nLongVal
       LOCAL nLoopVar, strReturn
    
       strReturn = ""
       FOR nLoopVar = 24 TO 0 STEP -8
          strReturn = CHR(INT(nLongVal/(2^nLoopVar))) + strReturn
          nLongVal = MOD(nLongVal, (2^nLoopVar))
       NEXT
    RETURN strReturn
    * End of Code
    					
  7. Ch?y m? t?o ? b?c 1. M?t h?p thng i?p s? xu?t hi?n thng bo s? thnh cng hay th?t b?i c?a cc ch?c nng. B?n c th? s? d?ng regedt32.exe ? xc minh r?ng gi tr? ?c ghi vo registry.
  8. B?n c th? thay th? nKey, cSubKey, cValue, v nValueToWrite v?i thng tin c?a b?n ? ?c ghi vo registry.
(c) Microsoft Corporation 2000, t?t c? cc quy?n. Nh?ng ng gp c?a Mark Barnard, Microsoft Corporation.

THAM KH?O


? thm thng tin c gi tr? t? s? ng k?, b?m vo s? bi vi?t d?i y ? xem bi vi?t trong c s? ki?n th?c Microsoft:
244675 Lm th? no ToUse Windows Script Host ? ?c, vi?t, xa s? ng k?

Thu?c tnh

ID c?a bi: 258262 - L?n xem xt sau cng: 21 Thang Tam 2011 - Xem xt l?i: 2.0
p d?ng
  • Microsoft Visual FoxPro 3.0 Standard Edition
  • Microsoft Visual FoxPro 5.0 Standard Edition
  • Microsoft Visual FoxPro 6.0 Professional Edition
T? kha:
kbapi kbcodesnippet kbhowto kbregistry kbmt KB258262 KbMtvi
My d?ch
QUAN TRONG: Bi vi?t ny ?c d?ch b?ng ph?n m?m d?ch my c?a Microsoft ch? khng ph?i do con ng?i d?ch. Microsoft cung c?p cc bi vi?t do con ng?i d?ch v c? cc bi vi?t do my d?ch ? b?n c th? truy c?p vo t?t c? cc bi vi?t trong C s? Ki?n th?c c?a chng ti b?ng ngn ng? c?a b?n. Tuy nhin, bi vi?t do my d?ch khng ph?i lc no c?ng hon h?o. Lo?i bi vi?t ny c th? ch?a cc sai st v? t? v?ng, c php ho?c ng? php, gi?ng nh m?t ng?i n?c ngoi c th? m?c sai st khi ni ngn ng? c?a b?n. Microsoft khng ch?u trch nhi?m v? b?t k? s? thi?u chnh xc, sai st ho?c thi?t h?i no do vi?c d?ch sai n?i dung ho?c do ho?t ?ng s? d?ng c?a khch hng gy ra. Microsoft c?ng th?ng xuyn c?p nh?t ph?n m?m d?ch my ny.
Nh?p chu?t vo y ? xem b?n ti?ng Anh c?a bi vi?t ny:258262

Cung cp Phan hi

 

Contact us for more help

Contact us for more help
Connect with Answer Desk for expert help.
Get more support from smallbusiness.support.microsoft.com