C# 相当于 VB6 的 GetObject
以下 VB6 代码连接到一些第三方软件并强制使用管理员用户名和密码登录:
Set obj = GetObject(, "workspace.application")
obj.System.FixLogin strAdminUsername, strAdminPassword
我想在 C# 中执行相同的任务,但作为一个非常新手的 C# 开发人员(大约 3 个月的经验),我不知道如何做这个。我在 Google 上度过了非常沮丧的一天,但没有找到任何符合要求的内容(其中大部分我什至无法理解)。我对 VB6 的了解甚至比对 C# 的了解还少,但 VB6 让它看起来如此简单。
此外,在我实施到我们的 QA 环境之前,我无法测试与此第三方软件的连接。所以我想用一个简单的应用程序(例如记事本)来测试功能。我可以在记事本上调用什么函数/方法来代替“FixLogin”?
如果有人能帮助我解决这个问题,我将不胜感激。
亲切的问候, 史蒂夫.
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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
即使您使用 C#,也可以使用 Vb.Net 提供的所有类和方法,包括 GetObject。
只需添加对 .NET 组件“Microsoft.VisualBasic”的引用即可。
添加引用后,您可以调用
Microsoft.VisualBasic.Interaction.CreateObject() 或 Microsoft.VisualBasic.Interaction.GetObject()
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()
Marshal.GetActiveObject方法
Marshal.GetActiveObject Method