4
Answers

what's going on with the forums?

Photo of Administrator

Administrator

22y
7.4k
1
We are working on fixing them at this stage.

Answers (4)

0
Photo of Vishal Gundage
NA 134 4.6k 7y
can u do some staff buddy Thank you !
0
Photo of Vishal Gundage
NA 134 4.6k 7y

I  was storing in that way in list now with the help that for i want implement this code as i post sometimes back that hardrive info..
 
0
Photo of Srikant Maruwada
NA 501 4.4k 7y
  1. namespace DemoConfig  
  2. {  
  3. class Program  
  4. {  
  5. static void Main(string[] args)  
  6. {  
  7. var listRemotes = new List<RemoteServerInfo>();  
  8. listRemotes.Add(  
  9. new RemoteServerInfo  
  10. {  
  11. ServerName = ConfigurationSettings.AppSettings["remoteServer1"],  
  12. UserName = ConfigurationSettings.AppSettings["remoteServer1UserName"],  
  13. Password = ConfigurationSettings.AppSettings["remoteServer1UserPassword"]  
  14. });  
  15.   
  16. listRemotes.Add(  
  17. new RemoteServerInfo  
  18. {  
  19. ServerName = ConfigurationSettings.AppSettings["remoteServer2"],  
  20. UserName = ConfigurationSettings.AppSettings["remoteServer2UserName"],  
  21. Password = ConfigurationSettings.AppSettings["remoteServer2UserPassword"]  
  22. });  
  23.   
  24. foreach (var remoteInfo in listRemotes)  
  25. {  
  26.   
  27. var srvname = remoteInfo.ServerName;  
  28. ConnectionOptions conn = new ConnectionOptions();  
  29. conn.Username = remoteInfo.UserName;  
  30. conn.Password = remoteInfo.Password;  
  31. string strNameSpace = @"\\";  
  32. if (srvname != "")  
  33. strNameSpace += srvname;  
  34. else  
  35. strNameSpace += ".";  
  36. strNameSpace += @"\root\cimv2";  
  37. System.Management.ManagementScope managementScope = new System.Management.ManagementScope(strNameSpace, conn);  
  38. System.Management.ObjectQuery query = new System.Management.ObjectQuery("select * from Win32_LogicalDisk");  
  39. ManagementObjectSearcher searcher = new ManagementObjectSearcher(managementScope, query);  
  40. }  
  41. }  
  42.   
  43. public class RemoteServerInfo  
  44. {  
  45. public string ServerName { getset; }  
  46.   
  47. public string UserName { getset; }  
  48.   
  49. public string Password { getset; }  
  50. }  
  51.   
  52. }  
  53. }  
Here is the code with simple approach. 
0
Photo of Vishal Gundage
NA 134 4.6k 7y
As u know srikant what i want buudy try to complete code .
0
Photo of Vishal Gundage
NA 134 4.6k 7y
ya offcourse has u mention code i write app.config file but i will access all at time i will used forach to read app settings now so can u please help to write code please i didn't understand what should i do.as u say iterate in for loop how? please do stuff srikant thankyou..i like ur way u helpn me..
0
Photo of Srikant Maruwada
NA 501 4.4k 7y
If you want all the remote machine's information, then get the username, password from app.config and store in collection. And iternate over this list in your logic.
 
 
in c# code:
string remoteServer1= ConfigurationSettings.AppSettings["remoteServer1"];
string remoteServer1UserName= ConfigurationSettings.AppSettings["remoteServer1UserName"];
string remoteServer1UserPassword= ConfigurationSettings.AppSettings["remoteServer1UserPassword"];
0
Photo of Vishal Gundage
NA 134 4.6k 7y
 
its my actaully code getting only single remote server information now i trying multiple which was i store some remote server username and passwrd in my app.config file.so please now let me know how i do
0
Photo of Srikant Maruwada
NA 501 4.4k 7y
In your code you are getting information from local machine. However with the below code you will get information from remote machine. Provide remote machine name in the "srvname".
 
Refer this article, which will give you idea to pass remote machine name and password.
 
https://msdn.microsoft.com/en-us/library/mt703458(v=vs.85).aspx
0
Photo of Vishal Gundage
NA 134 4.6k 7y
bro read my question again i didn't want single server information ..i already done this issue what u share here Now my focus is getting number of  remote server information?
thank you for answering  srikant
0
Photo of Srikant Maruwada
NA 501 4.4k 7y
Try using ManagementScope.
  1. var srvname=""serverName"// pass the server name  
  2. ConnectionOptions conn = new ConnectionOptions();  
  3. string strNameSpace = @"\\";  
  4. if (srvname != "")  
  5. strNameSpace += srvname;  
  6. else  
  7. strNameSpace += ".";  
  8. strNameSpace += @"\root\cimv2";  
  9. System.Management.ManagementScope managementScope = new System.Management.ManagementScope(strNameSpace, conn);  
  10. System.Management.ObjectQuery query = new System.Management.ObjectQuery("select * from Win32_LogicalDisk");  
  11. ManagementObjectSearcher searcher = new ManagementObjectSearcher(managementScope, query);  
https://msdn.microsoft.com/en-us/library/mt703458(v=vs.85).aspx