c# - 脚本手动运行,但不通过 c#
问题描述
我写了一个简单的控制台应用程序,应用程序以管理员权限运行,代码基于此链接,用户输入.ps1
(powershell)脚本路径,应用程序执行此路径中的脚本。
首先,我在“Hello World”脚本上尝试了该应用程序,它运行良好,但是当我尝试其他脚本时,powershell 给出了错误。
我在.ps1
scipt 中有这个:
install-WindowsFeature smtp-server
Read-Host -Prompt “Press Enter to exit”
令人惊讶的是,如果我install-WindowsFeature smtp-server
手动运行此命令,它可以正常工作。
但我需要应用程序来完成,而不是手动完成。
这是powershell错误:
install-WindowsFeature : The term 'install-WindowsFeature' is not recognized as the name of a cmdlet, function, script
file, or operable program. Check the spelling of the name, or if a path was included, verify that the path is correct
and try again.
At c:\users\administrator\desktop\EnableSMTP.ps1:1 char:1
+ install-WindowsFeature smtp-server
+ ~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : ObjectNotFound: (install-WindowsFeature:String) [], CommandNotFoundException
+ FullyQualifiedErrorId : CommandNotFoundException
Press Enter to exit:
解决方案
推荐阅读
- c# - 如何做出正确的“if”陈述?
- mysql - 使用 django 动态添加的数据不保存到数据库中
- python - 一次从多个子目录命名导入
- xml - 避免为 DITA 文件中的空标题元素应用样式
- bazel - bazel 不会复制二进制文件来构建输出文件夹
- scala - 将 varargs 参数限制为某些分离类型
- c# - IIS 中的 PuppeteerSharp - ASP.NET Web 窗体
- php - 当我将字符编码为 base64 时的不同结果
- python - 如何在 Python 中从 XML 中的列表中提取子元素
- android - 当我尝试从链接中获取 JSON 时出现致命异常