Visual Studio Command Window - Attach To Remote Process? - visual-studio

I was wondering if it is possible to use the command window commands to attach to a remote process? (It gets very annoying for remote debugging to roll through the dialog steps every time.)

I don't think there's any way to do what you want from the command line. But you should be able to eliminate at least some of the dialog steps.
For example, for C++, in the Project Properties find the Debugging Tab and change "Debugger to launch" to "Remote Windows Debugger". Now change Remote Command to the name of the process you want to attach to, change Remote Server Name to the relevant host name and change Attach to 'yes'. You can also set other properties as desired.
Press F5 (or Debug | Start) and you should end up attached to the process you identified on the remote server you identified.

Related

Automating user interaction from within Session 0

I am running on Windows Server 2012. I have a service that creates several processes, one of them is a GUI client. The process in high level is as follows:
Service runs a launcher exe
The launcher exe launches an AutoIT compiled exe
The AutoIT compiled exe launches a winform exe
The winform exe does two things:
a. It write a file to the disk on program startup (test.log)
b. It waits for a keyboard press "c" to write a second file to the disk (test2.log)
The AutoIT script does two things:
a. It launches the said winform exe
b. It sleeps for 5 seconds and then send "c" (Send command)
If I start running this chain manually (from step 2) - everything works fine and 2 files are being created. I guess this happens because I have an interactive session (specifically 2) so it's a no brainer here. However, if I run it from the service, everything runs in session 0 (I verified this with ProcessExplorer) but only the first file is being written. Meaning, the keystroke message was not read by the winform exe.
I read about Session 0 isolation which means that user input from other sessions can't interact with programs (services) running in session 0. However, all of the processes mentioned now run in the same session 0. So I'm not sure why my application doesn't get the keyboard strokes? Any workaround for this? Please note that running under a different session is probably not possible, as the server must run without user logged on and as far as I know, you can't launch a session yourself without logging into the system.
Any help is appreciated.
Thanks!
Your service probably runs under Local System or Local Service account (it's always "logged in" in some sense). But you can change this behavior to allow the service running under any specified account with access to the desktop.
Go to menu "Start->Computer->Manage".
In the "Computer Management" window select "Services and Applications->Services".
Find your service and call "Properties" by popup menu.
Open "Log on" tab.
You have 2 options here:
a. Choose "Local System account" radio button and check "Allo&w service to interact with desktop".
b. Choose "This account" and type or "Browse..." the account you need.
Option (b) could make sense if you set up an auto logon on the machine (in this case you may run as Administrator and have an access to the desktop simultaneously).
Option (a) is applicable only if you don't need running as Administrator. Hope it helps.

Kill a Process Started via a the Eclipse Remote Systems Feature

I'm trying to make some use of Remote Systems in Eclipse. This is what I did:
Click to Window > Show View > Other... from the Eclipse menu bar.
The Show View dialog appears.
Select Remote Systems and press OK
The system opens the Remote Shell tab in your workspace.
Rich click on Local Shells and select Launch Shell.
Started a process in the shell --- normally I can terminate this with CTRL-C at the DOS prompt.
There is no way to kill this process int he Local Shell. If I terminate the shell the process keeps running. I can kill the process by restarting Eclipse but that defeats the purpose.
I can run a shell by configuring an external tool, but I was hoping to use this nifty Remote Systems feature if I could.
Anyone got a work around?
Here's a solution when working with a particular process type (like NodeJS or Mongo) on Windows (could be adapted to other OS).
You can kill the process with the command line:
taskkill /im node.exe /f
So, set this up as a Remote Systems User Action (both Folder and File) by right-clicking in Remote Systems view and selecting User Action > Work with User Actions. Then any time you need you can right-click in the Remote Systems view and select your User Action to kill the process. I found an Eclipse restart was necessary after setting it up.

Windows 2008 Remote Desktop will not copy+paste

I have just set up a Guest Windows 2008 R2 Standard Edition 64bit (VirtualBox on Windows 7 64 bit host) for some testing.
I have found that while "inside" the remote desktop environment (i.e. I remote onto the guest ip from the host) that copy and paste does not work. When I say "does not work" let me be explicit.
Assume I am logged onto the Win2008 machine via RDC
Nothing is in the copy/paste buffer. I can mouse click some text and then rclick copy. I can then right click and click "paste" but nothing happens. I can see the "choice" is enabled to paste bu nothing happens. The caret stays put.
CTRL+C / CTRL-V / CTRL-X does not work in RDC land
I am not talking about going in-between copy/paste RDC land/host land.
HERE is the double whammy: when I do the above it then "infects" my host pc so that copy paste is unavailable there too. if PRT SCR doesn't work any more.
I have tried:
restarting the guest os and host os
in group policy editor I have disabled "do not allow clip board redirection" ( I can't give you the full path to this copy/paste just broke again)
I have made sure that in RDC "options" for local resources include clipboard.
NB: if I don't touch RDC at all and log into the guest OS via the console copy paste works perfectly
Kill the rdpclip.exe process using the Task Manager. Then, create a new process named rdpclip.exe. This will solve your problem.
Follow these steps in Remote Machine.
Stop the rdpclip process
Open Task Manager.
Go to process tab and find rdpclip
Choose rdpclip and End that task.
Start rdpclip.exe
Go to start menu and open Run command
Open rdpclip.exe and click Ok button.
Copy paste should work now.
it appears this is a flaw with VirtualBox
these posts covers it
https://forums.virtualbox.org/viewtopic.php?f=6&t=44498 (read the last post)
https://github.com/FreeRDP/FreeRDP/issues/230
(In VirtualBox) SETTINGS->GENERAL->[Advanced]->Shared Clipboard {disabled}
There are multiple things to check.
Restarting rdpclip.exe is a worthy try if the copy/paste fails sporadically, meaning we might on a process in a previous session.
On the client side, we check the RDP Options. Click on the Show Options button in the bottom, pick the third tab Local Resources. Make sure Clipboard is checked.
On the remote server side, we want to check Remote Desktop Session Host Configuration (Win Server 2008+).
Double click the connection to open its Properties window.
In the tab named Client Settings, Make sure Clipboard is not disabled.
We need to log off from the remote desktop.
Workaround
Use an online shared text box like this one:
https://pastebin.com/

VS2008 debugging with firefox as default browser - how to make the debugger stop/close on exit?

I have Firefox as my default browser on my dev machine and when I start debugging from visual studio Firefox launches as I would expect and all the attributes of the experience are the same as IE except for one thing - when I close the browser. When using IE, when I close the browser visual studio will automatically shut down the debugger. When I close FF I do not get this behavior - does anyone know how to make this happen?
The reason for this behavior is very simple: Visual Studio attaches itself to the process to be debugged, and will drop out of run mode if it sees that process terminate. FireFox does not create a new process every time a window is launched: it reuses the existing process. IE is able to create a new one for each window (depends on option settings). If you already have FF running and you launch an app to be debugged, the app window is created in the existing process and VS attaches to that process. When you close the app window the process doesn't terminate because it is still active for the pre-existing windows. Next time it happens close all the other FF windows and you will see Visual Studio drop out of debug run mode. If there was a way to tell FireFox to create a new process for a new window then this problem would go away. I haven't found any reasonably reliable way to do that.
To add to Mark's answer, you can setup a specific "debug" profile for firefox, and then change the project's properties/Web, select there "start external program" and browse to firefox.exe, and set commandline arguments to '-no-remote -P "MyDebugProfile" '.
To manage your profiles, start (from command-line) firefox like this:
c:\> <installation path of ff>\firefox.exe -profilemanager
There, you create a new profile (lets say "debug")
To start a new process of FF with this profile (i.e. what you set for VS):
c:\> <install path to ff>\firefox.exe -no-remote -P "debug" "http://mysite"
Note, that the "-P" parameter is case sensitive.
Right click on any .aspx page and choose the option "Browse With..." there you can setup the default browser
Try attaching the debugger to the FireFox process instead!
In VS (2008) select the Menu option Debug -> Attach to Process and then select firefox.exe - if you don't see this process you may have to ensure 'Show processes in all sessions' is checked.
I ran this and verified that it does work. I also verified that closing FireFox via app debug does not work, if you Firefox is set as the default browser in VS 2008.

Releasing Windows file share locks

This problem crops up every now and then at work. Our build machine can have it's files accessed via a normal windows file share. If someone browses a folder remotely on the machine, and leaves the window open overnight, then the build fails (as it has done now). The explorer window left opened points at one of the sub folders in the source tree. The build deletes the source, and does a clean checkout before building. The delete is failing.
Right now, I'd like to get the build to work. I'm logged in from home, and I'd rather not reboot the build machine. I'm unable to get hold of the person whose machine is looking and the files, and I can't remotely reboot their machine.
When a windows share has a lock, the locking process is System, so I don't think I can kill it, as with normal locks.
Does anyone know a way to release the lock on a shared folder without having to reboot the machine?
If you are admin on the server sharing the file over the network, you can use the Windows in-built feature:
Start → My Computer → Right-click → Manage gets you to the Computer
Management console
In the left nav, navigate to Systems Tools → Shared Folders
You can view Shares, Sessions & Open Files here. This allows you to find out who has opened which files from which workstations.
Right-click on an item in the list to be able to remove the file lock.
Hope this helps.
Found a solution.
Find the process using Process Explorer:
Download and extract procexp.exe
In Process Explorer use the "Find Handle or DLL..." command from the "Find" menu
Enter in the name of the directory which is having trouble deleting
A list of open files which match that name should be shown. Take some guesses and find which one is failing to be deleted. If the file is locked by a windows share, the process holding the file will be System
Note down the directory which was left open
Download and install the Unlocker (Warning: Link removed, as it contains malware)
Install Unlocker, disabling the option for Explorer extensions and other junk
Unlock the directory
Open up a cmd window, and navigate to C:\Program Files\Unlocker
From the cmd window, run Unlocker.exe "the-path-to-the-locked-folder"
A dialog will pop up confirming the lock release. Use the unlock button to unlock the file
Now the directory should be unlocked, and can now be deleted.
Try Process Hacker:
https://wj32.org/processhacker/
Process hacker is like Process Explorer on steroids.
To find the offending process, press CTRL+F or click the "Find Handles of DLLs" button and search for the file name.
Once you find the file in the find handles dialog, you can simply right click the file there and choose "close". (at least for v2.39.124)
Older versions had a "terminator" option in the context menu of the process.
Right click on the offending process --> Miscellaneous --> Terminator --> Select termination techniques. Note that some are possibly dangerous and may have unintended consequences.
I've had similar problems, and none of these suggestions I've seen above look suitable for automated overnight builds (as the original poster implied) because they all require manual effort to hunt down and kill the locks.
The only method I've tried that seems to work reliably is to remove the share itself, make the build, then add the share back. Here's one way of removing the share automatically:
D:\Projects>net share Projects /DELETE /Y
Users have open files on Projects. Continuing the operation will force the files closed.
Projects was deleted successfully.
(NOTE: Creating the share again automatically can be a pain if the privilege groups you need to give it are messy.)
The way i do it is by using both OpenFiles.exe and Handle.exe
You can run them in any order and you will have your resource fully unlocked.
OpenFiles: to disconnect File Sharing sessions
Handle.exe: to release any open handles (don't try to close handles belonging to pid4, since that's the system process)
You can automate this by using powershell, batch, or any language of your choice.
Another option is, starting from Windows Vista, to use the Windows tool built into the system:
monitor resources: perfmon.exe /res
Extracted from: Http://www.sysadmit.com/2017/06/windows-how-to-know-that-process-has-open-a-file.html

Resources