Skip to content

Conversation

@DeepakRajendranMsft
Copy link
Contributor

No description provided.

@azurecla
Copy link

Hi @DeepakRajendranMsft, I'm your friendly neighborhood Azure Pull Request Bot (You can call me AZPRBOT). Thanks for your contribution!
You've already signed the contribution license agreement. Thanks!
We will now validate the agreement and then real humans will evaluate your PR.

TTYL, AZPRBOT;

@ogail
Copy link
Contributor

ogail commented Aug 27, 2015

Update release notes

@DeepakRajendranMsft
Copy link
Contributor Author

@ogail updated release notes

@pcgeek86
Copy link
Contributor

@DeepakRajendranMsft Thank you -- I checked out the PR and the parameter sets look good.

However, I'm curious about the implementation of the mstsc.exe invocation. Is there a reason that you're wrapping the invocation inside a batch file? Isn't that going to leave a bunch of .bat files on the user's filesystem?

Cheers,
Trevor Sullivan
Microsoft MVP: PowerShell

@DeepakRajendranMsft
Copy link
Contributor Author

@pcgeek86. thanks for the feedback,

TBH, I dont have a good explanation for this. this is the same implementation as in the existing non-arm cmdlet

@pcgeek86
Copy link
Contributor

@DeepakRajendranMsft Cool, thanks for validating. Seems like a good opportunity to fix it then. Right? :)

@ogail
Copy link
Contributor

ogail commented Aug 27, 2015

@DeepakRajendranMsft
Copy link
Contributor Author

The batch file takes care of deleting the rdp and the batch itself file after mstsc is invoked so we should be okay right. (?)
Here is the generated bat file:
start /wait mstsc.exe E:\temp\1\tmpF1B9.tmp
del E:\temp\1\tmpF1B9.tmp
del E:\temp\1\6717222a-df20-4910-b108-22f7353d7d27.bat

Also verified that we actually delete both the rdp and batch file

@pcgeek86
Copy link
Contributor

Gotcha, I guess I just don't see a need to create the batch file in the first place. It's adding an additional layer of overhead that isn't necessary. Just invoke mstsc.exe directly from the C# code. Does that create any challenges? I think it would be simpler.

Cheers,
Trevor Sullivan

@ogail
Copy link
Contributor

ogail commented Aug 27, 2015

@DeepakRajendranMsft
Copy link
Contributor Author

@pcgeek86 yes i agree with you, we can invoke mstsc.exe directly. but the batch file is in there to delete the temporary rdp file(after the user is done with the RDP) that will be created when the user doesnt specify the "-localpath".

If it is okay to leave the temp rdp file in the temp dir, if so we can remove the batch file (or is there a better way to deal with the temp rdp file)

@pcgeek86
Copy link
Contributor

@DeepakRajendranMsft If the user downloads the file using the -LocalPath parameter, then we don't need to worry about cleaning it up at all, agreed. I'm only talking about the Launch parameter set here. You can delete the RDP temp file using C#, right? Why do we need a batch file to delete it? Just use System.IO.File.Delete() to kill off the RDP file.

https://msdn.microsoft.com/en-us/library/system.io.file.delete(v=vs.110).aspx

Cheers,
Trevor Sullivan
Microsoft MVP: PowerShell

@pcgeek86
Copy link
Contributor

Oh wait, I think I see what you're saying. The batch file lifetime is outside the RDP process lifetime. When the mstsc.exe process exits, the batch file removes the RDP file and exits as well. Since the C# code is not running synchronously with the RDP session, it is unable to handle this. I understand now. Nevermind, leave it as-is. It was my misunderstanding.

Cheers,
Trevor Sullivan
Microsoft MVP: PowerShell

@pcgeek86
Copy link
Contributor

Actually wait, once the RDP file is invoked, does mstsc.exe still have a file lock on it? If not, I would just kick off mstsc.exe from C# directly, and then immediately delete the RDP file (also using C#). There's no need to keep the RDP file around for the whole RDP session, is there? Of course, if mstsc.exe does have a lock on the file, then your existing solution is probably the simplest.

@DeepakRajendranMsft
Copy link
Contributor Author

hmmm let me try that (i dont there is a lock), will confirm

@pcgeek86
Copy link
Contributor

@DeepakRajendranMsft Thank you -- appreciate your discussion around this topic.

@DeepakRajendranMsft
Copy link
Contributor Author

@pcgeek86 mstsc doesnt seem to take a lock. but it looks like i need to put a sleep after the process has started and before i delete the file. (since the file sometimes gets deleted before we delete the process. I didnt find any api on process to wait on start). So i think the current implementation is probably the best and simple.

example of waiting:
bool found = 0;
while (!found)
{
foreach (Process clsProcess in Process.GetProcesses())
if (clsProcess.Name == Name)
found = true;

Thread.CurrentThread.Sleep(1000);

}

or use Process.waitForIdleTimeout()

ogail added a commit that referenced this pull request Aug 27, 2015
@ogail ogail merged commit 7da0852 into Azure:dev Aug 27, 2015
@DeepakRajendranMsft DeepakRajendranMsft deleted the AddLaunchOptionOnRDP branch December 14, 2015 21:46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants