Página 1 de 3

Função WIN_OSNETREGOK()

Enviado: 22 Out 2010 14:43
por Itamar M. Lins Jr.
Ola!

Função muito importate, pois ajusta o registro do windows otimiza para trabalhar com DBF.
Já coloque aqui no inicio do meu sistema, notei uma maior velocidade no XP na abertura dos DBF's :-)
Falta os testes com Win7 pois notei que está mais lento na indexação só que é em um cliente.

Código: Selecionar todos


If !WIN_OSNETREGOK() //Precisa direitos ADM
   If !WIN_OSNETREGOK(.t.,.t.) //primeiro .t. é para ajustar XP/W98..., o segundo ajusta no vista. 
      MsgInfo('Registro do windows não ajustado !')
   EndIf   
EndIf

Saudações,
Itamar M. Lins Jr.

Re: Função WIN_OSNETREGOK()

Enviado: 22 Out 2010 17:58
por lugab
O fórum agradece por vc compartilhar seus conhecimentos, Itamar.

Duas duvidas:

-O jeito que está o código q vc postou, é só pra windows XP, né ?

-o ajuste de regoistro só tem efeito na estação que executa a rotina, né ?

Gabriel

Re: Função WIN_OSNETREGOK()

Enviado: 22 Out 2010 19:06
por Itamar M. Lins Jr.
Ola!
O jeito que está o código q vc postou, é só pra windows XP, né ?
É para todas as versões do windows inclusive win7.
-o ajuste de registro só tem efeito na estação que executa a rotina, né ?
Exato e precisa dos direitos de admin no Vista/7 etc..

Saudações,
Itamar M. Lins Jr.

Re: Função WIN_OSNETREGOK()

Enviado: 22 Out 2010 21:00
por lugab
Obrigado, Itamar.

Agora eu Vou experimentar ela num ambiente de produção.

Uma última pergunta: Vc sabe dizer o nome da lib q tem essa função, pra quem usa Xharbour ?

Obrigado por tudo

gabriel

Re: Função WIN_OSNETREGOK()

Enviado: 23 Out 2010 11:37
por TerraSoftware
Caros colegas.
Eu tambem nao encontrei a respectiva funcao no meu xharbour.
Pode nos ajudar Itamar?
Ou é exclusividade de quem usa harbour?

Re: Função WIN_OSNETREGOK()

Enviado: 23 Out 2010 11:46
por Itamar M. Lins Jr.
Ola!
É exclusiva do Harbour, mas nada impede que seja ajustada para o xHarbour.
Os ajustes podem ser feitos até manualmente.
Abaixo o código da duas funções. Eu cortei a parte da Licença.
Tem também a WIN_OSNETVREDIROK() para os Win9X

Código: Selecionar todos

#include "common.ch"
#include "directry.ch"
#include "hbwin.ch"

/* NOTE: To change any of these registry settings
         Administrator rights are required by default in Windows. [vszakats] */

FUNCTION WIN_OSNETREGOK( lSetIt, lDoVista )
   LOCAL bRetVal := .T.
   LOCAL cKeySrv
   LOCAL cKeyWks

   IF ! ISLOGICAL( lSetIt )
      lSetIt := .F.
   ENDIF
   IF ! ISLOGICAL( lDoVista )
      lDoVista := .T.
   ENDIF

   IF ! lDoVista .AND. win_osIsVistaOrUpper()
      /* do nothing */
   ELSEIF hb_osIsWin9x()
      bRetVal := win_regQuery( WIN_HKEY_LOCAL_MACHINE, "System\CurrentControlSet\Services\VxD\VREDIR", "DiscardCacheOnOpen", 1, lSetIt )
   ELSE
      cKeySrv := "System\CurrentControlSet\Services\LanmanServer\Parameters"
      cKeyWks := "System\CurrentControlSet\Services\LanmanWorkStation\Parameters"

      IF lSetIt
         lSetIt := ! hb_osIsWinNT() .OR. wapi_IsUserAnAdmin()
      ENDIF

      /* Server settings */
      bRetVal := bRetVal .AND. win_regQuery( WIN_HKEY_LOCAL_MACHINE, cKeySrv, "CachedOpenLimit", 0, lSetIt )
      bRetVal := bRetVal .AND. win_regQuery( WIN_HKEY_LOCAL_MACHINE, cKeySrv, "EnableOpLocks", 0, lSetIt ) /* Q124916 */
      bRetVal := bRetVal .AND. win_regQuery( WIN_HKEY_LOCAL_MACHINE, cKeySrv, "EnableOpLockForceClose", 1, lSetIt )
      bRetVal := bRetVal .AND. win_regQuery( WIN_HKEY_LOCAL_MACHINE, cKeySrv, "SharingViolationDelay", 0, lSetIt )
      bRetVal := bRetVal .AND. win_regQuery( WIN_HKEY_LOCAL_MACHINE, cKeySrv, "SharingViolationRetries", 0, lSetIt )

      IF win_osIsVistaOrUpper()
         /* If SMB2 is enabled turning off oplocks does not work, so SMB2 is required to be turned off on Server. */
         bRetVal := bRetVal .AND. win_regQuery( WIN_HKEY_LOCAL_MACHINE, cKeySrv, "SMB2", 0, lSetIt )
      ENDIF

      /* Workstation settings */
      bRetVal := bRetVal .AND. win_regQuery( WIN_HKEY_LOCAL_MACHINE, cKeyWks, "UseOpportunisticLocking", 0, lSetIt )
      bRetVal := bRetVal .AND. win_regQuery( WIN_HKEY_LOCAL_MACHINE, cKeyWks, "EnableOpLocks", 0, lSetIt )
      bRetVal := bRetVal .AND. win_regQuery( WIN_HKEY_LOCAL_MACHINE, cKeyWks, "EnableOpLockForceClose", 1, lSetIt )
      bRetVal := bRetVal .AND. win_regQuery( WIN_HKEY_LOCAL_MACHINE, cKeyWks, "UtilizeNtCaching", 0, lSetIt )
      bRetVal := bRetVal .AND. win_regQuery( WIN_HKEY_LOCAL_MACHINE, cKeyWks, "UseLockReadUnlock", 0, lSetIt )

      IF win_osIsVistaOrUpper()
         bRetVal := bRetVal .AND. win_regQuery( WIN_HKEY_LOCAL_MACHINE, cKeyWks, "FileInfoCacheLifetime", 0, lSetIt )
         bRetVal := bRetVal .AND. win_regQuery( WIN_HKEY_LOCAL_MACHINE, cKeyWks, "FileNotFoundCacheLifetime", 0, lSetIt )
         bRetVal := bRetVal .AND. win_regQuery( WIN_HKEY_LOCAL_MACHINE, cKeyWks, "DirectoryCacheLifetime", 0, lSetIt )
      ENDIF

      IF hb_osIsWin2K()
         bRetVal := bRetVal .AND. win_regQuery( WIN_HKEY_LOCAL_MACHINE, "System\CurrentControlSet\Services\MRXSmb\Parameters", "OpLocksDisabled", 1, lSetIt )
      ENDIF
   ENDIF

   RETURN bRetVal

FUNCTION WIN_OSNETVREDIROK( /* @ */ nResult )
   LOCAL aFiles

   nResult := 0

   IF hb_osIsWin9x()
      aFiles := Directory( hb_GetEnv( "WINDIR", "C:\WINDOWS" ) + "\SYSTEM\VREDIR.VXD" )  /* Check for faulty files. */
      IF ! Empty( aFiles )
         IF aFiles[ 1 ][ F_SIZE ] == 156749 .AND. aFiles[ 1 ][ F_TIME ] == "11:11:10"
            nResult := 1111
         ELSEIF aFiles[ 1 ][ F_SIZE ] == 140343 .AND. aFiles[ 1 ][ F_TIME ] == "09:50:00"
            nResult := 950
         ENDIF
      ENDIF
   ENDIF

   RETURN Empty( nResult )
Saudações,
Itamar M. Lins Jr.

Re: Função WIN_OSNETREGOK()

Enviado: 23 Out 2010 11:50
por TerraSoftware
Caro colega Itamar.
Isso realmente melhora o uso de dbf's? Vale a pena?

Re: Função WIN_OSNETREGOK()

