# using runas with a password and a sql command

I have a batch file with the following script (which i found here at stackoverflow)

@if (@CodeSection == @Batch) @then
@echo off
CScript //nologo //E:JScript "%~F0"
goto :EOF
@end
WScript.CreateObject("WScript.Shell").SendKeys("mypass{ENTER}");


this works perfectly and a new commandline window opens as the new user! the problem is that i now need to run an sqlcmd with parameter and I can't find any way to write a batch that does both things together (open the new window as another user together with the command with parameters)

the sql command:

"C:\Program Files\Microsoft SQL Server\110\Tools\Binn\SQLCMD.EXE" -S "my.server.com, 1234" -d "myDataBase" -E -b -q "EXEC myDataBase.[dbo].[myTable] @parameter=1"


I tried moving the whole sql command to another batch (myBatch.bat) file and change the first batch to this:

start runas "/user:domain\username" "myBatch.bat"


but it doesn't work.

runas /user:domain\user "cmd.exe /k c:\path\to\mybatch.bat test"

cmd /k to keep the console open after the batch execution, or cmd /c to close it