当前位置: 动力学知识库 > 问答 > 编程问答 >

c++ - Windows Command Line History

问题描述:

I need to programmatically mount a WebDAV volume in Windows using C, and I think I'm going to use system() to achieve this (via the 'net use' command)... However, since net use requires that the password be written in plain text, I just wanted to make sure there's no logging of commands run in the Windows command line shell... I know in Mac OS X and Linux in some circumstances commands can be logged in the file .bash_history, so I thought maybe something similar was going on in Windows. I don't think so though, since nothing showed up on Google.

网友答案:

The shell has a history, but it's only stored in memory not a log on disk. That said, it could end up in the swap file and open to (slightly non-trivial) discovery. Then again, if you did the connection directly in your own program using something like WNetAddConnection2, it could end up in the swap file anyway.

网友答案:

It might be better to use the 'CreateProcess' and redirect the input and output to your code, and feed it into it by writing to stdin (which would be redirected to the 'Net use' command), and read the output, in that way, the password input would not be logged... this is in theory....I am not 100% confident if the popen implementation exists....as it's POSIX compliant and not found in standard C...it exists in the *nix world...

Edit: Good news, I found some code that emulates a popen using a wrapper around CreateProcess, just thought it might help. The code would need to be tweaked a bit...It's GPL v2 licence..so..something to bear in mind...

Hope this helps, Best regards, Tom.

网友答案:

Not an answer to your question, but instead of net use check WNetAddConnection2 win32 function

网友答案:

The windows command shell doesn't have any built in command logging, it uses an external command for that (doskey), I don't think that a command prompt from a system() command has doskey installed, but if you want to be certain, use system() to execute

doskey /history

and it will output the command line history for that instance of the command prompt.

网友答案:

A normal command interface doesn't have a history unless you explicitly active it (but I can't remember this command being available , last I checked was in the DOS/windows 95 days). Visual studio command prompt does have a history though -- but I doubt its retained when you close the prompt.

分享给朋友:
您可能感兴趣的文章:
随机阅读: