I've created a procedure on VBA (Excel) that restarts services on remote servers calling the command prompt and executing the "runas" command. I need to enter the command on the servers as administrator. So far it works fine but I don't want to have to type my password for each I want to run the command in. I know how I can automate the task using VBA and the Excel. What I don't know is how could I input my password on the command prompt using VBA?
Can anybody help me?
Thanks.
I've had all sorts of issues trying to convince runas to let me specify passwords from a program.
In the end, I tossed it and downloaded psexec from the Microsoft Windows Sysinternals site, which has other good stuff as well.
While many see this as a tool running remote programs, it can also be used quite happily to run local stuff under a different user name while allowing you to specify the password as a command-line argument, such as:
psexec -d -u USER -p PWD -w WORKDIR EXECUTABLE
You should be able to create a textbox control in VBA with the input mask set to password, this will allow you to enter the password in a non-viewable fashion.
Then you can just construct the psexec command and execute it from VBA, without having to worry about injecting the password into the process running runas.
Related
I have a scenario where I need to run a shell command to a unix based appliance frequently from windows (linux could be an option). Because it's an appliance, it doesn't have the full breadth of capabilities that, say, Linux would have. I am using PuTTY to do this (I could use SSH from linux as well) which, I assume will work if I do something like "putty.exe -ssh -2 -l username -pw password -m c:remote.cmd hostname", but that only gets the command started. A user has to manually input the password - it cannot be done through command line, and I'm unaware of the capability to grab input from a file.
Is there a way by which I can automate this through the Putty?. By that I mean, I would like to send the input to the command in Putty like I was there, which would thereby be sent it to the appliance, not run a local script.
Thanks all in advance. Your input is greatly appreciated as we all may learn a little something.
Victor
For automation, use Plink (from PuTTY package). It's a console equivalent of PuTTY. So it supports input redirection:
(
echo password
echo some other input if needed
) | plink username#example.com command
I am writing a shell script in Jenkins that logs into a database and runs an sql file. All of the commands are logged to the console, so if I use the simple login method for sqlplus (sqlplus -s $USERNAME/$PASSWORD#connectionstring), the password gets logged, which isn't ideal.
This works:
sqlplus -S ${USERNAME}/${PASSWORD}#connectionstring #sql_update.sql
but the logging on Jenkins shows the command once the values have been substituted:
+ sqlplus user123/pass123#connectionstring #sql_update.sql
To avoid having the password logged, I am trying to use the sqlplus login method where you just provide the username and then get asked to input the password.
I have tried the following, but I am getting ORA-01-17: invalid username/password; logon denied
sqlplus -s ${USERNAME}#\"connectionstring\" <<EOF
${PASSWORD}
sql_update.sql
exit
EOF
Is there something obviously wrong with this?
It's worth noting that simply disabling the console logging isn't an option, as we need it for other things in the script.
Also, the difference between this question and Connect to sqlplus in a shell script and run SQL scripts is that I am asking about providing the password separately.
EDIT I managed to partially resolve the issue thanks to Echo off in Jenkins Console Output. My script now contains set +xbefore the commands are run, which hides the commands. However, I'd still like to know what was wrong with the above, so am leaving this question open for now.
I need to SSH a remote machine and get onto the developer mode. To be specific, I want to execute the command 'Ctrl+gog' upon which I will be prompted for a password. I know how to execute the normal commands, for example chan.send("enable\n"). Please provide me with an answer.
chan.send("\x07\x0F\x07")
Above command worked fine for me.Just concatenate the Hexa equivalent for Ctrl-g,Ctrl-o,Ctrl-g which is, x07x0Fx07.
I am unable to supply password to runas from commandline
I have tried the following
cmd /C echo my_admin_password | runas /user:DOMAIN\my_admin_login c:\test.bat
and
echo my_admin_password | runas /user:DOMAIN\my_admin_login c:\test.bat
And the error I get is
Attempting to start c:\test.bat as user "DOMAIN\my_admin_login" ...
RUNAS ERROR: Unable to run - c:\test.bat
1326: Logon failure: unknown user name or bad password.
How do I fix this?
Take a look at this link: runas utility
It's a runas free utility that have the follwing features:
It accepts password as a command line parameter so that it can be used in batch files.
It can bind started process to the interactive user Desktop so it can be used to start interactive processes from various services such as 24x7 Scheduler, 24x7 Event Server and other.
Note: Professional version of RunAs also supports encryption of the entire command line, which administrators can use to give regular users access to certain programs requiring admin-level privileges. Users don't need to know the administrator's password and cannot use it to run anything elseā¦ simple, yet very efficient solution for this common problem.
Also you can try pass the password as input for the process using subprocess.Popen.communicate or even subprocess.Popen.stdin.write.
Other interesting links:
How to pass a password to a process?
Command-line runas with password
PsExec
I have a batch file that runs another batch file as a different user.
I also need to run the calling batch file remotely. Locally I can bypass having to enter the password with the /savecred option but then when I run the batch remotley, I still get prompted for the password but it would appear the connection times out because I'm brought back to the powershell prompt on the machine i'm connecting from.
my batch looks like this:
runas.exe /env /savecred /user:sqlsvr_dba ".\myBatch.bat"
How can I run the remote batch on my local machine without having to enter the password? I've been trying to use powershell for this.
Same question bothered me too :-)
I've tried to workaround this with schtasks and eventcreate.Here i posted my solution :
http://ss64.org/viewtopic.php?id=1539
If you want to run the script on a remote machine you can also try with wmic:
http://ss64.org/viewtopic.php?id=1495
Hope these will help you.