将VBS代码转换为c#
本文关键字:转换 代码 VBS | 更新日期: 2023-09-27 18:08:30
我只是有下面的代码,是提供作为hMailServer的DCOM API在http://www.hmailserver.com/documentation/latest/?page=com_example_account_create下面的脚本工作良好。它没有参考,什么都没有。在安装hMailServer之后,运行下面的代码就可以创建一个帐户。现在,我需要在c#中做同样的事情。他们没有为我提供任何c#的库,我搜索了一下,但没有相关的结果,我只有下面的代码,但根据hMailServer API,他们说你可以把下面的脚本转换成任何你想要的语言。但如何?我甚至不知道如何开始写,甚至第一行。谁来帮帮我。
Dim obApp
Set obApp = CreateObject("hMailServer.Application")
' Authenticate. Without doing this, we won't have permission
' to change any server settings or add any objects to the
' installation.
Call obApp.Authenticate("Administrator", "your-main-hmailserver-password")
' Locate the domain we want to add the account to
Dim obDomain
Set obDomain = obApp.Domains.ItemByName("example.com")
Dim obAccount
Set obAccount = obDomain.Accounts.Add
' Set the account properties
obAccount.Address = "account@example.com"
obAccount.Password = "secret"
obAccount.Active = True
obAccount.MaxSize = 100 ' Allow max 100 megabytes
obAccount.Save
将COM对象(hMailServer)添加到您的c#项目中作为参考,并将其余代码转换为c#。
它看起来像这样:
var app = new hMailServer.Application();
// Authenticate. Without doing this, we won't have permission
// to change any server settings or add any objects to the
// installation.
app.Authenticate("Administrator", "your-main-hmailserver-password");
// Locate the domain we want to add the account to
var domain = app.Domains["example.com"];
var account = domain.Accounts.Add();
// Set the account properties
account.Address = "account@example.com";
account.Password = "secret";
account.Active = true;
account.MaxSize = 100; // Allow max 100 megabytes
account.Save();
我希望这仍然是相关的,可以帮助别人。在这里,我只是使用get item by name属性来提取hMailServer中配置的域名。
protected void Page_Load(object sender, EventArgs e)
{
var app = new hMailServer.Application();
// Authenticate. Without doing this, we won't have permission
// to change any server settings or add any objects to the
// installation.
app.Authenticate("Administrator", "your.admin.password.here");
// Locate the domain we want to add the account to
var domain = app.Domains.get_ItemByName("your.configured.domain.name.here");
var account = domain.Accounts.Add();
// Set the account properties
account.Address = "account.name.here";
account.Password = "pass.word.here";
account.Active = true;
account.MaxSize = 100; // Allow max 100 megabytes
account.Save();
}