How do I remotely obtain a system's network shares and connections? - windows

I'm looking for a way to obtain information similar to the following console applications, remotely:
net use
net share
netstat -ano
However, I need to be able to do this without running a 3rd party application on the system. This effectively rules out using psexec to execute the command remotely, because psexec would then be installed as a service.
I should add that I have administrative credentials on the remote system. I've considered using WMI's remote execution ability, but that requires me to write output to a file and then retrieve it. It's possible, but I'd like to know if anyone has a better way.
I am using Delphi 2010.

there are a couple Delphi WMI components that allow remote access. I have not used the remote options personally though.
MagWmi - http://www.magsys.co.uk/delphi/magwmi.asp (Delphi 2010 support, and free with source)
WMISet/NTSet - http://www.online-admin.com/ntset.html (TNTShare
Manages shared resources on a local computer and remote hosts. Using this component you can change list of shared devices, see files that have been opened by remote users, watch and terminate remote sessions opened to the destination computer, change list of mapped network drives. It is not free.)
GLibWMI - Found at Torry.net, home page not available. (Delphi 2010 support and Freeware with source). Not sure if its capable of remote access. I have not used it.
Hope this helps

I think the same as Logman.
You can access this information using WMI.
GLibWMI components can be found on this website (http://neftali.clubdelphi.com) or sourceforge (http://sourceforge.net/projects/glibwmi/).
The current version is 1.8b and has a component called SharedInfo with which you can get that information.
The source code is available so you can expand it to access other WMI classes if necessary.
Regards.
P.D: Sorry for my mistakes with english.

You can enumerate shares using the NetShareEnum function (headers are in the Jedi Apilib).
I assume there must be an api for the "net use" but I have never used it (check the WNet functions). Alternative is to use the EnumNetworkDrives method of the WshNetwork com object.
As for netstat I don't think it's possible to do that remotely (other than using some kind of method to spawn a process remotely).

Related

Automating remote desktop connection

We use many remote desktops in our development environment and there are many servers deployed in multiple environments. It is tedious to remember their IP addresses, usernames, and passwords. I want to write a small utility with buttons on it. When clicked, I want to start those remote desktops, automatically fetching usernames and passwords from some list.
I know there is a command line equivalent for MS Remote Desktop: mstsc.
This question suggests to do this as follows:
cmdkey /generic:TERMSRV/"computername or IP address" /user:"username" /pass:"password"
mstsc /v:"computer name or IP"
I run the first line, and it says credential successfully added. Then when I run the second line it simply runs Remote Desktop Connection for the specified IP address and asks for username and password. I would like it to simply open the remotely connected desktop at specified IP address by automatically applying the credential specified in cmdkey.
What's wrong here? Is it possible using such PowerShell script?
Can I invoke this script through an HTML page (since there are many other resources that I will be laying onto the webpage which will serve as one spot links for we developers, so that we will not be wasting time and effort finding them each time we want them)? Is it possible by registering the application to a URI scheme?
Is there another (standard) way?
The problem in your attempt is the parameter /generic.
According to the official website for cmdkey, /generic
identifies the computer or domain name that this entry will be associated with.
In my example, I will call the computer Computer01.
Do you want the credentials associated with TERMSRV/Computer01 ? (Like your example /generic:TERMSRV/"computername or IP address " said)
No, you want it associated to the normal computername Computer01.
Then you have to remove TERMSRV/.
The working result is:
cmdkey /generic:"computername or IP" /user:"username" /pass:"password"
To your other questions:
See the answer above
I don't know if it's possible with HTML only. I don't think so. But I also implement some PowerShell scripts into ASP.NET. This works.
See answer above.
A lot has changed since 2013. Many system operators already suggested to use ready-made tools which does this. Back in year 2013, Windows store wasn't that great a place (*my opinion). But now it's OK.
There is Microsoft's own Remote Desktop application in the store. The application is universal, that is, it runs on PCs, mobile phones, and holographic devices.
What's good? Microsoft has made the same app available on Android. I have tried for PC and Android. Both work great.
So have a try. I am regular user of these applications now.

Copy Files from Remote RDP to Local Machine [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
This question does not appear to be about a specific programming problem, a software algorithm, or software tools primarily used by programmers. If you believe the question would be on-topic on another Stack Exchange site, you can leave a comment to explain where the question may be able to be answered.
Closed 3 years ago.
Improve this question
Is there a way I can launch a RDP session to a remote Windows server, and perform a file transfer to the local computer? Versions of the remote Windows Server varies. Ranges anywhere from 2000 to 2008.
I've tried to look up solutions and it seems scattered everywhere. Some suggest using mstsc.exe, others suggest PowerShell / Java / ASP Net. I'm confused. Appreciate some guidance here.
Thanks!
Update Below: 17 Feb 2012
Thanks for all suggestions. Would like to add that the remote servers are securely locked down and I'm not allowed to install SSH servers, FTP servers, or shared drives. The only way for accessing the remote machine is through RDP, and these machines are also on separate VLANs to which only authorised users can use RDP to access these machines. I'm trying to create a script that can help authorised users to download the required files.
You can map a drive using remote desktop.
Options > Local Resources > More
Ctrl + C at the Remote Desktop, and Ctrl + V at local, if you not looking for any automated solution. (Please check RD Config to enable copy and paste)
Once you have mapped the drives you want using mstsc, you can use \\tsclient to access the file system of the local machine i.e the Terminal services client from which you have RDP'ed on to the remote box.
If all you are trying to do is copy file from a remote box, just do \\machine\c$\path etc or share the folder and do \\machine\share to get them. RDP is not necessary in this case.
Once you have mapped the needed drives as Andy says, you can execute remotely a LOCAL batch file every time you connect specifying it's local path (using \\tsclient\c to refer your local drive) in the Programs tab at RDP properties.
Remember to write cmd /c before that path.
The rdp connection will automatically close once the batch file ends, but you can add the pause command to the end to see what happened during execution.
Connecting this way, you can edit the batch file before connecting.
Make sure your remote Machine enabled PSRemoting by running the following command in PowerShell
Enable-PSRemoting –Force
From the client computer, run the following command to establish the connection.
net use "\\{RemoteIP}\c$" "{Password}" /USER:"{Username}" /persistent:no
Here after you can use Copy-Item, Delete-Item over the network.
Copy-Item [PACKAGEPATH]\* \\[COMPUTER]\c$\installers -recurse
In Client machine, Run->mstsc.exe-> Local Resources-> enable clipboard.
In remote machine-> windows run command (Windows Key + R).
Open cmd->(Taskkill.exe /im rdpclip.exe) type brackets command
You got "Success", then
Type same command prompt "rdpclip.exe"
Now copy and paste both, its working fine
You can copy and paste files over RDP, it works perfectly. See http://www.reddit.com/r/sysadmin/comments/1d6a1o/til_you_can_copy_and_paste_files_over_rdp/ for more info.
eug wrote what I thing is an extremely useful comment that seems to have overlooked by everyone:
You can very easily share a single folder by using subst to map it to a drive letter, and then selecting that drive in remote desktop.
Note that it's fairly easily to have problems with this method due to subst performing the mapping only for the user under which it is run.
So I recommend to run everything from a single command prompt:
Open a command prompt (Win+R -> cmd)
Type subst <lettertomap>: <pathtofolder>
Type mstsc (which launches Remote Desktop)
Keep in mind that the subst mappings are not persistent across reboots, of course, so this is mostly convenient for a one-time session of file transfer.
There are actually also other ways to do the mapping, see raymond.cc .
And yes, the mapping does seem to disallow access to the rest of the drive, although I wouldn't bet my life that it doesn't have chroot-like "vulnerabilities" (assuming it is supposed to be secure in the first place).
1) Install dropbox or equivalent cloud storage product and sync needed files that way between computers. Remember, you can allow only certain folders to be synced on specific devices (you don't have to sync the entire dropbox, just the folders you need)
2) If you are allowed to setup more than one user on the remote server, have a 2nd user and then have user2 session connect rdp session to user1. This will keep the user1's gui alive in the cloud without having to remain logged in to rdp locally.
This video should show you how to implement this 2 user setup on your server to hold an rdp session open. Note that this does 'permanently' use 1 rdp session until you decide to close it.
[markdown cannot embed video :( ]
Then use AmmyyAdmin AnyDesk on user1's desktop to connect and manipulate the desktop. This includes using AnyDesk's file manager's ability to browse any folder you need and copy. AnyDesk can be free if you connect via direct IP connection. Most vps servers have dedicated IP addresss or subdomain address so this should not be a problem. Good idea to password protect your AnyDesk login and which IDs have access to unattended remote connections. The AnyDesk file manager is a bit crude, but it works. Their big thing is simplicity and speed.
Note: Use portable mode only on the remote user's desktop; Do NOT fully install AnyDesk. Also, the CPU usage might increase to stream the desktop screen, somewhat related to the size of the RDP window. I am using 1280 x 2048 window with 4 cores and the CPU usage is 22-25% idle or moving things around. This might decrease if there is more video ram or graphics processor on the target server. But, if you only "browse files" (use only the file manager without streaming the desktop), CPU usage >0.3% idle and >1 avg% when transferring files (burst up to 5-6% when the file is finished uploading and the pieces are being finalized).
You'd have to write your own scripts (java, .net, c#/c++, AutoIT, etc) to launch AnyDesk locally and automate the connecting and downloading specific files.
This strategy is a bit more complex, but it should do the job. Not sure why microsoft rdp cannot have some simple, quick file manager like what ammyy admin AnyDesk has; oh well.
Add: Can also use AnyDesk or Teamviewer. Teamviewer became a lot more restrictive on what is considered to be "non commercial use", but Anydesk is secure, much smaller footprint, and if you can have a direct connection doesn't seem to care too much about usage. If you do need a license, it will be much lighter on the wallet.
AnyDesk works flawlessly without any installation required. In fact, if using in a server environment as I described above, no installation is recommended.
Edit: AmmyyAdmin is no longer recommended for several months now due to some security and technical concerns. Added AutoIT as a scripting capability to automate interaction with GUI/nearly any windows function.

Is it possible to run programs locally from a terminal services remote app?

First, I guess I'd have to figure out if I'm running remotely and second I'd have to figure out whether my remote connection is a standalone remote app or an app running on a terminal server (that may be tricky).
But, once I've figured out all those awful things, is there a way to run a windows function like ShellExecute locally instead of remotely?
The reason I'd want to do this is because I launch a web browser to view rather high bandwidth things that require javascript and flash and certain sysadmins who administer our product aren't too keen on having to make unnecessary and insecure modifications to their terminal server farm.
Yes, if the clients are running Windows and you can install software on them.
See Remote Desktop Services Virtual Channels in MSDN.
There is a free tool that does exactly what you want. I got reference from TechNet forums, it's named Remote Executer from http://www.mqtechnologies.com
Good luck

Detecting a Citrix XenDesktop Session

I'm looking to determine if our application is running on a XenDesktop session rather than locally. Here is what I have found so far:
We currently have code to detect a Citrix XenApp session similar to the solution mentioned by Helge Klein in "API for Determining if App is Running on Citrix or Terminal Services".
Sadly that solution in a XenDesktop environment is returning back a WTSClientProtocolType of 0 which signifies a local console session.
In response to the same question Josh Weatherly mentioned checking the sessionname environment variable.
However a quick console check with echo %sessionname% on the XenDesktop environment returns back 'Console'.
From "Detect citrix “application mode”?" John Sibly suggested a solution for detecting a remote session (not Citrix in particular):
GetSystemMetrics(SM_REMOTESESSION) however returns 0 which also means that it is a local session.
Does anyone know of a way to detect that it is a XenDesktop session? So far as you can see all my attempts are returning that the session is a local console session.
I'm using XenDesktop Express 5.5, accessing the desktop using the Citrix Receiver Web Plug-In.
If you are using XenDesktop for VDI, then as far as the application is concerned, the application is executing locally. VDI, or virtual desktop infrastructure, consists of delivering the GUI from a full featured desktop operating system to a remote device. Typically, the desktop O/S executes in a virtual machine on a hypervisor in a data center, and the GUI is transmitted to the remote device using Citrix' ICA stack. For example, this happens in the pooled desktops scenario.
XenApp offers virtual desktops, which is a slightly different concept. Again, the desktop is delivered to a remote device using the ICA stack. However, the desktop is no longer running on a dedicated O/S. Rather, it is one of a number of user sessions on a single Windows Server. There may be any number of users logged on to that server. This places limits on the applications that can be run, which is why applications might want to know that they are on a multi-user O/S.
What you might try to do is determine whether the GUI is being delivered remotely using the ICA stack. A simple check would involve looking for the "ProticaService", which is responsible for implementing the ICA stack.
Alternatively, you may be trying to determine if your machine is running in a VM or native to a machine. Besides the pooled scenario described in the first paragraph, XenDesktop can deliver desktop running native. This overcomes limits on virtualision I/O devices such as graphics cards used by CAD applications. In this case, you need to rule out the presence of a VMM, or hypervisor.
I have updated my answer linked to in the question with a description of how to determine the remoting protocol type in XenDesktop sessions.
You need the (not really well documented) function WFGetActiveProtocol from Citrix' WFAPI SDK. Proceed as follows:
Download the SDK (link)
Install WFApiSDK64-65.msi
In your C++ project include wfapi.h and link to wfapi[64].lib
Use the undocumented function WFGetActiveProtocol
More detail and sample code here.

Prefered method to map a remote filesystem in windows?

For a current project, I need to allow users to access their files remotely from Windows. I'm looking for a solution with an explorer integration (using Shell Namespace Extensions).
I first try using WebDAV and the built-in client in Windows but the client is not of equal quality in all Windows version and adding SSL and/or authentication is not working as espected.
I am not attached to WebDAV, it can be any protocol. I prefer open-source project or a commercial one with a SDK license (must be integrated in a product).
Have you tried "sharing" the filesystem? If your server runs Linux, you could try samba. I haven't tried Windows in a while, but I seem to remember that the Explorer did ftp as well.
I'm assuming plain HTTP is a no go here.

Resources