Can you use WMI to create an MSMQ message queue (PRIVATE queue)? - wmi

I need to create a PRIVATE message queue on a remote machine and I have resolved to fact that I can't do this with the .NET Framework in a straight forward manner. I can create a public message queue on a remote machine, but not a PRIVATE one. I can create a message queue (public or private) locally.
I am wondering if anyone knows how to access MSMQ through WMI.
Edit: I don't see anything to do it with using the MSMQ Provider. May have to get tricky and use PSExec to log onto a remote server and execute some code.

Yes, queue creation is simple in .NET, however you cannot create a private queue on a remote machine this way.
I have been thinking about adding queue creation to the MSMQ WMI provider for some time... If you need it for a real product / customer, you can contact me and I will consider giving this feature a priority.
All the best,
Yoel Arnon

A blog post about MSMQ and WMI is here: http://msmq.spaces.live.com/blog/cns!393534E869CE55B7!210.entry
It says there is a provider here: http://www.msmq.biz/Blog/MSMQWmiSetup.msi
It also says there is a reference here: http://www.msmq.biz/Blog/MSMQ%20WMI%20Provider%20Objects.doc
Hope this helps.

WMI can't do this out-of-box. The previous answer has some obsucre WMI provider, but it doesn't even seem to support Queue creation.
This is very simple in .NET however! I wouldn't go so far as PSExec.
MessageQueue.Create

I was wanting to create remote private queues also, but since .NET doesn't support it, we decided we will just use remote public queues instead. If we set Send and Receive permissions on the queues as desired, this should be fine.
One idea for a work around would be to write your own Windows service or web service that runs on the same machine where the queue needs to reside. You could call this service remotely through a socket or over http, and your locally-running code could create the local private queue.
If you use the direct name format to reference the queue, you can Send and Receive from a remote private queue.

set qinfo = CreateObject("MSMQ.MSMQQueueInfo")
qinfo.PathName = ".\Private$\TestQueue"
qinfo.Label = ".\Private$\TestQueue"
qinfo.Journal = "1"
qinfo.Create
Copy the code in a text editor, save the file as .vbs and execute.

Related

Disable prevent windows log event

I'm using WMI (Windows Management Instrumentation) to try to collect some information from a allot of remote computers.
The issue is that every time I try to initiate a connection to a remote computer/resource using:
//IWbemLocator::ConnectServer method (wbemcli.h)
m_pLoc->ConnectServer ....
where
IWbemLocator *m_pLoc;
(You can assume m_pLoc is correctly initialized)
, if the remote resource is unavailable, Windows generates a log event in the Windows Event Viewer:
DCOM was unable to communicate with the computer ....using any of the
configured protocols; requested by PID .....
The problem is that given a huge number of remotes that at some point are not accessible the logs get flooded.
Is there any way to control or to prevent Windows from pushing a event in the Event Viewer every time I try to initiate a connection?
Seems that arguments for :
IWbemLocator::ConnectServer method (wbemcli.h)
or
CoCreateInstance used to intialize an IWbemLocator do not permit this sort of very custom configuration I'm looking for.
Any suggestion or alternatives?
Thank you!
Looking at the message logged in EventViewer more closely, I can see that this is a DCOM thing, and it looks like you can turn DCOM error logging off by (as usual) tweaking the registry.
The key you want is:
HKEY_LOCAL_MACHINE
SOFTWARE
Microsoft
Ole
And then create a DWORD value in there called ActivationFailureLoggingLevel and set it to 2.
Info gleaned from here. I haven't tested this myself but it looks like it should work.

Multiple partial results in a UWP app service

