Search code examples
windowsbatch-filecmdrunas

Get output of the command line opened by runas command


I have been trying to get the output of the RUNAS command, but I have so far been unsuccessful.

I need to get the time of another user, and save it to the a file so another process can read it later.

I have tried many things, but here is an example: runas /noprofile /savecred /user:username "cmd /c time > output.txt"

This does not save the command line output to the file. I was wondering if someone could please help me figure out what I am doing wrong!

I have also tried writing a VBScript to do what I need and I have had no luck so far


Solution

  • two Problems: the command time expects user Input and the new cmd instance opens with working Directory of c:\Windows\system32 where username probably has no write permissions.

    Use another command to get the time and give a full path to a Folder with write permissions:

    runas /noprofile /savecred /user:username "cmd /V:on /C echo !time!>c:\temp\output.txt"