Batch file for 2 level protection RDP connection - file

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 ?

Related

Batch file to send files through ip

im new with .bat files.
Im trying to create a .bat file that backups files from a PC to a server PC that is not in the same network.
In this case, i can connect to the server pc with my home pc with remote desktop (got the IP, domani username and password), and i want to make a batch file that sends files from my house pc, to the server pc in my job.
Is there any type of way to send them?
This is what i tried so far:
PROGRAM 1:
copy C:\FROM_HERE \\xxx.xxx.xxx.xx\C:\TO_HERE
net use \\xxx.xxx.xxx.xx\C:\TO_HERE /user:username password
robocopy \xxx.xxx.xxx.xx\C:\TO_HERE C:\FROM_HERE
net use /delete
pause
This program says that the route cannot be found.
I dont know, any suggestion please?

Fully Connect to a Remote Desktop using Batch

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.

batch file to automatically connect to vpn connection

I need some help with batch file. I am using windows 7.
I need a batch file to:
Open VPN Client on my PC, path is
("C:\Program Files (x86)\Cisco Systems\VPN Client\vpngui.exe)
There are 5 VPNs in the list. Connect to vpn name (AA_VPN) using my username and password
A window pop ups when I connect - that is 'continue or discontinue'
3. The process should press 'continue' button or spacebar key (all works)
And then the batch file should close itself.
Thanks.
From documentation:
"C:\Program Files (x86)\Cisco Systems\VPN Client\vpnclient" connect AA_VPN user <yourUser> pwd <yourPassword>

Automated Bat File Not Working For Service Account

We have a file that we send to the bank and it worked via bat file when sending through FTPS.exe but not we must use PSFTP.exe which works for the desktop user but not the service account. We have tried logging in as the service account user and running the process which works when we are logged in as but not when scheduled through a Windows Server. Have also tried putting the Y in the bat file to answer the validate question whcih we have to answer only once when using desktop user without success.
I have read a lot of hits online pointing to authentication, using two files, etc... but not sure how to implement them. I would really appreciate assistance with this.
here is my bat file which is called by Gentran as an executeable, server is Windows 2008 R2, Service Pack1:
SET MOVEitIP=FTX-SERVSH.bnymellon.com
SET MOVEitUser=******
SET MOVEitPassword=******
echo cd /inbound/trp/ >> frommoveit.txt
echo mput D:\GENSRVNT\PositivePay\*.txt >> frommoveit.txt
echo quit >> frommoveit.txt
psftp -batch %MOVEitIP% -l %MOVEitUser% -pw %MOVEitPassword% -b frommoveit.txt
del frommoveit.txt
Basically took script from bat file for FTPS.exe and updated it for PSFTP.exe to use. Again, this works as desktop user and service account user (when signed into the server) but not when automated.
Thank you in advance for your assistance.
Krise
The service account must have the "Log On Locally" rights otherwise the account will not be able to logon to execute the sheduled task. I think you will see the logon error in the eventvwr at the time the task was run.

How can I use a batch file to launch an application as a specific user?

I'm trying to figure out how I can use a batch file to launch Internet Explorer as a local user on the system hosting the batch file. Ideally I'd like to be able to double click the batch file and not have to enter user credentials. To break it down a bit:
User is logged onto the host system with a domain user (Server 2008 R2 Standard 64bit)
User can then double click on a batch file that will launch Internet Explorer as a local user on the host system, without prompting for the local user credentials
All I can find is information about NET USE, any help would be greatly appreciated!
"runas" command was intentionally designed to prompt for password. So, that is not your solution.
One of option is to create a scheduled task where you can store the password (safely) and run the scheduled task from batch file.
But if the batch file is distributable and not going to be run on same machine.. you may have to investigate on how to create a schedule task from batch file and then run it.
you may find this reference helpful

Resources