Thank you for being a valued part of the CNET community. As of December 1, 2020, the forums are in read-only format. In early 2021, CNET Forums will no longer be available. We are grateful for the participation and advice you have provided to one another over the years.

Thanks,

CNET Support

General discussion

Need Help with Modifying a Batch File

Jan 14, 2008 10:42PM PST

I have no experience with coding batch files, but have been asked to look at and try to fix one here at my job. The batch file was written to transfer information from our company to another company. However, within the file, the username is hard-coded into the script. This would be fine, except that when we went to change to a new user, we have to change the code. Is there any way to use a constant value in the batch file, so that it will accept whatever user has permissions through the program?

Discussion is locked

- Collapse -
Re: batch file
Jan 14, 2008 10:47PM PST

Janine,

The usual meaning of "batch file" comes from MS-DOS, and MS-DOS doesn't know usernames, let alone in batch files. And there's no MS-DOS program that will ever ask for it.

So please give more details, such as a listing of the relevant part of this batch file and its filename (including the extension). Of course, if there's any sensitive information in it, edit it and replace with something neutral.

Kees

- Collapse -
Re: batch file
Jan 15, 2008 12:09AM PST

The filename of this batch file is pgp.bat. The batch file is as shown below, where "elements" is the name of the program that the information is transferred from.

copy "c:\progra~1\elements\pgp\???ring.*" "c:\documents and settings\nameofuser\my documents\pgp\???ring.*" /y

if exist c:\progra~1\elements\*TXFRK27 del c:\progra~1\elements\*TXFRK27

pgp --encrypt --sign --armor --conventional-passphrase "companypassword" --text c:\progra~1\elements\checks.txt --user "12345678" --output "c:\progra~1\elements\PGP_ARP_ISSUED_7LFJ2CX" --sign-with "Manager Name"

Sillygp --encrypt --sign --text --input c:\checks.txt --user "12345678" --output "c:\PGP_ARP_ISSUED_7LFJ2CX" --sign-with "COMPANYUSERNAME" --passphrase "companypassword"

\\servername\apps\ws_ftp\ws_ftp95.exe -p BankName -s local:c:\progra~1\elements\PGP_ARP_ISSUED_7LFJ2CX -d BankName:/

- Collapse -
Been a while....
Jan 15, 2008 2:49AM PST

It has been a while since I have messed with batch files, but you should be able to put in a prompt for the user to fill in their username and password. The batch would then use those variables during that session.

- Collapse -
Add a variable to that batch. Example.
Jan 15, 2008 5:22AM PST

You say it's called PGP.bat? For Windows we have some standard variables listed at http://vlaurie.com/computers2/Articles/environment.htm

So copy "c:\progra~1\elements\pgp\???ring.*" "c:\documents and settings\nameofuser\my documents\pgp\???ring.*" /y is now

copy "c:\progra~1\elements\pgp\???ring.*" "c:\documents and settings\%USERNAME%\my documents\pgp\???ring.*" /y

But I'd beef that line up by a rewrite to...

copy "%PROGRAMFILES%\elements\pgp\???ring.*" "%USERPROFILE%\my documents\pgp\???ring.*" /y

Bob