13

The following VB6 code connects to some third party software and forces a login with the admin username and password:

Set obj = GetObject(, "workspace.application")
obj.System.FixLogin strAdminUsername, strAdminPassword

I am wanting to do the same task in C# but as a very green C# developer (about 3 months experience) I have no idea how to do this. I've spent a very frustrating day on Google but have found nothing that fits the bill (most of it I couldn't even understand) I know even less about VB6 than I do about C#, but VB6 makes it look so easy.

Also I can't test connecting to this third party software until I implement to our QA environment. So I would like to test the functionality with a simple app, Notepad for example. What function / method could I call on Notepad instead of "FixLogin"?

I would be most grateful if someone could help me with this problem.

Kind Regards, Steve.

Jeff LaFay
  • 12,882
  • 13
  • 71
  • 101
user455176
  • 131
  • 1
  • 1
  • 3
  • [`Microsoft.VisualBasic.Interaction.GetObject`](https://learn.microsoft.com/en-us/dotnet/api/microsoft.visualbasic.interaction.getobject) with reference to Microsoft.VisualBasic.dll – Slai Nov 27 '19 at 20:09

2 Answers2

21

Even if you're working with c#, you can use all classes and methods provided by Vb.Net, including GetObject.

Just add a reference to the .NET Component "Microsoft.VisualBasic".

Once you have added the reference, you are able to call Microsoft.VisualBasic.Interaction.CreateObject() or Microsoft.VisualBasic.Interaction.GetObject()

Andrea Parodi
  • 5,534
  • 27
  • 46
13

Marshal.GetActiveObject Method

Viacheslav Ivanov
  • 1,535
  • 13
  • 22
  • The desire with GetObject is to get an instantiated object in memory if it exists; which this solution does. If it returns null then you can use new to instantiate. This is the best solution to the question, because it handles all the aspects of behavior. – Jay Imerman Oct 11 '12 at 17:57