Windows

首页Windows
11
Jan
0

kb2847927 无法安装

这个补丁kb2847927 需要先安装另外一个更新KB947821

1.kb2847927补丁
https://www.microsoft.com/zh-cn/download/details.aspx?id=39462

2.KB947821补丁
https://www.microsoft.com/zh-cn/download/details.aspx?id=20858

21
Nov
0

Linux和win原子操作

InterlockedIncrement()对应 atomic_inc()
InterlockedDecrement()对应 atomic_dec()

29
Sep
0

在python3上实现微软域帐号ldap登陆认证

有任务要实现域帐号认证,分别试用了ldap,python-ldap包后发现都是基于python2的
在python3上试用基本全部失败,ldap网上和官方代码基本跑不了
python-ldap包直接只支持python2安装不上,在改了部分代码后放弃
主要是在win下修改代码,边改边跑这两个包,N多努力后,偶然看见电脑里有ldap3这样一个控件包
并非主动安装,而是在python-ldap包时发现它引用的ldap包,顺腾摸瓜准备改代码时发现的

然后利用ldap3包如愿实现了所需要的功能,过程略折腾,因为网上的代码要么跑不动,要么有些在win下看似可以,实则不行
造成误会, 下面的代码在centos7.2 和python3.6下测试通过
接下来上代码:

from ldap3 import Server, Connection, ALL, NTLM
LDAP_URI = '10.86.87.52'
LDAP_USER = 'geely\\Huang.Xiaogang'  #域和用户之间必须是双斜划线
LDAP_PASS = 'xxx'
BASE_DN = 'OU=GeelyStaff,dc=geely,dc=auto'

1.验证登陆 成功True 反之

server = Server(LDAP_URI, get_info=ALL)
conn = Connection(server, user=LDAP_USER, password=LDAP_PASS, authentication= NTLM)
print(conn.bind())

2.返回基本信息

print(conn.extend.standard.who_am_i())
u:GEELY\Huang.XiaoGang

3.ssl登陆

server = Server('ipa.demo1.freeipa.org', use_ssl=True, get_info=ALL)
conn = Connection(server, 'uid=admin, cn=users, cn=accounts, dc=demo1, dc=freeipa, dc=org', 'Secret123', auto_bind=True)

4.ssl第二种方法

from ldap3 import Server, Connection, Tls
import ssl
tls_configuration = Tls(validate=ssl.CERT_REQUIRED, version=ssl.PROTOCOL_TLSv1)
server = Server('ipa.demo1.freeipa.org', use_ssl=True, tls=tls_configuration)
conn = Connection(server)
conn.open()

5.搜索用户

from ldap3 import Server, Connection, ALL
server = Server('ipa.demo1.freeipa.org', get_info=ALL)
conn = Connection(server, 'uid=admin, cn=users, cn=accounts, dc=demo1, dc=freeipa, dc=org', 'Secret123', auto_bind=True)
conn.search('dc=demo1, dc=freeipa, dc=org', '(objectclass=person)')
conn.entries #array

6.检查密码

def check_user(username,password):
    '''
    connection to LDAP and check whether user exists
    return str and '' means password correct, otherwise it means error message
    '''
    _connection.search('ou=users,'+_baseDN,'(&(uid='+username+')(objectclass=person))',attributes=['uid','userPassword'])
    if hasattr(_connection,'entries'):
        ens=_connection.entries
        if len(ens)==1:
            pwd=str(ens[0]['userPassword'])
            if _checkPassword(pwd,password):
                return ''
            else:
                return 'password not correct'
        elif len(ens)>1:
            return 'too many users'
    return 'user not found'


def _makeSecret(password):
    salt = os.urandom(4)
    h = hashlib.sha1(password)
    h.update(salt)
    return "{SSHA}" + encode(h.digest() + salt)

def _checkPassword(challenge_password, password):
    challenge_bytes = decode(challenge_password[6:])
    digest = challenge_bytes[:20]
    salt = challenge_bytes[20:]
    hr = hashlib.sha1(password)
    hr.update(salt)
    return digest == hr.digest()
'''
challenge_password = _makeSecret('testing123')
challenge_password
    '{SSHA}0c0blFTXXNuAMHECS4uxrj3ZieMoWImr'
_checkPassword(challenge_password, 'testing123')
    True
_checkPassword(challenge_password, 'testing124')
    False
'''
21
Sep
0

