简体   繁体   English

如何在 Windows 中远程编辑文本

[英]How do I edit text remotely in Windows

(Note, this question is also posted on technet ) (注意,这个问题也发布在technet 上

How can I remotely edit a text file in Windows?如何在 Windows 中远程编辑文本文件?

I am running and administering a number of Windows 7 workstations and Windows Server 2012 machines.我正在运行和管理许多 Windows 7 工作站和 Windows Server 2012 机器。 I would like to be able to remotely edit text files on any of these machines.我希望能够在任何这些机器上远程编辑文本文件。 I can connect to any of these machines via psexec or powershell remoting.我可以通过 psexec 或 powershell 远程处理连接到这些机器中的任何一台。 I can also connect via rdp, but for the workstations I would rather not kick the user off unless I absolutely have to.我也可以通过 rdp 进行连接,但是对于工作站,除非万不得已,否则我宁愿不将用户关闭。

For example, we manage state configuration using Salt.例如,我们使用 Salt 管理状态配置。 Local configuration files are stored in C:\\salt\\conf .本地配置文件存储在C:\\salt\\conf I would like to be able to edit these config files on the fly.我希望能够即时编辑这些配置文件。

This question covers the same topic, but none of the answers are particularly satisfying. 这个问题涵盖了相同的主题,但没有一个答案特别令人满意。

Some of the possible solutions are:一些可能的解决方案是:

  • Remote Desktop: as I say, I would rather not have to kick a user off their workstation远程桌面:正如我所说,我宁愿不必将用户踢出他们的工作站
  • Edit a file over a UNC path: this only works for files on a share, and setting up arbitrary shares for quick edits seems like a bad idea.通过 UNC 路径编辑文件:这仅适用于共享上的文件,并且为快速编辑设置任意共享似乎是个坏主意。
  • Install some manner of ftp or ssh server on all the target computers.在所有目标计算机上安装某种方式的 ftp 或 ssh 服务器。 This would certainly work, but it is it necessary with WinRM already active?这当然可以工作,但是在 WinRM 已经激活的情况下是否有必要? I feel like installing and configuring extra software across all the machines in my organisation would be a last resort.我觉得在我的组织中的所有机器上安装和配置额外的软件将是最后的手段。
  • Edit with a command line editor (eg vim, emacs) over a remote powershell session.使用命令行编辑器(例如 vim、emacs)通过远程 powershell 会话进行编辑。 This doesn't work.这不起作用。 I don't understand the technical details, but a powershell remote session isn't interactive in the same way that ssh connections are.我不了解技术细节,但是 powershell 远程会话的交互方式与 ssh 连接的交互方式不同。
  • Edit using powershell's -replace operator, out-file and add-content cmdlets.使用 powershell 的 -replace 运算符、out-file 和 add-content cmdlet 进行编辑。 This works, but is hardly the same as a fully featured text editor.这有效,但与功能齐全的文本编辑器几乎不一样。
  • Retrieve content from the remote, edit locally, and post back to the remote.从远程检索内容,在本地编辑,然后回发到远程。 This works, and is arguably the best solution I've found.这很有效,可以说是我找到的最好的解决方案。 Code sample from the previous SO question:来自上一个 SO 问题的代码示例:
PS C:\Users\Meredith> Invoke-Command -Session $ps -ScriptBlock {get-content c:/inetpub/myapp/web.config} > web.config

Edit web config:编辑网页配置:

PS C:\Users\Meredith> get-content web.config | Invoke-Command -Session $ps -ScriptBlock {set-content c:/inetpub/myapp/web.config}

The last two options are the workflow that I've been using for now.最后两个选项是我现在一直在使用的工作流程。 Regex replacement for very simple changes, and copying to local and editing there for more complicated ones.正则表达式替换非常简单的更改,复制到本地并在那里编辑更复杂的更改。 Neither is ideal, but they work.两者都不是理想的,但它们有效。 It just feels incredibly old fashioned.它只是感觉非常老式。

I'm considering writing a plugin to my editor of choice (vim) to perform the remote fetch and save, to make my workflow a little bit smoother.我正在考虑为我选择的编辑器 (vim) 编写一个插件来执行远程获取和保存,以使我的工作流程更加顺畅。 Before I try that, I just want to know if there's anything that I've missed, or misunderstood.在我尝试之前,我只想知道是否有任何我遗漏或误解的地方。

Use administrative shares.使用管理共享。 These are created by default on Windows, and they take the form of a drive letter followed by a $ , like this: \\\\machine\\c$这些是在 Windows 上默认创建的,它们采用驱动器号后跟$ ,如下所示: \\\\machine\\c$

A $ in any share name makes it "hidden" (as in it won't show up when browsing \\\\machine\\ ).任何共享名称中的$都会使其“隐藏”(因为浏览\\\\machine\\时它不会显示)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM