2015年12月18日星期五

Windows 10 新功能:系统服务有增减时会有通知弹出来,可以更好地知道发生了什么

 psexec之类的工具会动态增添service,关闭时删除,Windows10会亲切的提醒系统发生了重要的变化,这个真的贴心,有进步啊。

贴几个图吧,没用psexec,该用PAExec了,一样的效果:
以管理员执行 paexec -i -s cmd,右下角就会弹出通知。

Windows 10 added two undocumented service type: userown, usershare

sc.exe Usage:
...
type= <own|share|interact|kernel|filesys|rec|adapt|userown|usershare>
...

The strange things is, service created as "userown" type will not show in Service Manager, just show in Registry Editor.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
C:\Users\q\Downloads>sc create TrustedInstaller_Test binPath= "c:\windows\system32\cmd.exe /K start" type= userown obj= TrustedInstaller
[SC] CreateService SUCCESS
C:\Users\q\Downloads>sc qc TrustedInstaller_Test
[SC] QueryServiceConfig SUCCESS
SERVICE_NAME: TrustedInstaller_Test
        TYPE               : 50  USER_OWN_PROCESS TEMPLATE
        START_TYPE         : 3   DEMAND_START
        ERROR_CONTROL      : 1   NORMAL
        BINARY_PATH_NAME   : c:\windows\system32\cmd.exe /K start
        LOAD_ORDER_GROUP   :
        TAG                : 0
        DISPLAY_NAME       : TrustedInstaller_Test
        DEPENDENCIES       :
        SERVICE_START_NAME :

The  "USER_OWN_PROCESS TEMPLATE" is not documented.

2015年12月3日星期四

做了一个Mac里的工具:列出所有的Windows的信息,包括其进程ID

在Mac里有时候出了一个画面顿住了,需要找到他的进程号以便杀了他,KillAll有时误杀,所以需要更仔细的找到进程号。但是遗憾的是,Mac里没有Windows里的Spy++或者Process Explorer那样拖拽到画面上得到进程号的方法,只好拼凑了一个工具lswin.py。

用法: (针对结果再自己做grep吧)
$ python lswin.py

    PID WinID  x,y,w,h                  [Title] SubTitle
------- -----  ---------------------    -------------------------------------------
    169  1956 {0,-38,1280,25        }   [Window Server] Backstop Menubar
    169  1955 {0,-60,1280,22        }   [Window Server] Menubar
    169   396 {0,-38,1280,25        }   [Window Server] Backstop Menubar
    169   395 {0,-60,1280,22        }   [Window Server] Menubar
    169     6 {0,0,0,0              }   [Window Server] Cursor
    169     4 {0,22,1280,25         }   [Window Server] Backstop Menubar
    169     3 {0,0,1280,22          }   [Window Server] Menubar
    169     2 {0,0,1280,800         }   [Window Server] Desktop
    262   404 {0,-38,1280,38        }   [Google Chrome] 
    262   393 {0,0,1280,800         }   [Google Chrome] 
    262   380 {100,100,1,1          }   [Google Chrome] Focus Proxy
    262   351 {1189,45,46,18        }   [Google Chrome] 
    262    51 {0,0,1280,800         }   [Google Chrome] sjitech/mac_list_windows_pids
    262    50 {0,755,1,1            }   [Google Chrome] 
    262    43 {0,0,1280,22          }   [Google Chrome]
    262    42 {0,0,1280,22          }   [Google Chrome]
    266  3294 {0,23,1276,777        }   [Sublime Text] README.md — mac_list_windows_pids
    266  1954 {0,-38,1280,38        }   [Sublime Text] 
    266  1953 {0,0,1280,800         }   [Sublime Text] 
    266  1952 {0,0,1280,800         }   [Sublime Text] 
    266   345 {529,83,116,56        }   [Sublime Text] 
    266   188 {100,100,1,1          }   [Sublime Text] Focus Proxy
    266   186 {0,0,1280,22          }   [Sublime Text]
    266   185 {0,0,1280,22          }   [Sublime Text]
    266    93 {0,0,1280,800         }   [Sublime Text] lswin
    ... ...

源码,很短,就贴下了:
?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
#!/usr/bin/env python
 
import Quartz
 
#wl = Quartz.CGWindowListCopyWindowInfo( Quartz.kCGWindowListOptionOnScreenOnly | Quartz.kCGWindowListExcludeDesktopElements, Quartz.kCGNullWindowID)
wl = Quartz.CGWindowListCopyWindowInfo( Quartz.kCGWindowListOptionAll, Quartz.kCGNullWindowID)
 
wl = sorted(wl, key=lambda k: k.valueForKey_('kCGWindowOwnerPID'))
 
#print wl
 
print 'PID'.rjust(7+ ' ' + 'WinID'.rjust(5+ '  ' + 'x,y,w,h'.ljust(21+ ' ' + '\t[Title] SubTitle'
print '-'.rjust(7,'-'+ ' ' + '-'.rjust(5,'-'+ '  ' + '-'.ljust(21,'-'+ ' ' + '\t-------------------------------------------'
 
for in wl:
    print ( \
        str(v.valueForKey_('kCGWindowOwnerPID'or '?').rjust(7+ \
        ' ' + str(v.valueForKey_('kCGWindowNumber'or '?').rjust(5+ \
        ' {' + ('' if v.valueForKey_('kCGWindowBounds') is None else \
           ( \
               str(int(v.valueForKey_('kCGWindowBounds').valueForKey_('X')))     + ',' + \
               str(int(v.valueForKey_('kCGWindowBounds').valueForKey_('Y')))     + ',' + \
               str(int(v.valueForKey_('kCGWindowBounds').valueForKey_('Width'))) + ',' + \
               str(int(v.valueForKey_('kCGWindowBounds').valueForKey_('Height'))) \
           ) \
           ).ljust(21+ \
        '}' + \
        '\t[' + ((v.valueForKey_('kCGWindowOwnerName'or '') + ']') + \
        ('' if v.valueForKey_('kCGWindowName') is None else (' ' + v.valueForKey_('kCGWindowName') or '')) \
    ).encode('utf8')