Remote MSMQ count via Powershell - C#
Формулировка задачи:
В сети нашел такую статью про то, как удаленно узнать сколько сообщений. Так как все методы проверил, не помогает:
Message-Queue-Counting-Comparisions
Там толькона том компьютере, в каком набрал код, запускаю, ввожу данные локального компьютера, и все работает.
Но стоит запустить это в сети, чтоб удаленно проверить, то ошибка.
нужна ваша помощь. Которое время не могу решить проблему с удаленным считыванием msmq
PowerShell (WMI) Method
по утверждению автора должно помочь для удаленных компьютор Вот и сам код:static void Main(string[] args)
{
Console.Write("QueuePath:");
string queuePath = Console.ReadLine();
Console.Write("machine:");
string machine = Console.ReadLine();
Console.Write("username:");
string username = Console.ReadLine();
Console.Write("password:");
string password = Console.ReadLine();
try
{
Console.WriteLine("Count:" + GetPowerShellCount(queuePath,machine,username,password));
}
catch(Exception ex)
{
Console.WriteLine(ex.ToString());
}
Console.ReadLine();
}
static private int GetPowerShellCount(string queuePath, string machine, string username, string password)
{
var path = string.Format(@"\\{0}\root\CIMv2", machine);
ManagementScope scope;
if (string.IsNullOrEmpty(username))
{
scope = new ManagementScope(path);
}
else
{
var options = new ConnectionOptions { Username = username, Password = password };
scope = new ManagementScope(path, options);
}
scope.Connect();
if (queuePath.StartsWith(".\\")) queuePath = queuePath.Replace(".\\", string.Format("{0}\\", machine));
string queryString = String.Format("SELECT * FROM Win32_PerfFormattedData_msmq_MSMQQueue");
var query = new ObjectQuery(queryString);
var searcher = new ManagementObjectSearcher(scope, query);
IEnumerable<int> messageCountEnumerable =
from ManagementObject queue in searcher.Get()
select (int)(UInt64)queue.GetPropertyValue("MessagesInQueue");
//IEnumerable<string> messageCountEnumerable =
// from ManagementObject queue in searcher.Get()
// select (string)queue.GetPropertyValue("Name");
var x = messageCountEnumerable.First();
return x;
}Решение задачи: «Remote MSMQ count via Powershell»
textual
Листинг программы
SELECT * FROM Win32_PerfFormattedData_msmq_MSMQQueue WHERE Name LIKE '%product'