I am trying to use an UWP app service to provide some non-UI processing service to other app including the host app. For responsiveness, I want to return the result progressively. Think about grep-ping a folder for files containing a certain string: It would be better to report the files as we found it instead of reporting everything at the end.
So my question is: Can this scenario be achieved with the current UWP technology? (I think it is probably possible via polling using the multiple app instances approach. I want to know if there's an easier method with app service.)
The AppServiceConnection is a bi-directional communication pipe, so you can use it to communicate progress updates from the service to the client. No need for polling. Just retain a reference to the AppServiceConnection instance in your service implementation once the client has connected and then call SendMessageAsync to send progress updates to client whenever you want.

communicating with windows service using SERVICE_USER_DEFINED_CONTROL

I am looking forward for an example for using a user defined control code in services. I want to send a user defined command to my windows service. At this command windows service will create a named-pipe for client process, and client will establish a connection with this named-pipe by CreateFile function. My custom control sometimes works well but later it shows error for invalidation.
So how can I establish information exchange between a service and various clients?
SERVICE_USER_DEFINED_CONTROL is rarely used. When it is used, it is generally to prompt the service to re-read its configuration file. (On unix SIGHUP is generally used for the same purpose).
In your case the correct answer is to simply create the named pipe on startup and keep listening, and wait for someone to connect if they ever do.

How to communicate between service controller and a service/daemon?

It is easy to display the status of a Windows service or to control it (start/stop) from a GUI application but the question if how about receiving/sending notifications from the service? Like: service telling to the user monitoring it that it needs attention.
Please consider that you can have several controllers started at any time in a multi-user environment.
Do you know an example(open source) for this kind of communication?
Extra points for a platform independent solution :)
If the "user" monitoring the service is a person, how about writing to an event log and then having your enterprise event monitoring system send alerts. Alternatively, have the service log the issue to the event log and then send an email.
If the "user" or client of the service is a separate or multiple applications here are a couple thoughts without fully understadning your problem.
Write to file. Have the client tell the service what file or some agreed token to create a file for that particular client instance and then have the service write to the file. The client can then monitor the file.
Status Ping. Have the client ping the service on a regular basis in a background thread to ask the service how it is doing. If unhealthy, then the client could ping the service for more information. Kind of like getting the LastMessage.
Open Sockets or End Point. Find a way to setup communication back from the service so that the service can call the client. This may be initiated by the client first telling the service where it is so it can call back. I forget the specifics, but WCF should be able to handle this out of the box for you. If you want something more generic you may need to roll your own.
Hope these ideas help.
As an option, use our MsgConnect (free with source) to send messages between services and controllers (crossplatform). Communication between services and controllers is possible both locally (via MMF or socket transport) and remotely (via socket transport).

Capturing network status change event

I am trying to get events when the internet connection is reestablished after it is lost. It is for a data transfer software that I am developing. If I lose the network during data transfer, I would like to be notified when it is back and continue the transfer automatically.
I can of course create a separate thread and check the network once in a while with a timer, but maybe there is a better option out there.
I am developing for windows mainly, in C++ (not .net).
I can also use wxwidgets (I use it for GUI) but I doubt it offers any related functionality.
You might want to check out the System Event Notification Server (SENS) API http://msdn.microsoft.com/en-us/library/cc185680(VS.85).aspx
I have not actually used it, but it seems like it supplies the events your looking for.
EDIT:
WMI appears to have all the information you need about various network connectivity and state changes. It also has an asynchronous event model that can be used to get notifications. The trick is, i suppose, generating the proper WMI query to get the information you want. This blog looks like the right type of query, and this MSDN explains how to handle the events asynchronously.
I don't know which protocol you use and whether you can control the destination, but in that case, the destination can poll for a retry. The destination knows best what it has received, so it can give the received number of bytes as offset for the retransmission.
This MSDN link gives a very detailed example of how to capture events on WMI with COM. The example doesn't actually capture network events - but I believe that if you plug the right query in, it would work.
(lots of code here, so I'm not copying it into the answer)
http://msdn.microsoft.com/en-us/library/aa390425%28v=vs.85%29.aspx
this Codeproject link gives detail on
How to use the Windows NLM API to get notified of new network
connectivity
And maybe helpful to any challenge related to this one.
An application often needs to know if the machine has internet
connectivity and take actions depending on that. In this sample, we
are looking at the usage of the Windows NLM API in managed code so
that an application can choose to respond to internet connectivity
changes. There are many other specific NLM APIs for checking domain
connectivity, network adapter interfaces etc., that haven't been
mentioned in this article; you can refer to this link for further
details. The downloadable zip file has the source code.
more reading here
https://www.codeproject.com/Articles/34650/How-to-use-the-Windows-NLM-API-to-get-notified-of