Analyzing remote computer's disk space without credentials.
-
Friday, August 10, 2012 10:41 AM
Hello,
I want to know the space available on each drive of remote computer. For that I am using the following code and its working fine.
ConnectionOptions oConn = new ConnectionOptions(); oConn.Username = "username"; oConn.Password = "password"; string strNameSpace = @"\\"; if (srvname != "") strNameSpace += srvname; else strNameSpace += "."; strNameSpace += @"\root\cimv2"; ManagementScope oMs = new ManagementScope(strNameSpace, oConn); ObjectQuery oQuery = new ObjectQuery("select FreeSpace,Size,Name from Win32_LogicalDisk where DriveType=3"); ManagementObjectSearcher oSearcher = new ManagementObjectSearcher(oMs, oQuery); ManagementObjectCollection oReturnCollection = oSearcher.Get(); foreach (ManagementObject oReturn in oReturnCollection) { MessageBox.Show("Drive Name : " + oReturn["Name"].ToString() + "\nFree Space =" + (Convert.ToDouble(oReturn["FreeSpace"]) / 1048576) / 1024 + " GB. \nTotal Space = " + (Convert.ToDouble(oReturn["Size"]) / 1048576) / 1024 + " GB."); }Just wanted to know if it is possible to connect to remote computer without specifing the username and password. Want to skip following two statements;
oConn.Username = "username"; oConn.Password = "password";
Is it possible?
Please let me know.
Thanks,
-Kaustubh
All Replies
-
Friday, August 10, 2012 11:08 AM
It is only possible if an account is available which does not require logon credentials from a remote connection - you do not want to do this!
As trying to secure the account so that it is limited to only safe operations is very difficult indeed.
You could create a Windows Service on the remote machine which you can remotely ask information from without credentials. This is how I would do it. It is a lot easier to code and control.
Digital Forensic Software Developer
CCS LABS Digital Forensic Software
Mark as Answer or Vote up if useful thank you!- Marked As Answer by Bob ShenMicrosoft Contingent Staff, Moderator Tuesday, August 21, 2012 10:10 AM
-
Friday, August 10, 2012 1:26 PM
you can put the code(.bat/.exe) that calculates local machine's disk space on that remote server in some shared drive and then call/execute it remotely from outside with another code. http://stackoverflow.com/questions/1393711/c-sharp-get-free-disk-space
regards
joon
- Marked As Answer by Bob ShenMicrosoft Contingent Staff, Moderator Tuesday, August 21, 2012 10:10 AM

