Code: Select all
#include "FiveWin.ch"
function Main()
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
RETURN NIL
#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
// Gracias Lucas, mi duda major és aqui:
IF Os_IsWin7() //hb_osIsWin7()
bRetVal := bRetVal ... ??? Entende?
ENDIF
IF Os_IsWin8() //hb_osIsWin8()
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 )
#pragma BEGINDUMP
#include <windows.h>
HB_FUNC( OS_ISUSERANADMIN )
{
BOOL b;
SID_IDENTIFIER_AUTHORITY NtAuthority = SECURITY_NT_AUTHORITY;
PSID AdministratorsGroup;
b = AllocateAndInitializeSid( &NtAuthority, 2,
SECURITY_BUILTIN_DOMAIN_RID,
DOMAIN_ALIAS_RID_ADMINS,
0, 0, 0, 0, 0, 0,
&AdministratorsGroup );
if( b )
{
if ( !CheckTokenMembership( NULL, AdministratorsGroup, &b ) )
b = FALSE;
FreeSid( AdministratorsGroup );
}
hb_retl( b );
}
#pragma ENDDUMP