Message118348
| Author |
ocean-city |
| Recipients |
amaury.forgeotdarc, brian.curtin, ocean-city, paul.moore, theller, tim.golden |
| Date |
2010年10月11日.10:07:38 |
| SpamBayes Score |
0.00026849116 |
| Marked as misclassified |
No |
| Message-id |
<1286791661.81.0.977211875847.issue9055@psf.upfronthosting.co.za> |
| In-reply-to |
| Content |
Hello. I've been finding the way to determine whether
the process is running as service or not. Does this way
work? On my environment, True is returned. I hope False
will be returned in service environment.
http://msdn.microsoft.com/en-us/library/d56de412%28v=VS.80%29.aspx
http://msdn.microsoft.com/en-us/library/ms683225%28VS.85%29.aspx
/////////////////////////////////////////
from __future__ import print_function
import ctypes
from ctypes.wintypes import *
UOI_FLAGS = 1
WSF_VISIBLE = 0x0001
class USEROBJECTFLAGS(ctypes.Structure):
_fields_ = [("fInherit", BOOL),
("fReserved", BOOL),
("dwFlags", DWORD)]
def window_station_has_display_surfaces():
dll = ctypes.windll.user32
h = dll.GetProcessWindowStation()
if not h:
raise ctypes.WinError()
uof = USEROBJECTFLAGS()
needed = DWORD()
res = dll.GetUserObjectInformationW(h,
UOI_FLAGS,
ctypes.byref(uof),
ctypes.sizeof(uof),
ctypes.byref(needed))
if not res:
raise ctypes.WinError()
return bool(uof.dwFlags & WSF_VISIBLE)
def main():
print(window_station_has_display_surfaces())
if __name__ == '__main__':
main() |
|