Jump to content

Create plugin in Visual Studio (vb)


Recommended Posts

Goodmorning paul,

Ok got the message, but the mstsc.exe opens on my laptop, so thats already good.  And i've hooped that the plugin is executed on the host side, so wouldn't it be easier to get the correct external ip?

Because I've got some working script to get external ip, but ofcourse: it is that of my laptop and not the server I want to make an RDP connection to.

So the problem is to run execute (on my laptop) the mstsc.exe command ... That already works, but with the external ip address of the server ... As the argument of mstsc.exe.

 

So briefly:

 

Now "mstsc.exe" opens on my laptop of I click the plugin button in webUI

 

But the goal is to open "mstsc.exe /v:externalipaddressserver" on my laptop, so I can do an RDP connection to that server...

 

 

Kind regards

Kurt

 

 

Hello Digbyp ... when the plugin is working I will post it on the forum with some extra info how to configure (FW) ... but all credit goes to paul of course

Link to comment
Share on other sites

  • Administrators

Here is the code that gets your public IP address of the current computer:

public string GetPublicIPAddress()
{
    var request = (HttpWebRequest) WebRequest.Create("http://checkip.dyndns.org");
    request.Method = "GET";
    WebResponse response = null;
    StreamReader reader = null;
    try
    {
        response = request.GetResponse();
        // ReSharper disable AssignNullToNotNullAttribute
        reader = new StreamReader(response.GetResponseStream());
        // ReSharper restore AssignNullToNotNullAttribute
        var result = reader.ReadToEnd();
        result = result.Remove(0, result.IndexOf("Address:", StringComparison.Ordinal) + 9);
        return result.Remove(result.IndexOf("</body>", StringComparison.Ordinal));
    }
    catch
    {
        return "127.0.0.1";
    }
    finally
    {
        if (reader != null)
        {
            reader.Close();
            reader.Dispose();
        }
       if (response != null)
           response.Close();
       request.Abort();
   }
}

Note: You may need some using statements (try pressing CTRL + . (dot) ) on the red types, or right click -> resolve -> select namespace.

 

