WinRb / winrm-elevated

Runs PowerShell commands as elevated over Windows Remote Management (WinRM) via a scheduled task
Apache License 2.0
27 stars 17 forks source link

Two concurrent processes using winrm-elevated against the same Windows Host may run into conflict in log filenames. #5

Closed jerryk55 closed 8 years ago

jerryk55 commented 8 years ago

Attempting to run two different requests via winrm-elevated against the same Windows server resulted in the following error:

Error running PowerShell command. del : Cannot remove item C:\Users\usernameAppData\Local\Te mp\winrm_elevated_out.log: The process cannot access the file 'C:\Users\username\AppData\Local\Temp\winrm_elevated_out.log' because it is being used by another process. At C:\windows\temp\winrm-elevated-shell.ps1:8 char:3 + del $out_file + ~~~~~ + etc. etc. etc.

The log files in the elevated_shell.ps1 should named more uniquely - perhaps using the process id or a timestamp.

mwrock commented 8 years ago

Currently this gem does not "play nice" with concurrent elevated calls. It stores the elevated command in a hard coded static file name c:/windows/temp/winrm-elevated-shell.ps1. So if two or more elevated calls are made the first will "win" and subsequent calls will fail until the first call completes.

We could uniquely name this file per instance to protect against this.

jerryk55 commented 8 years ago

Agreed both the ps1 file and the log files are non-unique - however two separate processes running a common powershell script isn't really an issue, is it ?(assuming the act of uploading the script when it already exists doesn't clobber an existing process running it).

The act of attempting to delete a log file to which another process is writing is always problematic.

Regardless as you've stated, the powershell script should be modified to make the log names unique, as well as changing runner.rb to make the uploaded powershell script unique.

sneal commented 8 years ago

Fixed by #6