This does as described. It'll enumerate the shares of any remote machine, and list them. This invokes WMI, and I've incorporated the functionality into my MobileExec 2011 program.
if (words[0].ToString().ToLower() == "shares")
{
this.Label1.Style["text-align"] = "left";
Label1.ForeColor = Color.Black;
Label1.ForeColor = Color.Black;
Label1.Text = "Sorry! Shares could not be found!";
ConnectionOptions co = new ConnectionOptions();
co.Username = txtUsername.Text;
co.Password = txtPassword.Text;
co.Impersonation = ImpersonationLevel.Impersonate;
co.EnablePrivileges = true;
co.Authentication = AuthenticationLevel.PacketPrivacy;
//"Select * from Win32_Directory where Name = 'c:\\Scripts'"
string queryStr = "Select * From Win32_Share";
System.Net.IPHostEntry h =
System.Net.Dns.GetHostEntry(System.Net.Dns.GetHostName());
string IPAddress = h.AddressList.GetValue(0).ToString();
string lm = System.Net.Dns.GetHostName().ToString();
if (txtUsername.Text == "" || txtPassword.Text == ""
|| txtServer.Text == "127.0.0.1"
|| txtServer.Text.ToLower() == "localhost"
|| txtServer.Text.ToLower() == lm.ToLower()
|| txtServer.Text.ToLower() == IPAddress.ToLower())
{
co.Username = null;
co.Password = null;
}
string temp1 = txtServer.Text;
System.Management.ManagementScope ms =
new System.Management.ManagementScope
("\\\\" + temp1 + "\\root\\cimv2", co);
ObjectQuery oQuery = new ObjectQuery(queryStr);
//Execute the query
ManagementObjectSearcher oSearcher = new ManagementObjectSearcher(ms, oQuery);
//Get the results
ManagementObjectCollection oReturnCollection = oSearcher.Get();
Label1.Text = "Shares for <b>" +
temp1 + "</b><br />------------------------------<br />";
foreach (ManagementObject oReturn in oReturnCollection)
{
Label1.Text += oReturn["Name"] + "<br />";
// oReturn.Dispose();
}
}
//end of shares
Various Scripts and Application Code Segments for .NET, VB, C#, C++, C, Java, JavaScript, HTML, Python, Perl, AutoIT, Batch, ASP Classic, Objective-C, Swift, Unreal Engine 4, Unity3D & others. Also contains numerous IT tidbits, procedures, and tricks including Technology Hacks on various platforms.
Subscribe to:
Post Comments (Atom)
Generating "Always On Top" NSWindow in macOS across all detected displays
Also: Using UIKit & Cocoa Frameworks using Objective-C In m acOS or OS X , written in either Objective-C or Swift Langues, you m...
-
In Unreal Engine 4 you will eventually need Linear Interpolation between two values to do something like ping pong between two float val...
-
Recently Possess () has been deprecated from UE4 , and when writing classes based on AAIController you have to use the function OnPossess ...
-
Often we intermingle C++ and Blueprints, and need for the two to communicate. With Behavior Trees, using ENUMs is an everyday occurrence an...
No comments:
Post a Comment