This code gets the IP address using a free online service that returns your IP address (http://checkip.dyndns.org). It does not return the IP address of other monitored computers :). It will always be the IP address of the machine the code executes from.

 

Good Luck,

Paul.

Link to comment
Share on other sites

Crap ... It doenst work ... At all ... I've tested it till yesterday on a local system, and mstsc + ipadress opens just fine ...

 

But - the mean goal - was to open locally on my laptop, an RDP connection to a remote server via the external ip adress (already shown in webUI)

 

When I try it on another server, it doenst work at all .... Doesn't even opens mstsc ...

 

Crap Crap Crap ... It would have been soooooooo nice if this could work...

 

It must work somehow: how the hell do they open IE with maps.google.be when you click the external ip adres in the webUI ????

 

Greetings

Kurt

Link to comment
Share on other sites

  • Administrators

You can do a RDP connection using PC Monitor Dashboard using the context menu.

 

Don't get it wrong. Plugins and cloud instances are very useful when used properly. In your case you want a client side plugin which is not supported (well at least at the moment).

Link to comment
Share on other sites

  • Administrators

As far as I know PC Monitor release dates are not announced so when an update is release you will see it in the forum and social media. I'm not sure what feature you want to see into PC Monitor, launch mstsc from web app or execute code on webapp?

 

If so I highly doubt this will happen because it will pose a great security risk on users.

Edited by Paul
Link to comment
Share on other sites

  • 3 weeks later...
  • 4 months later...

Hi Paul,

 

I have a question regarding your code for the project PaulCsiki.SystemInfoPlugin. I have modify it a little bit to extarct som more information about my system but im stuck now. The question i have is why som of the data wont show in my plugin. If you take a look down here in the code, the blue marked code works just fine but the red does not?  Why? What did I do wrong? It seams as none of the Win32_PerfRawData classes wont work when I try to SELECT data from them. Can you please help me?

 

namespace Test3
{
    public class Plugin : ClientPlugin
    {
        private bool Paged
        {
            get { return GetValueForKey("paged") == "true"; }
            set { SetValueForKey("paged", value ? "true" : "false"); }
        }
 
        public override Groups GetAdditionalComputerDetails()
        {
            return GetData(Paged);
        }
 
        public override void CommandReceived(int commandId)
        {
            Paged = !Paged;
        }
 
        public override Groups GetPageDetails(int pageId)
        {
            return GetData(false);
        }
 
        public override void PageCommandReceived(int pageId, int commandId)
        {
            CommandReceived(commandId);
        }
 
        private Groups GetData(bool paged)
        {
            var container = new Groups();
 
            if (paged)
            {
                var page = new Group("SystemInfo Plugin");
                page.Items.Add(new PageItem(1, "Open SystemInfo"));
                page.Items.Add(new CommandItem(1, Paged ? "Disable paged view" : "Enable paged view"));
                container.Add(page);
            }
            else
            {
                var wmiPath = string.Format(@"\\{0}\root\cimv2", Environment.MachineName);
                
                var biosDetails = QueryWMI(wmiPath, "SELECT Version FROM Win32_BIOS");
                var osDetails = QueryWMI(wmiPath, "SELECT Caption, " +
                                                  "Version, " +
                                                  "WindowsDirectory, " + 
                                                  "FreePhysicalMemory, " +
                                                  "TotalVirtualMemorySize, " +
                                                  "FreeVirtualMemory, " +
                                                  "SizeStoredInPagingFiles FROM Win32_OperatingSystem");
                var computerDetails = QueryWMI(wmiPath, "SELECT Name, " +
                                                        "Manufacturer, " +
                                                        "Model, " +
                                                        "UserName, " +
                                                        "TotalPhysicalMemory FROM Win32_ComputerSystem");
                var processorDetails = QueryWMI(wmiPath, "SELECT Description, " +
                                                         "LoadPercentage, " +
                                                         "NumberOfCores FROM Win32_Processor");
                var memoryDetails = QueryWMI(wmiPath, "SELECT AvailableMBytes, " +
                                                            "Description, " +
                                                            "CacheBytes FROM Win32_PerfRawData_PerfOS_Memory");
                var networkDetails = QueryWMI(wmiPath, "SELECT Name, " +
                                                         "UserName, " +
                                                         "ConnectionState, " +
                                                         "RemoteName, " +
                                                         "RemotePath, " +
                                                         "Status FROM Win32_NetworkConnection");
                var tcpipDetails = QueryWMI(wmiPath, "SELECT Name, " +
                                                         "Description, " +
                                                         "Caption, " +
                                                         "BytesSentPerSec, " +
                                                         "BytesReceivedPerSec, " +
                                                         "BytesTotalPerSec, " +
                                                         "CurrentBandwidth, " +
                                                         "PacketsPerSec FROM Win32_PerfRawData_Tcpip_NetworkInterface");
 
                if (biosDetails != null)
                {
                    var biosGroup = new Group("BIOS Details");
                    foreach (var biosDetail in biosDetails)
                        biosGroup.Items.Add(new SimpleItem(biosDetail.Name, biosDetail.Value.ToString()));
                    container.Add(biosGroup);
                }
                if (osDetails != null)
                {
                    var osGroup = new Group("Operating System Details");
                    foreach (var osDetail in osDetails)
                        osGroup.Items.Add(new SimpleItem(osDetail.Name, osDetail.Value.ToString()));
                    container.Add(osGroup);
                }
                if (computerDetails != null)
                {
                    var computerGroup = new Group("Computer Details");
                    foreach (var computerDetail in computerDetails)
                        computerGroup.Items.Add(new SimpleItem(computerDetail.Name, computerDetail.Value.ToString()));
                    container.Add(computerGroup);
                }
                if (processorDetails != null)
                {
                    var processorGroup = new Group("Processor Details");
                    foreach (var processorDetail in processorDetails)
                        processorGroup.Items.Add(new SimpleItem(processorDetail.Name, processorDetail.Value.ToString()));
                    container.Add(processorGroup);
                }
                if (memoryDetails != null)
                {
                    var memoryGroup = new Group("Memory Details");
                    foreach (var memoryDetail in memoryDetails)
                        memoryGroup.Items.Add(new SimpleItem(memoryDetail.Name, memoryDetail.Value.ToString()));
                    container.Add(memoryGroup);
                }
                if (networkDetails != null)
                {
                    var networkGroup = new Group("Network Details");
                    foreach (var networkDetail in networkDetails)
                        networkGroup.Items.Add(new SimpleItem(networkDetail.Name, networkDetail.Value.ToString()));
                    container.Add(networkGroup);
                } 
                if (tcpipDetails != null)
                {
                    var tcpipGroup = new Group("TCPIP Details");
                    foreach (var tcpipDetail in tcpipDetails)
                        tcpipGroup.Items.Add(new SimpleItem(tcpipDetail.Name, tcpipDetail.Value.ToString()));
                    container.Add(tcpipGroup);
                }
 
                if (container.Count == 0)
                {
                    var error = new Group("Error");
                    error.Items.Add(new SimpleItem("Error", "No settings founds, check your queries.", SimpleItemStyle.ERROR));
                    container.Add(error);
                }
 
                var commands = new Group("Commands");
                commands.Items.Add(new CommandItem(1, Paged ? "Disable paged view" : "Enable paged view"));
                container.Add(commands);
            }
 
            return container;
        }
 
        public override Version GetMinimumRequiredAgentVersion()
        {
            return new Version(3, 8);
        }
 
        public override string GetPluginName()
        {
            return "META.SystemInfoPlugin";
        }
 
        public override string GetPluginDescription()
        {
            return "Plugin that shows information of your system using WMI";
        }
 
        public override Version GetPluginVersion()
        {
            return new Version(1, 0);
        }
 
        private static IEnumerable<PropertyData> QueryWMI(string path, string query)
        {
            ManagementObjectCollection coll = null;
            ManagementObjectSearcher searcher = null;
            var list = new List<PropertyData>();
            try
            {
                searcher = new ManagementObjectSearcher(path, query);
                coll = searcher.Get();
                list.AddRange(coll.OfType<ManagementObject>().Select(item => item.Properties).SelectMany(innerItem => innerItem.OfType<PropertyData>()));
                return list;
            }
            catch
            {
                return list;
            }
            finally
            {
                if (coll != null)
                    coll.Dispose();
                if (searcher != null)
                    searcher.Dispose();
            }
        }
    }
}
 
Link to comment
Share on other sites

Hi Paul,

 

Thank you for a quick respons. I can try it on my home system. Right now im att work and im sitting on Win 8.1. Is it possible that it can differ between win 7 and win 8.1? Also witch .NET framework version are u uising? Can that be the problem? Because when i compile the code i seent you it works then when i run the .dll fil in pc monitor the when i look under my plugin its just trying to load the data then after a while it says no data available. But when i comet away the red marked code and run it again then it works. I get the indo i want.

 

Best Regards,

Meta 

Link to comment
Share on other sites

Hi Paul,

 

Just wanted to let you know that i solved the problem. Some of the values I was trying to get ware null. It didnt sem to like that.  

 

Thanks for the help and contribution you are doing here. Grate job man! 

 

Regards,

Meta

Link to comment
Share on other sites

  • Administrators

Hello Meta,

 

Congrats on finding the problem. I did copy your code and test it out but only in a debugger. I did see that some values were null but it never occurred to me that I was actually referencing a null instance. Thanks for the heads-up!

 

Paul.

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...