Dinesh Kumar
Dinesh Kumar

Reputation: 101

How to open cmd and pass parameter through batch file

I want to create a batch file to run the command. I want to add IP in my command.
My command is

 route add 26.284.254.269 mask 245.245.256.236 24.18.16.4

The above IPs are examples not actual.

I have created a batch file named runAs.bat. It successfully run in login Administrator. I need to open command prompt as runas domain-name\administrator password and pass the above command in it in windows xp.
I have used the following command.

runas domain-name\administrator password cmd "route add 26.284.254.269 mask 245.245.256.236 24.18.16.4"

But it shows RUNAS USAGE: How to use RUNAS.
Where is the problem in my command. I had google about it but noone could help me. Please give some suggestion or batchfile command for this.

Upvotes: 0

Views: 10306

Answers (2)

HoGo
HoGo

Reputation: 587

Try:

runas /user:domain-name\administrator "cmd /c route add 26.284.254.269 mask 245.245.256.236 24.18.16.4"

runas command does not have password parameter - it will be really insecure to add admin password to batch file. But you can use /savecred parameter.

Upvotes: 1

mydoghasworms
mydoghasworms

Reputation: 18591

The runas command usage shows that the user must be prefixed with a forward slash; possibly that is why you are getting the message. From the runas /? help:

RUNAS [ [/noprofile | /profile] [/env] [/netonly] ]
        /user:<UserName> program

You can execute a command with cmd by using

cmd /c [command]

Upvotes: 1

Related Questions