问题
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