I want to make a simple program to help connect to a Remote Desktop, this is what I got till now:
#echo off
echo Connect Program
echo Enter IP of computer:
set /p ip=
echo Enter Username
set /p user=
echo Enter Pass
set /p pass=
Now I just want the code where I fill the variables %ip%, %user%, %pass%.
Any easy way to do this?
Here is what I derived from this post. First, an entry for the login credentials is created. Second, the RDP connection is established. Third, the entry containing the credentials is deleted. I've been using this on Win7 and Win10 so far.
I call this script from the KeePass password manager which passes the parameters to the script.
Usage example:
rdp.bat "my.host.name.de" "port" "username" "password"
rdp.bat
:: RDP connection without password prompt ------------
:: %1 = hostname
:: %2 = port
:: %3 = username
:: %4 = password
:: ---------------------------------------------------
cmdkey /add:"%~1" /user:"%~3" /pass:"%~4"
start /wait mstsc /v:"%~1:%~2"
cmdkey /delete:"%~1"
Note:
If the script running in the background is closed before the RDP session has ended, the entry containing the login credentials will not be deleted. Only use this approach if you know what you are doing. Do not use this e.g. on a public computer, as your login information might be exposed!!
Remote Desktop Connection (mstsc.exe) doesn't allow you to provide the credentials from the command line. Running mstsc /? from a command prompt shows the available switches:
MSTSC [] [/v:] [/admin] [/f[ullscreen]] [/w: /h:] [/public] | [/span] [/multimon] [/edit "connection file"] [/restrictedAdmin] [/prompt] [/shadow: [/control] [/noConsentPrompt]]
"connection file" -- Specifies the name of an .RDP file for the connection.
/v: -- Specifies the remote computer to which you want to connect.
/admin -- Connects you to the session for administering a server.
/f -- Starts Remote Desktop in full-screen mode.
/w: -- Specifies the width of the Remote Desktop window.
/h: -- Specifies the height of the Remote Desktop window.
/public -- Runs Remote Desktop in public mode.
/span -- Matches the remote desktop width and height with the local virtual desktop, spanning across multiple monitors, if necessary. To span across monitors, the monitors must be arranged to form a rectangle.
/multimon -- Configures the Remote Desktop Services session monitor layout to be identical to the current client-side configuration.
/edit -- Opens the specified .RDP connection file for editing.
/restrictedAdmin -- Connects you to the remote PC or server in Restricted Administration mode. In this mode, credentials won’t be sent to the remote PC or server, which can protect you if you connect to a PC that has been compromised. However, connections made from the remote PC might not be authenticated by other PCs and servers, which might impact app functionality and compatibility. Implies /admin.
/prompt -- Prompts you for your credentials when you connect to the remote PC or server.
/shadow: -- Specifies the sessionID you wish to view.
/control -- Allows control of the session.
/noConsentPrompt -- Allows shadowing without user consent.
This indicates that the only way to ask for the user credentials when launching is to either have them stored in the .RDP file in advance or to prompt the user at run time using /prompt.
Related
I am running SAP GUI script automation on a Windows VM. When I am disconnecting from the remote desktop, I am running below command on a batch file, to disconnect and keep a virtual session of the current user.
for /f "skip=1 tokens=3" %%s in ('query user %USERNAME%') do (
%windir%\System32\tscon.exe %%s /dest:console
)
Earlier the resolution was not an issue for the GUI scripts I executed. But this time, when I execute the script while logged into the machine, the SAP login screen and the rest of the SAP windows launched on full-screen mode, to match the screen size of my laptop. But, when I execute the above batch file, the screen area gets small and the script is unable to find the element below the visible area, as it needs to scroll down.
This is a screenshot captured during a timeout.
If I log into this vm while, it is running (in the middle of the virtual session), I get the same window as below.
But, if I run this while logged into the machine, it just gets launched full screen. I am using SAP client 770.
I don't have permission to change to screen resolution. Is there any way I can fix this issue?
I am creating a batch file to open a RDP session.
The remote desktop uses a gateway, so there are 2 credentials to be entered.
One for the gateway and other for the remote desktop.
I have written the following code:-
cmdkey /generic:gateway/abc.com /user:user1 /pass:password1
cmdkey /generic:TREMSRV/10.2.13.4 /user:user2 /pass:password2
start mstsc /v:10.2.13.4
But on running this code the pop to enter first set of credentials appears. I want to hardcode the credentials in the batch file itself
Can anyone suggest how shall i accomplish this ?
I am trying figure out how to run an application on local pc and then on my second pc both are at my home network, I am using several applications which merge together by entering second pc ip, so i though if i can anyway do something like
my spec: local 10.0.0.1
and second pc 10.0.0.4
need to run from my local
#echo off
start "" "C:\TEST\TESTAPP.EXE"
start 10.0.0.4 "C:\TEST2\TESTAPP.EXE" <-- just need find a way how to do this
didnt found anything regarding start command and ip address specified maybe it couldnt be achieved with bat script?
thanks everyone for any helpful response and sorry if its just dumb question
If I understand correctly you are trying to start a script on machine B from machine A. If this is correct I would recommend using PSExec from Sysinternals Suit.
Example
Psexec.exe \\<computername or ip> -u username -p password C:\ProgramToRun.exe
PSExec help file from http://technet.microsoft.com/en-us/sysinternals/bb897553.aspx
Using PsExec
Usage: psexec [\\computer[,computer2[,...] | #file]][-u user [-p psswd][-n s][-r servicename][-h][-l][-s|-e][-x][-i [session]][-c [-f|-v]][-w directory][-d][-<priority>][-a n,n,...] cmd [arguments]
-a Separate processors on which the application can run with commas where 1 is the lowest numbered CPU. For example, to run the application on CPU 2 and CPU 4, enter: "-a 2,4"
-c Copy the specified program to the remote system for execution. If you omit this option the application must be in the system path on the remote system.
-d Don't wait for process to terminate (non-interactive).
-e Does not load the specified account’s profile.
-f Copy the specified program even if the file already exists on the remote system.
-i Run the program so that it interacts with the desktop of the specified session on the remote system. If no session is specified the process runs in the console session.
-h If the target system is Vista or higher, has the process run with the account's elevated token, if available.
-l Run process as limited user (strips the Administrators group and allows only privileges assigned to the Users group). On Windows Vista the process runs with Low Integrity.
-n Specifies timeout in seconds connecting to remote computers.
-p Specifies optional password for user name. If you omit this you will be prompted to enter a hidden password.
-r Specifies the name of the remote service to create or interact with.
-s Run the remote process in the System account.
-u Specifies optional user name for login to remote computer.
-v Copy the specified file only if it has a higher version number or is newer on than the one on the remote system.
-w Set the working directory of the process (relative to remote computer).
-x Display the UI on the Winlogon secure desktop (local system only).
-priority Specifies -low, -belownormal, -abovenormal, -high or -realtime to run the process at a different priority. Use -background to run at low memory and I/O priority on Vista.
computer Direct PsExec to run the application on the remote computer or computers specified. If you omit the computer name, PsExec runs the application on the local system, and if you specify a wildcard (\\*), PsExec runs the command on all computers in the current domain.
#file PsExec will execute the command on each of the computers listed in the file.
cmd Name of application to execute.
arguments Arguments to pass (note that file paths must be absolute paths on the target system).
-accepteula This flag suppresses the display of the license dialog.
I would like to run a batch file that could open the services window and allows me to connect to another computer in order to restart a service on a remote machine.
And a different batch file to remote a network registry located in the same domain.
Here are the steps that I'm trying to do using a batch file :
open "services.msc"
connect to another computer...
select computer name (I will then type the computer name manually)
net start RemoteRegistry + Select Startup type to "Automatic"
open "regedit"
GO to File > Connect Network Registry > enter computer name (I will then type the computer name manually once again)
modify the following key : HKEY_Local_Machine>System>CurrentControlSet>services>LanManServer>Parameters
to [0] disable
or [1] enable
Restart "Server" services
Type sc /?. This is built in to Windows. At it's most simple
sc \\server start service
Registry (reg /?) is the same but the computer name is part of the registry path.
REG QUERY \\server\HKLM\Software\Microsoft\ResKit\Nt\Setup /s
I am Help Desk for a company and we have some computers on our VPN. We sometimes have to use Windows Remote Desktop to login to these computers. (mostly Windows XP but some Windows 7)
When we remote into a Windows the computer/session is locked
I would like to be able to make a popup appear on their computer saying they can log back in.
I use 2 command-line tools in order to issue remote commands: psexec & nircmd.
nircmd is useful because it has command-line options to make a pop-up but it will pop-up inside the session not on the "computer locked screen".
I have played with Local Security Policy and it will you to display a message when they first login but not while the session is locked.
It does have an option to display username while session is locked so somehow it can display certain things during a locked session.
#npocmaka Thanks
I ended up using msg.exe but because of restrictions on our company's network I used a combination of psexec and msg
msg server:IPADDRESS /v "message"
didn't work so I used
psexec \IPADDRESS -u username -p password msg /server:IPADDRESS /v "message"
but in order for it to work I had to run
psexec \IPADDRESS -u username -p password reg add "HKLM\SYSTEM\CurrentControlSet\Control\Terminal Server" /v AllowRemoteRPC /t REG_DWORD /d 1 /f
on the remote computer. I got the reg command from another post in StackOverflow actually!