|
Answer» Hi Guys,
I have a very very simple script that I can't seem to get working.
----------------------------------------------------------------------------------- @echo off
SET /P abaccount1=Enter your Admin username : echo.
runas /user:europe\%abaccount1% "cmd /k (set vara=%computername1%=Enter the computer name : && ping -t %computername1%) " -----------------------------------------------------------------------------------
It should ask me for my admin user name and password, once the correct credentials have been entered, type in the computer name I wish to ping and ping it. It doesn't seem to hold the variable using the "&&" command.
Not sure if this is possible to do, but its been driving me nuts all morning?
Cheers
Danny tbh I'm not quite sure what your trying to achieve, but...
try, Code: [Select]runas /user:europe\%abaccount1% "cmd /k (set /p vara=%computername1%=Enter the computer name : | ping -t %computername1%) "
I've replaced the && with a pipe as your trying to pipe out the set command to a ping. not sure if this will work though.... Seems to give me a syntax error.
At present I'm just trying to run CMD as an admin user, be prompted for a computer name and then execute a command after that. Its relatively useless for ping, but there are other commands like stop services on remote PC's which is what I'll once this basic script works!
CheersWith the original script, I get "IP address must be specified". Due to the "|" pipe or "&&" the variable is not recognized in the second command, which I think is where the problem is I've done somthing similar before. But i used pstools I think;
Code: [Select]set /p PC="Enter pc name or ip address: "
echo. echo.
start /wait c:\pstools\psexec \\%PC% cmd.exe(or path to program to be run) -u username -p password
echo.Pressing a key will end this script... pasue>nul
exit Unfortunately I am unable to use any 3rd party tools due to it being a tool for work
Thanks for the script though it'll work nicely at home.
Unless I missed something, there seems to be too MANY equal signs.
Code: [Select]@echo off
SET /P abaccount1=Enter your Admin username : echo.
runas /user:europe\%abaccount1% "cmd /k set /p vara=Enter the computer name: & ping -t %vara%"
Thanks for the reply.
I still get "IP address must be specified." as the error message.
I doesn't seem to pick up the variable. There may be a problem with using cmd in this context. By using the /k switch you have two ENVIRONMENTS. The original cmd prompt environment and another created by cmd /k
You can test this by running:
Code: [Select]cmd /k set /p vara=Enter the computer name: & ping -t %vara%
from the command line. After the set runs, type exit and you can watch the ping attempt to run in the original window with %vara% undefined.
A batch file should work with runas by BATCHING all the commands into the new environment.
Why not ask for both variables up FRONT? Try something like: Code: [Select]@echo off
SET /P abaccount1=Enter your Admin username: SET /P computername1=Enter the computer name: echo.
runas /user:europe\%abaccount1% "cmd /k ping -t %computername1%"
|