This website requires JavaScript.
0
Issues
Pull Requests
Milestones
Explore
0
Create…
New Repository
New Migration
New Organization
public
Signed in as
public
Profile
Starred
Subscriptions
Settings
Help
Sign Out
yws
/
lc-mcp
Watch
1
Star
0
Fork
0
Code
Issues
Pull Requests
Actions
Packages
Projects
Releases
Wiki
Activity
Files
lc-mcp
/
scripts
/
or
Cancel
Edit File
Preview
Preview Changes
Spaces
Tabs
2
4
8
Wrap
No wrap
# -*- coding: utf-8 -*- """打印指定 Windows 终端服务会话的连接状态。 qwinsta 在计划任务/隐藏窗口上下文里拿不到输出, 所以用 WTS API。 用法: python session_state.py [session_id] 输出: Active / Connected / Disc / Idle / Listen / ... 或 UNKNOWN 退出码: 0 成功, 1 查询失败 """ import ctypes import sys from ctypes import wintypes WTS_CURRENT_SERVER_HANDLE = 0 WTS_CONNECT_STATE = 8 WTS_STATES = { 0: 'Active', 1: 'Connected', 2: 'ConnectQuery', 3: 'Shadow', 4: 'Disc', 5: 'Idle', 6: 'Listen', 7: 'Reset', 8: 'Down', 9: 'Init', } def main(argv): session_id = int(argv[1]) if len(argv) > 1 else 2 wts = ctypes.WinDLL('wtsapi32') wts.WTSQuerySessionInformationW.argtypes = [ wintypes.HANDLE, wintypes.DWORD, ctypes.c_int, ctypes.POINTER(ctypes.c_void_p), ctypes.POINTER(wintypes.DWORD), ] wts.WTSQuerySessionInformationW.restype = wintypes.BOOL wts.WTSFreeMemory.argtypes = [ctypes.c_void_p] buf = ctypes.c_void_p() size = wintypes.DWORD() ok = wts.WTSQuerySessionInformationW( WTS_CURRENT_SERVER_HANDLE, session_id, WTS_CONNECT_STATE, ctypes.byref(buf), ctypes.byref(size)) if not ok or not buf: print('UNKNOWN') return 1 try: state = ctypes.cast(buf, ctypes.POINTER(ctypes.c_uint)).contents.value finally: wts.WTSFreeMemory(buf) print(WTS_STATES.get(state, 'Unknown%d' % state)) return 0 if __name__ == '__main__': sys.exit(main(sys.argv))
Commit Changes
Add a Signed-off-by trailer by the committer at the end of the commit log message.
Commit directly to the
main
branch.
Create a
new branch
for this commit and start a pull request.
Commit Changes
Cancel