任务栏高度获取的方法

1.直接API 引用Windows单元

GetSystemMetrics(SM_CYSCREEN)-GetSystemMetrics(SM_CYFULLSCREEN)-GetSystemMetrics(SM_CYCAPTION)

2.获取绘图区域 引用Windows单元

function GetSystemTaskBarHeight:Integer;  
var  
  R:TRect;  
begin  
  SystemParametersInfo(SPI_GETWORKAREA,0,@R,0);  
  Result:=Screen.Height-R.Bottom;  
end;  

3.也是获取绘图区域的一种方法 引用ShellAPI单元

function GetTaskBarRect: Integer;  
var  
  TBData: TAPPBARDATA;  
begin  
  TBData.cbSize := SizeOf(TAPPBARDATA);  
  SHAppBarMessage(ABM_GETTASKBARPOS, TBData);  
  Result   :=Screen.Height-TBData.rc.Top;  
end;  
21
Sep
0

delphi窗体置顶几种方式的优缺点

1.只对主窗体有效

SetWindowPos(Handle,HWND_TOPMOST,Left,Top,Width,Height,SWP_NOACTIVATE or SWP_NOMOVE or SWP_NOSIZE);

2.函数 虽然也是调用API

function ForceForegroundWindow(hwnd: THandle): boolean;
const
    SPI_GETFOREGROUNDLOCKTIMEOUT = $2000;
    SPI_SETFOREGROUNDLOCKTIMEOUT = $2001;
var
    ForegroundThreadID: DWORD;
    ThisThreadID      : DWORD;
    timeout           : DWORD;
begin
    if IsIconic(hwnd) then ShowWindow(hwnd, SW_RESTORE);
    // Windows 98/2000 doesn't want to foreground a window when some other
    // window has keyboard focus
    if ((Win32Platform = VER_PLATFORM_WIN32_NT) and (Win32MajorVersion > 4))
        or
        ((Win32Platform = VER_PLATFORM_WIN32_WINDOWS) and
        ((Win32MajorVersion > 4) or ((Win32MajorVersion = 4) and
         (Win32MinorVersion > 0)))) then begin
        // Code from Karl E. Peterson, www.mvps.org/vb/sample.htm
        // Converted to Delphi by Ray Lischner
        // Published in The Delphi Magazine 55, page 16
        Result := false;
        ForegroundThreadID := GetWindowThreadProcessID(GetForegroundWindow,nil);
        ThisThreadID := GetWindowThreadPRocessId(hwnd,nil);
        if AttachThreadInput(ThisThreadID, ForegroundThreadID, true) then begin
            BringWindowToTop(hwnd); // IE 5.5 related hack
            SetForegroundWindow(hwnd);
            AttachThreadInput(ThisThreadID, ForegroundThreadID, false);
            Result := (GetForegroundWindow = hwnd);
        end;
        if not Result then begin
            // Code by Daniel P. Stasinski
            SystemParametersInfo(SPI_GETFOREGROUNDLOCKTIMEOUT, 0, @timeout, 0);
            SystemParametersInfo(SPI_SETFOREGROUNDLOCKTIMEOUT, 0, TObject(0), SPIF_SENDCHANGE);
            BringWindowToTop(hwnd); // IE 5.5 related hack
            SetForegroundWindow(hWnd);
            SystemParametersInfo(SPI_SETFOREGROUNDLOCKTIMEOUT, 0, TObject(timeout), SPIF_SENDCHANGE);
        end;
    end
    else begin
        BringWindowToTop(hwnd); // IE 5.5 related hack
        SetForegroundWindow(hwnd);
    end;
    Result := (GetForegroundWindow = hwnd);
end;

3.非主窗口置顶 把窗体的父窗体设为窗面 再调用上面的方法 别忘了把CAPTION设为空

procedure CreateParams(var Params: TCreateParams);
begin
  inherited;
  with Params do
  begin
    WndParent := GetdesktopWindow();
  end;
end;

4.最后一种,在调用上面的方法前先调用

Application.NormalizeTopMosts;

ps.1和2调用后 主窗体最小化,会跟着最小化,解决方法是用3 重载

procedure CreateParams(var Params: TCreateParams); override;
begin
  Params.WndParent := GetDesktopWindow;
end;