Results 1 to 7 of 7

Thread: my.computer

  1. #1

    Thread Starter
    New Member
    Join Date
    Jan 2007
    Posts
    6

    my.computer

    Hi,
    I'm a Vb.net programmer moving to C#.
    I wanted to know if anbody could tell me how to use the my.computer object -from Vb.net- in C#.
    Thanks!

  2. #2
    Shared Member
    Join Date
    May 2005
    Location
    Kashmir, India
    Posts
    2,277

    Re: my.computer

    Simplest way would be to add a Reference to Microsoft.Visualbasic.dll. And then add using Microsoft.VisualBasic.MyServices; at the top of your module. And then you can use the code like this
    Code:
    MyComputer thisComputer = new MyComputer();
    Use [code] source code here[/code] tags when you post source code.

    My Articles

  3. #3
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  4. #4
    Shared Member
    Join Date
    May 2005
    Location
    Kashmir, India
    Posts
    2,277

    Re: my.computer

    Sometime I think people just forget that there is something known as GOOGLE too in this world. And for that matter they even forget that MS has a dedicated network for developers who need to learn new things and search for resources, which is known as MSDN.
    Use [code] source code here[/code] tags when you post source code.

    My Articles

  5. #5
    Fanatic Member Bombdrop's Avatar
    Join Date
    Apr 2001
    Location
    St Helens, England, UK
    Posts
    667

    Question Re: my.computer

    Is it really best practice to use these libraries in C#?

  6. #6
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: my.computer

    Quote Originally Posted by Bombdrop
    Is it really best practice to use these libraries in C#?
    The My namespace makes many tasks easier, which is why it was created. If you don't want to do things the long way in C# then you could create your own library to make these tasks easier. You would then have a .NET assembly that you could reference in your C# projects that would make performing certain tasks easier. Microsoft.VisualBasic.dll is a .NET assembly that you can reference in your C# projects that makes performing certain tasks easier, and you don't have to spend the time writing it yourself. You choose.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  7. #7
    Fanatic Member
    Join Date
    Jan 2006
    Posts
    710

    Re: my.computer

    Quote Originally Posted by Shuja Ali
    Simplest way would be to add a Reference to Microsoft.Visualbasic.dll. And then add using Microsoft.VisualBasic.MyServices; at the top of your module. And then you can use the code like this
    Code:
    MyComputer thisComputer = new MyComputer();
    Unfortunately, this is a case where google is not your friend. That 'solution' has been widely circulated, but doesn't work. You can't access "My" even with a reference to the Microsoft.VisualBasic assembly.

    Here is a support file we include with Instant C# which will provide some of what you need - the missing parts are converted in-line by Instant C#. Download the demo edition for details:

    Code:
    //----------------------------------------------------------------------------------------
    //	Copyright © 2005 - 2007 Tangible Software Solutions Inc.
    //
    //	This file provides classes to reproduce most of the My.Computer and My.User
    //	functionality in VB. Calls to My.Computer.Clipboard, My.Computer.FileSystem,
    //	and My.Computer.Registry have been converted where they were referenced.
    //
    //	Note: My.Settings is converted elsewhere to the standard C# Properties.Settings.
    //	Note: My.Resources is converted elsewhere to the standard C# Properties.Resources.
    //	Note: My.Application calls are redirected to the converted My.MyApplication.
    //----------------------------------------------------------------------------------------
    
    using Microsoft.VisualBasic.ApplicationServices;
    using Microsoft.VisualBasic.Devices;
    using System.Security.Principal;
    using System.Windows.Forms;
    
    namespace My
    {
    	internal static class Computer
    	{
    		//Instant C# Notes:
    		//Calls to My.Computer.Clipboard have been redirected to System.Windows.Forms.Clipboard
    		//Calls to My.Computer.FileSystem have been redirected to Microsoft.VisualBasic.FileIO.FileSystem
    		//Calls to My.Computer.Registry have been redirected to Microsoft.Win32.Registry
    
    		internal readonly static Audio Audio;
    		internal readonly static Clock Clock;
    		internal readonly static ComputerInfo Info;
    		internal readonly static Keyboard Keyboard;
    		internal readonly static Mouse Mouse;
    		internal readonly static string Name;
    		internal readonly static Network Network;
    		internal readonly static Ports Ports;
    		internal readonly static Screen Screen;
    
    		static Computer()
    		{
    			Audio = new Audio();
    			Clock = new Clock();
    			Info = new ComputerInfo();
    			Keyboard = new Keyboard();
    			Mouse = new Mouse();
    			Network = new Network();
    			Ports = new Ports();
    			Screen = Screen.PrimaryScreen;
    
    			ServerComputer ThisServerComputer = new ServerComputer();
    			Name = ThisServerComputer.Name;
    		}
    	}
    
    	internal static class User
    	{
    		private static Microsoft.VisualBasic.ApplicationServices.User ThisUser = new Microsoft.VisualBasic.ApplicationServices.User();
    
    		internal static IPrincipal CurrentPrincipal
    		{
    			get
    			{
    				return ThisUser.CurrentPrincipal;
    			}
    		}
    		internal static bool IsAuthenticated
    		{
    			get
    			{
    				return ThisUser.IsAuthenticated;
    			}
    		}
    		internal static string Name
    		{
    			get
    			{
    				return ThisUser.Name;
    			}
    		}
    		internal static void InitializeWithWindowsUser()
    		{
    			ThisUser.InitializeWithWindowsUser();
    		}
    		internal static bool IsInRole(BuiltInRole ThisRole)
    		{
    			return ThisUser.IsInRole(ThisRole);
    		}
    		internal static bool IsInRole(string ThisRole)
    		{
    			return ThisUser.IsInRole(ThisRole);
    		}
    	}
    }
    David Anton
    Convert between VB, C#, C++, & Java
    www.tangiblesoftwaresolutions.com

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width