find OS drive by asp.net coding

Last post 11-08-2009 12:06 AM by jitendramcu. 7 replies.

Sort Posts:

  • find OS drive by asp.net coding

    11-07-2009, 2:14 AM
    • Member
      14 point Member
    • harry16
    • Member since 02-25-2008, 7:04 AM
    • Posts 158
    You get the best out of others when you give the best of yourself.
  • Re: find OS drive by asp.net coding

    11-07-2009, 4:51 AM
    Answer
    • All-Star
      26,465 point All-Star
    • qwe123kids
    • Member since 03-27-2008, 5:49 AM
    • Mumbai
    • Posts 4,497

    Hi,


    http://www.dotnetspider.com/resources/33834-Find-Driver-Details-VB-NET.aspx.aspx

    chk the above link

    Thanks
    Avinash Tiwari

    Remember to click “Mark as Answer” on the post, if it helps you.

    MY Blog

    Hacking Inside .net exe
  • Re: find OS drive by asp.net coding

    11-07-2009, 4:53 AM
    Answer
    • Contributor
      5,730 point Contributor
    • irokhes
    • Member since 10-29-2009, 5:46 AM
    • Posts 846

    Hi,

    the code below show how to get all drives on the computer, i think you could use it to solve your problem

    //get the drive names on the target computer
            DriveInfo[] drives = DriveInfo.GetDrives();
    
                foreach (DriveInfo drive in drives)
                {
                    //Console.WriteLine("Drive: {0} {1}", drive.Name, drive.DriveType);
                    
                    if (drive.DriveType.ToString() == "Fixed")
                    {
                        try
                        {
                            //Search for the folder in each drive
                            string[] dirs = Directory.GetDirectories(drive.Name, "MySql", SearchOption.AllDirectories);
    
                            Console.WriteLine("The number of directories found is {0}.", dirs.Length);
                            foreach (string dir in dirs)
                            {
                                Console.WriteLine(dir);
                            }
    
                        }
                        catch(Exception ex)
                        {
                            Console.WriteLine(ex.ToString());
                            
                        }
                    }    
                }

    good luck

    Please mark this post as answered if it helped you!

    mY BlOg
  • Re: find OS drive by asp.net coding

    11-07-2009, 4:53 AM
    • Contributor
      3,310 point Contributor
    • ramiramilu
    • Member since 08-12-2009, 10:16 AM
    • Posts 445

    Hello,

    USe Environment.SystemDirectory to get the system directory......

    And if you want to get the complete details of that directory then use System.IO.DirectoryInfo to get all files and directories in that folder....

    alternatively you can check it up solution mentioned here....

    http://bytes.com/topic/visual-basic-net/answers/366279-how-get-windows-directory

    Hope that helps...

    Thanks.

    Rami Vemula
    MCTS (Microsoft .NET Framework 3.5 - ASP.NET Application Development)

    If you got a possible solution to your question, then please mark the post as answer. Help the community to get better.
  • Re: find OS drive by asp.net coding

    11-07-2009, 4:59 AM
    • Member
      270 point Member
    • veenag81
    • Member since 07-04-2009, 7:04 AM
    • Gandhinagar,India
    • Posts 61

    The class System.Environment is used to retrieve information about the operating system.

    Some of the static members of this class are as follows:
    1) Environment.OSVersion - Gets the version of the operating system

  • Re: find OS drive by asp.net coding

    11-07-2009, 2:25 PM
    • All-Star
      63,012 point All-Star
    • TATWORTH
    • Member since 02-04-2003, 8:34 AM
    • England
    • Posts 12,309
    • TrustedFriends-MVPs

    The code

        #region " GetSystemDirectory       "
        /// <summary>
        /// Gets Location of System Directory
        /// </summary>
        /// <returns>Location of System Directory</returns>
        public static string GetSystemDirectory
        {
          get { return Environment.SystemDirectory; }
        }
        #endregion

    returns in my case: C:\Windows\system32

    A little sub-stringing gets you the OS drive.

    Don't forget to click "Mark as Answer" on the post that helped you.
    This credits that member, earns you a point and marks your thread as Resolved so we will all know you have been helped.
  • Re: find OS drive by asp.net coding

    11-07-2009, 2:40 PM
    Answer
    • Participant
      1,641 point Participant
    • vishwaraj1
    • Member since 11-07-2008, 7:44 PM
    • India
    • Posts 424

    see this code....
    
    
    add using System.Management;
    
    and this code,...
    ManagementClass mgnt = new ManagementClass("Win32_LogicalDisk");
                ManagementObjectCollection mcolln = mgnt.GetInstances();
                // to show the information of drives in grid..  
                foreach (ManagementObject strt in mcolln)
                {
                    string name = "";
                    string Description = ""; 
                    string capacity = "";
                    string usedspace = "";
                    string freespace = "";
                    string filesystem = "";
                    string volserialno = "";
    
                    name = Convert.ToString(strt["Name"]).ToString();
                    double capsity = Convert.ToDouble(strt["size"]) / 1073741824;
                    capacity = capsity.ToString("N3");
    
                    double freespc = Convert.ToDouble(strt["Freespace"]) / 1073741824;
                    freespace = freespc.ToString("N3");
                    double usdspac = (Convert.ToInt64(strt["size"]) - Convert.ToInt64(strt["Freespace"])) / 1073741824;
                    usedspace = usdspac.ToString("N3");
    
                    filesystem = Convert.ToString(strt["Filesystem"]).ToString();
                    Description = Convert.ToString(strt["Description"]).ToString();
                    volserialno = Convert.ToString(strt["VolumeSerialNumber"]).ToString();
                    
                }
    



    Regards:

    Vishwaraj Malik

    VB to C# Converter


    Please: Don't forget to click "Mark as Answer" on the post that helped you. That way future readers will know which post solved your issue.
  • Re: find OS drive by asp.net coding

    11-08-2009, 12:06 AM
    • Participant
      1,622 point Participant
    • jitendramcu
    • Member since 08-28-2009, 8:58 AM
    • Mumbai
    • Posts 285

    This is also useful for getting the system information in asp.net.

    Response.Write("Machine Name:->"+System.Environment.MachineName.ToString()); Response.Write("<br>System Directory:->" + System.Environment.SystemDirectory); Response.Write("<br>User Name:->" + System.Environment.UserName);
    Response.Write("<br>User Domain:->" + System.Environment.UserDomainName); Response.Write("<br>Physical Memory:->" + System.Environment.WorkingSet);
    string[] drvies = System.Environment.GetLogicalDrives();
    Response.Write("Logicial Drive of this PC:"+ string.Join(",",drvies));
    Response.Write("<br>*********************Special Folder *************"); Response.Write("<br>Program Fies:->"+ System.Environment.GetFolderPath(Environment.SpecialFolder.ProgramFiles));
    Response.Write("<br>Internet Cache:->" + System.Environment.GetFolderPath(Environment.SpecialFolder.CommonProgramFiles));
    Response.Write("<br>****************End of Special Folder *************"); Label1.Text ="Os Name:"+System.Environment.OSVersion.VersionString+"<br>"+ "OS Version:" + System.Environment.OSVersion.Version + "<br>" + "os ServicePack" + System.Environment.OSVersion.ServicePack + "<br>" + "OS PlateForm:" + System.Environment.OSVersion.Platform;
     

    Thanks,if it helps you then mark as "Answered"
    -----------------------------------------------
    Jitendra Kr.
    http://jitendra-aspnet.blogspot.com/


Page 1 of 1 (8 items)