-
-#ifdef _MSC_VER
-#pragma comment(lib,"delayimp")
-/*
- * CL command line should also be complemented with following:
- *
- * /link /delayload:advapi32.dll /delayload:user32.dll
- *
- * This is required if/as we want to support Win9x. With delayloaded
- * DLLs in question all we have to do is to make sure NT-specific
- * functions are not actually called under Win9x.
- */
-#endif
-
-#if defined(_WIN32_WINNT) && _WIN32_WINNT>=0x0333
-int IsService()
-{ HWINSTA h;
- DWORD len;
- WCHAR *name;
-
- GetDesktopWindow(); /* return value is ignored */
-
- h = GetProcessWindowStation();
- if (h==NULL) return -1;
-
- if (GetUserObjectInformationW (h,UOI_NAME,NULL,0,&len) ||
- GetLastError() != ERROR_INSUFFICIENT_BUFFER)
- return -1;
-
- if (len>512) return -1; /* paranoia */
- len++,len&=~1; /* paranoia */
-#ifdef _MSC_VER
- name=(WCHAR *)_alloca(len+sizeof(WCHAR));
-#else
- name=(WCHAR *)alloca(len+sizeof(WCHAR));
-#endif
- if (!GetUserObjectInformationW (h,UOI_NAME,name,len,&len))
- return -1;
-
- len++,len&=~1; /* paranoia */
- name[len/sizeof(WCHAR)]=L'\0'; /* paranoia */
-#if 1
- /* This doesn't cover "interactive" services [working with real
- * WinSta0's] nor programs started non-interactively by Task
- * Scheduler [those are working with SAWinSta]. */
- if (wcsstr(name,L"Service-0x")) return 1;
-#else
- /* This covers all non-interactive programs such as services. */
- if (!wcsstr(name,L"WinSta0")) return 1;
-#endif
- else return 0;
-}
-#endif