Web设置项目 - 获取当前计算机名称

时间:2023-02-05 17:33:29

I've got a web setup project with a custom screen in it that asks for a machine name. Is there anyway to prepopulate this field with the current machines name?

我有一个Web设置项目,其中包含一个自定义屏幕,要求提供机器名称。无论如何使用当前的机器名称预先填充此字段?

For the case that I need it for just including "Localhost" does not meet my requirements.

对于我需要它只包括“Localhost”的情况不符合我的要求。

"Environment.MachineName" will return the machine name within a code block which would be fine if I was needing it in a custom action. But it seems custom actions don't excecute until after you go through the installation wizard... So I cant actually use it. Anyway let me know what you think.

“Environment.MachineName”将在代码块中返回机器名称,如果我在自定义操作中需要它,那将是正常的。但是,在你完成安装向导之后,似乎自定义操作不会超出...所以我实际上无法使用它。无论如何让我知道你的想法。

4 个解决方案

#1


From my limited research, it doesn't look like the simple Web Setup Project will be enough for you to do what you want. I would suggest any of the following, depending on how important this is to your project:

从我有限的研究来看,简单的Web Setup Project看起来不足以让你做你想做的事。我会建议以下任何一种,具体取决于这对您的项目有多重要:

  • Just use a default of LOCALHOST
  • 只需使用默认的LOCALHOST

  • Leave the default blank and use the dialog text to tell the user how to retrieve the machine name
  • 保留默认空白并使用对话框文本告诉用户如何检索计算机名称

  • Don't ask the user and make the settings later w/ a post-install exe/script that has access to environment variables
  • 不要询问用户并在以后使用有权访问环境变量的安装后exe /脚本进行设置

  • Use a different (read: more robust) installer
  • 使用不同的(读取:更健壮)安装程序

I would suggest the last one of course, but if you don't need really need this feature that bad, go with one of the other options that is acceptable enough in your situation.

我当然会建议最后一个,但是如果你真的不需要这个功能那么糟糕的话,请选择其中一个在你的情况下足够可接受的选项。

#2


I'm not sure if you have access to code while the web setup project is running. If so, you could try the static "Environment.MachineName" property.

在Web安装项目运行时,我不确定您是否可以访问代码。如果是这样,您可以尝试静态“Environment.MachineName”属性。

#3


System.Environment.MachineName

#4


Do you have access to environment variables? You could evaluate %COMPUTERNAME%.

你有权访问环境变量吗?您可以评估%COMPUTERNAME%。

#1


From my limited research, it doesn't look like the simple Web Setup Project will be enough for you to do what you want. I would suggest any of the following, depending on how important this is to your project:

从我有限的研究来看,简单的Web Setup Project看起来不足以让你做你想做的事。我会建议以下任何一种,具体取决于这对您的项目有多重要:

  • Just use a default of LOCALHOST
  • 只需使用默认的LOCALHOST

  • Leave the default blank and use the dialog text to tell the user how to retrieve the machine name
  • 保留默认空白并使用对话框文本告诉用户如何检索计算机名称

  • Don't ask the user and make the settings later w/ a post-install exe/script that has access to environment variables
  • 不要询问用户并在以后使用有权访问环境变量的安装后exe /脚本进行设置

  • Use a different (read: more robust) installer
  • 使用不同的(读取:更健壮)安装程序

I would suggest the last one of course, but if you don't need really need this feature that bad, go with one of the other options that is acceptable enough in your situation.

我当然会建议最后一个,但是如果你真的不需要这个功能那么糟糕的话,请选择其中一个在你的情况下足够可接受的选项。

#2


I'm not sure if you have access to code while the web setup project is running. If so, you could try the static "Environment.MachineName" property.

在Web安装项目运行时,我不确定您是否可以访问代码。如果是这样,您可以尝试静态“Environment.MachineName”属性。

#3


System.Environment.MachineName

#4


Do you have access to environment variables? You could evaluate %COMPUTERNAME%.

你有权访问环境变量吗?您可以评估%COMPUTERNAME%。