Accessing Win32 CreateEvent/SetEvent from WSH or other native Windows program

本秂侑毒 提交于 2020-01-06 06:17:10

问题


I need to interface with a program suite that uses named. Win32 Events (eg, CreateEvent() API) to communicate between running processes.

I'm able to do this with some very simple C code

 h = CreateEvent(NULL, FALSE, FALSE, argv[1]);
 if (h != INVALID_HANDLE_VALUE) SetEvent(h);

However, due to policy issues, I can't install custom binaries on production machines!

Is there a way to do this with Windows Scripting Host?

I could possibly get signed binaries added to the production environment - so other scripting language might be viable. Recommendations are welcome.


回答1:


If you just need a Win32 event for normal eventing purposes, you could use PowerShell. This will give you access to the .Net framework. This will allow you to indirectly access the API by using a managed event class such as ManualResetEvent. This is just a thin wrapper on top of the normal CreateEvent APIs.




回答2:


I can't install custom binaries on production machines! ... I could possibly get signed binaries added to the production environment

Sign your own binaries.

Whoever instituted such a policy that allows you to run arbitrary WSH programs but not binaries should pay for your code-signing cert.




回答3:


Python has a PyWin32 library that allows you to use Windows API functions, including CreateEvent/SetEvent.

In general (and with different level of convenience), you could use any language that allows defining and invoking external functions (from kernel32.dll in this case).



来源:https://stackoverflow.com/questions/858816/accessing-win32-createevent-setevent-from-wsh-or-other-native-windows-program

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!