42

I am using an application that requires several attempts to log in (because of overloaded servers).

This app has no "remember my password" feature.

Therefore, I would like to make a script (preferably a .bat script), that would first copy my password into the clipboard -so that I don't have to retype my password on every log on attempt- , then launch the application (easy part)

Is this possible with a MS-DOS command ? Do I need a little exe or another script language ?

I'm obviously looking for the quickest solution to implement.

Thanks in advance for your ideas

Sébastien
  • 1,127

6 Answers6

52

http://www.petri.co.il/software/clip.zip
Note- Petri's link is currently down. He got it from windows server 2003 but I see clip.exe on windows 7 too. It's on windows versions post windows 7 too.

C:\>echo abc| clip  <-- copies abc to the clipboard.

EDIT
The main thing is that clip command but as pointed out by Asu, a line like echo abc will also send a \r\n (which is a new line). If you want to avoid that, then that's a very standard issue solved by replacing echo texttoecho, with echo|set/p=texttoecho So C:\>echo|set/p=texttoecho|clip

further addition
You can of course then paste with right click, but for a command line paste too.

unxutils(an ancient thing not maintained since the 1990s) has gclip and pclip (they don't seem to be in gnuwin32), with those you can copy and paste via command line.

note- gnuwin32 might not be that updated either. Gnuwin32 was last updated in 2010! Cygwin is still updated but anyhow.

C:\unxutilsblah\usr\local\wbin>echo a|gclip <-- copy a to clipboard

C:\unxutilsblah\usr\local\wbin>pclip
a

C:\unxutilsblah\usr\local\wbin>

note- you can just copy all of wbin to e.g. c:\unxutils, and the EXEs have no dependencies/dlls.

and you can of course do pclip>a.a to paste to a file. or pclip|somecmd

C:\>(echo b & echo a)<ENTER>
b
a

C:&gt;

C:\unxutils>(echo b & echo a)|gclip<ENTER>

C:\unxutils>pclip<ENTER> b a

C:\unxutils>pclip|sort<ENTER> a b

C:\unxutils>

barlop
  • 25,198
35

barlop's option isn't entirely correct because echo will add a newline character to your password breaking it.

What you need to use instead is this:

echo|set /p=MyPassWord|clip

This way the string will be copied to the clipboard as is.

slhck
  • 235,242
Asu
  • 543
4

You can just use powershell this way:

powershell -c "Set-Clipboard -Value 'MyPassword'"

Not sure how quoting would affect the command line (i.e. if your password has got a single or double quote character in it).

cdlvcdlv
  • 1,739
3

I've myself encountered a similar scenario and here's how I've solved it.

First, I store my passwords in the Windows Credential Vault (Windows Vista and greater). For this, I use Python's keyring library, but you can just as well use something like CredMan (Powershell) to manage them. Using the Windows Credential Vault means the password never has to be typed on the command line, so is unlikely to leak (such as through a command-line history).

Second, I use a tool like clip to copy the password to the clipboard.

You may find you want to combine the two with your own PowerShell script that grabs the text from the credential manager and puts it on the clipboard. The script could be something as simple as:

$cred = Read-Creds 'Some System'
[Windows.Forms.Clipboard]::SetText($cred.CredentialBlob)

Then, all you have to do is add the password to 'Some System' in Windows Credential Manager and that script will magically put the password on the clipboard on command.

2

The easies way to do this is:

  1. open Notepad
  2. copy [CTRL + C] this line:
  3. ECHO | SET /P=mypassword | CLIP
  4. paste [CTRL + V] this line to Notepad
  5. and change "mypassword" for your text, then save it as "filename".bat

And you can edit this copied text whenever you want just edit this file with Notepad.

gamer0
  • 1,001
1

AutoIt v3 can automate windows, which makes trying several login attempts easy.

AutoIt v3 is a freeware BASIC-like scripting language designed for automating the Windows GUI and general scripting. It uses a combination of simulated keystrokes, mouse movement and window/control manipulation in order to automate tasks in a way not possible or reliable with other languages (e.g. VBScript and SendKeys). AutoIt is also very small, self-contained and will run on all versions of Windows out-of-the-box with no annoying "runtimes" required!

AutoIt was initially designed for PC "roll out" situations to reliably automate and configure thousands of PCs. Over time it has become a powerful language that supports complex expressions, user functions, loops and everything else that veteran scripters would expect.

They have good examples, documentation and a solid community that can help you with script problems.

Although, you might be better off asking if they could solve the problem with their overloaded servers, as automating requests might only make the problem worse for them...