xp_cmdshell 将文件目录写入文本文件

发布于 2024-11-02 06:35:16 字数 280 浏览 1 评论 0原文

如何将文件目录写入文本文件?我想使用的目录是 C:\

我现在拥有的代码是

exec xp_cmdshell 'dir *.exe & echo > file_directory.txt';--

但它并没有写入文件。这还需要我说吗...

exec xp_cmdshell 'cd c: \ & dir *.exe & echo > file_directory.txt';--

how do I write my file directory to a text file? The directory I want to use is C:\

The code I have now is

exec xp_cmdshell 'dir *.exe & echo > file_directory.txt';--

It's not writing to a file though. Do I need to say this...

exec xp_cmdshell 'cd c: \ & dir *.exe & echo > file_directory.txt';--

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

居里长安 2024-11-09 06:35:16

cd (单独)仅设置工作目录,不会更改工作磁盘驱动器。如果您(可能)需要更改工作驱动器和工作目录,则需要 pushd c:\cd /dc:\

更简单的解决方案是完全限定文件名:

echo > c:\file_directory.txt

但写入 C: 的根目录通常不是一个好主意。微软试图让这一点变得更加困难,因为向系统分区的根目录开放写入权限会带来各种安全风险。

(更新:)
我想你想要的是

exec xp_cmdshell 'dir *.exe > c:\file_directory.txt';

cd (by itself) only sets the working directory, it won't change the working disk drive. If you (may) need to change the working drive and working directory you need pushd c:\ or cd /d c:\.

The easier solution is to fully-qualify the file name instead:

echo > c:\file_directory.txt

But it's generally not a good idea to write to the root of C:. Microsoft has tried to make this harder, for the very good reason that opening up write privilege to the root of your system partition opens up all sorts of security risks.

(Update:)
I think what you want is

exec xp_cmdshell 'dir *.exe > c:\file_directory.txt';
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文