Enviado: 23 Out 2010 12:31
por Itamar M. Lins Jr.
Lógico, que melhora, algumas dessas é até crucial.
É um ajuste de como o windows irá tratar os travamentos dos DBF's, porque o windows interfere na abertura e fechamento dos arquivos.

Saudações,
Itamar M. Lins Jr.

Re: Função WIN_OSNETREGOK()

Enviado: 24 Out 2010 21:32
por alaminojunior
Ajustado para xHarbour. Por favor tirem suas conclusões.

Código: Selecionar todos

#include "common.ch"
#include "directry.ch"

#define WIN_HKEY_LOCAL_MACHINE 0 
#define WIN_HKEY_CLASSES_ROOT 1 
#define WIN_HKEY_CURRENT_USER 2 
#define WIN_HKEY_CURRENT_CONFIG 3 
#define WIN_HKEY_LOCAL_MACHINE 4 
#define WIN_HKEY_USERS 5 


/* NOTE: To change any of these registry settings
         Administrator rights are required by default in Windows. [vszakats] */

FUNCTION WIN_OSNETREGOK( lSetIt, lDoVista )
   LOCAL bRetVal := .T.
   LOCAL cKeySrv
   LOCAL cKeyWks

   IF ! ISLOGICAL( lSetIt )
      lSetIt := .F.
   ENDIF
   IF ! ISLOGICAL( lDoVista )
      lDoVista := .T.
   ENDIF

   IF ! lDoVista .AND. Os_IsWinVISTA() //win_osIsVistaOrUpper()
      /* do nothing */
   ELSEIF Os_IsWin9X() // hb_osIsWin9x()
      bRetVal := QueryRegistry( WIN_HKEY_LOCAL_MACHINE, "System\CurrentControlSet\Services\VxD\VREDIR", "DiscardCacheOnOpen", 1, lSetIt )
   ELSE
      cKeySrv := "System\CurrentControlSet\Services\LanmanServer\Parameters"
      cKeyWks := "System\CurrentControlSet\Services\LanmanWorkStation\Parameters"

      IF lSetIt
         lSetIt := ! Os_IsWinNT() .OR. os_IsUserAnAdmin() //wapi_IsUserAnAdmin()
      ENDIF

      /* Server settings */
      bRetVal := bRetVal .AND. QueryRegistry( WIN_HKEY_LOCAL_MACHINE, cKeySrv, "CachedOpenLimit", 0, lSetIt )
      bRetVal := bRetVal .AND. QueryRegistry( WIN_HKEY_LOCAL_MACHINE, cKeySrv, "EnableOpLocks", 0, lSetIt ) /* Q124916 */
      bRetVal := bRetVal .AND. QueryRegistry( WIN_HKEY_LOCAL_MACHINE, cKeySrv, "EnableOpLockForceClose", 1, lSetIt )
      bRetVal := bRetVal .AND. QueryRegistry( WIN_HKEY_LOCAL_MACHINE, cKeySrv, "SharingViolationDelay", 0, lSetIt )
      bRetVal := bRetVal .AND. QueryRegistry( WIN_HKEY_LOCAL_MACHINE, cKeySrv, "SharingViolationRetries", 0, lSetIt )

      IF Os_IsWinVISTA() // win_osIsVistaOrUpper()
         /* If SMB2 is enabled turning off oplocks does not work, so SMB2 is required to be turned off on Server. */
         bRetVal := bRetVal .AND. QueryRegistry( WIN_HKEY_LOCAL_MACHINE, cKeySrv, "SMB2", 0, lSetIt )
      ENDIF

      /* Workstation settings */
      bRetVal := bRetVal .AND. QueryRegistry( WIN_HKEY_LOCAL_MACHINE, cKeyWks, "UseOpportunisticLocking", 0, lSetIt )
      bRetVal := bRetVal .AND. QueryRegistry( WIN_HKEY_LOCAL_MACHINE, cKeyWks, "EnableOpLocks", 0, lSetIt )
      bRetVal := bRetVal .AND. QueryRegistry( WIN_HKEY_LOCAL_MACHINE, cKeyWks, "EnableOpLockForceClose", 1, lSetIt )
      bRetVal := bRetVal .AND. QueryRegistry( WIN_HKEY_LOCAL_MACHINE, cKeyWks, "UtilizeNtCaching", 0, lSetIt )
      bRetVal := bRetVal .AND. QueryRegistry( WIN_HKEY_LOCAL_MACHINE, cKeyWks, "UseLockReadUnlock", 0, lSetIt )

      IF Os_IsWinVISTA() //win_osIsVistaOrUpper()
         bRetVal := bRetVal .AND. QueryRegistry( WIN_HKEY_LOCAL_MACHINE, cKeyWks, "FileInfoCacheLifetime", 0, lSetIt )
         bRetVal := bRetVal .AND. QueryRegistry( WIN_HKEY_LOCAL_MACHINE, cKeyWks, "FileNotFoundCacheLifetime", 0, lSetIt )
         bRetVal := bRetVal .AND. QueryRegistry( WIN_HKEY_LOCAL_MACHINE, cKeyWks, "DirectoryCacheLifetime", 0, lSetIt )
      ENDIF

      IF Os_IsWinNT() //hb_osIsWin2K()
         bRetVal := bRetVal .AND. QueryRegistry( WIN_HKEY_LOCAL_MACHINE, "System\CurrentControlSet\Services\MRXSmb\Parameters", "OpLocksDisabled", 1, lSetIt )
      ENDIF
   ENDIF

   RETURN bRetVal

FUNCTION WIN_OSNETVREDIROK( /* @ */ nResult )
   LOCAL aFiles

   nResult := 0

   IF Os_IsWin9X() // hb_osIsWin9x()
      aFiles := Directory( GetEnv( "WINDIR", "C:\WINDOWS" ) + "\SYSTEM\VREDIR.VXD" )  /* Check for faulty files. */
      IF ! Empty( aFiles )
         IF aFiles[ 1 ][ F_SIZE ] == 156749 .AND. aFiles[ 1 ][ F_TIME ] == "11:11:10"
            nResult := 1111
         ELSEIF aFiles[ 1 ][ F_SIZE ] == 140343 .AND. aFiles[ 1 ][ F_TIME ] == "09:50:00"
            nResult := 950
         ENDIF
      ENDIF
   ENDIF

   RETURN Empty( nResult )

Re: Função WIN_OSNETREGOK()

Enviado: 25 Out 2010 11:25
por TerraSoftware
Caro colega Alaminojunior.
Minha compilacao nao encontrou a funcao os_IsUserAnAdmin().
Onde posso encontrar?

Re: Função WIN_OSNETREGOK()

Enviado: 25 Out 2010 12:09
por alaminojunior
Pode ser a versão do xHarbour. Algumas funções dentro desta rotina, foram incorporadas na versão 1.2.1 em diante.

[OT] A propósito, ví que você utiliza o BCC 6.3. Eu baixei aquele "zip enxugado" disponibilizado aqui no fórum, e não vieram alguns arquivos da pasta INCLUDE, e com isso não consigo compilar os prg´s. De onde o colega baixou o BCC 6.3 ?

Re: Função WIN_OSNETREGOK()

Enviado: 25 Out 2010 15:43
por TerraSoftware
Caro colega alaminojunior.
Uso o xharbour 1.0.0, provavelmente que o problema seja este, mas nao estou com tempo de migrar agora.
Sobre o bcc, eu tambem baixei o zip enxuto e nao tive problemas com falta de includes. Talvez o seu problema esteja em nao ter observados que os arquivos .h estao expalhados em varias subpastas. Dá uma olhadinha ai.

Re: Função WIN_OSNETREGOK()

Enviado: 25 Out 2010 16:09
por alaminojunior
Enquanto não faz o update do xHarbour, você pode fazer as alterações manualmente. O inconveniente é ter que fazer pc por pc em cada cliente.

Re: Função WIN_OSNETREGOK()

Enviado: 26 Out 2010 16:57
por sygecom
Buenas Alamino,
Assim prontinho vou me acostumar mal em...rsrsrs Vlw pela tradução. abraços.

Re: Função WIN_OSNETREGOK()

Enviado: 26 Out 2010 17:47
por alaminojunior
sygecom escreveu:Assim prontinho vou me acostumar mal em...rsrsrs Vlw pela tradução. abraços.
Mas bah...capaz !