Monday, January 28, 2013

Windows remote control

I'm going to try and gather some useful commands and tools here for controlling servers. Initially this is based ona  need to control a windows server, bu tI may add unix commands too just for completness.

Start Stop services
  • sc [command]
 One issue I had was permissions. Some service (run as local system user) were unable to start/ stop services on a different server (return code 5: Access Denied was returned)

SysInternals
To counter this you can use the following PsExec - http://technet.microsoft.com/en-us/sysinternals/bb897553    (taken from  http://serverfault.com/questions/359010/execute-windows-sc-command-as-another-user)

If you want to script using the sysInteranl files then the popUp EULA can cause problems. (It pops up and you have to accept it). One way around this is to add -accepteula to your script

e.g.
pskill -accepteula


Remote Desktop controls
List existing Remote Desktop connections. (Note in the end I ran these on the remote machine in question (after using the mstsc command to login below)
  • qwinsta /SERVER:
once you have the list, you can evict some users using
  •  rwinsta /SERVER:
e.g.
dir> qwinsta
 SESSIONNAME       USERNAME                 ID  STATE   TYPE        DEVICE
>rdp-tcp#29        myUser                  0  Active  rdpwd
 rdp-tcp                                 65536  Listen  rdpwd
                   sa507823                  1  Disc    rdpwd
 console                                     4  Conn    wdcon


Here I had a disconnected instance still hanging around. This could be killed using
rwinsta 1

Also to 'force' a login you remoteDesktop command in console mode e.g.

You can run the remote desktop in consoel mode (http://h0w2.blogspot.com/2011/04/how-to-force-go-in-to-remote-desktop.html )
If you need to force, follow this trick :
- From the Start menu  click RUN Command
- type mstsc /console /v:nameserver or ip address of remote computer 
for example:   mstsc /console /v:192.168.0.10 
Or 
- type mstsc /console /v:nameserver or ip address of remote computer /admin
for example:   mstsc /console /v:192.168.0.10 /admin
- Click OK


No comments: