PsExec and WindDirStat on a remote system - how to run - windows

I'd like to be able to run WinDirStat on a remote machine that I have administrative rights over but it does not work.
This is what I have done:
Run CMD as admin:
psexe.exe -i -s cmd.exe
From the new prompt:
psexec.exe \\host -u username winddirstate.exe
I type in my PW and it does not launch
Both running Windows 7 Enterprise.

Usage: psexec [\\computer[,computer2[,...] | #file]][-u user [-p psswd][-n s][-r servicename][-h][-l][-s|-e][-x][-i [session]][-c [-f|-v]][-w directory][-d][-<priority>][-a n,n,...] cmd [arguments]
-a Separate processors on which the application can run with
commas where 1 is the lowest numbered CPU. For example,
to run the application on CPU 2 and CPU 4, enter:
"-a 2,4"
-c Copy the specified program to the remote system for
execution. If you omit this option the application
must be in the system path on the remote system.
-d Don't wait for process to terminate (non-interactive).
-e Does not load the specified account's profile.
-f Copy the specified program even if the file already
exists on the remote system.
-i Run the program so that it interacts with the desktop of the
specified session on the remote system. If no session is
specified the process runs in the console session.
-h If the target system is Vista or higher, has the process
run with the account's elevated token, if available.
-l Run process as limited user (strips the Administrators group
and allows only privileges assigned to the Users group).
On Windows Vista the process runs with Low Integrity.
-n Specifies timeout in seconds connecting to remote computers.
-p Specifies optional password for user name. If you omit this
you will be prompted to enter a hidden password.
-r Specifies the name of the remote service to create or interact.
with.
-s Run the remote process in the System account.
-u Specifies optional user name for login to remote
computer.
-v Copy the specified file only if it has a higher version number
or is newer on than the one on the remote system.
-w Set the working directory of the process (relative to
remote computer).
-x Display the UI on the Winlogon secure desktop (local system
only).
-arm Specifies the remote computer is of ARM architecture.
-priority Specifies -low, -belownormal, -abovenormal, -high or
-realtime to run the process at a different priority. Use
-background to run at low memory and I/O priority on Vista.
computer Direct PsExec to run the application on the remote
computer or computers specified. If you omit the computer
name PsExec runs the application on the local system,
and if you specify a wildcard (\\*), PsExec runs the
command on all computers in the current domain.
#file PsExec will execute the command on each of the computers listed
in the file.
cmd Name of application to execute.
arguments Arguments to pass (note that file paths must be
absolute paths on the target system).
-accepteula This flag suppresses the display of the license dialog.
-nobanner Do not display the startup banner and copyright message.
First you are in Same Directory of Psexec or set path of PSexec in Environment path then put this command
psexec.exe \host -u username -p password -s cmd /C C:\full_remote_path_of_\windirstat.exe
OR
put one bat file inside your remote machine like C:\abc\run.bat and put this code inside it
echo off
C:\full_path_of_\windirstat.exe
echo "Success"
and run command from your local
below command will run that bat file present on remote
psexec.exe \host -u username -p password -s cmd /C "C:\remote\run.bat"
OR
there is no need to put run.bat file in remote machine put only on local and then give below command
psexec.exe \host -u username -p password -s -i -c -f "C:\local\run.bat"
OR
psexec.exe \host -u username -p password -s -i -c -v "C:\local\run.bat"
-s ----->as a Administrator
-i ----->Interactive
-c ----->copy run.bat to remote
-f -----> if run.bat already exist on remote Computer
-v -----> if higher version on local and lower version on remote then it
will copy otherwise not
USING FILE NAME
If you want to run on many remote machine and all remote machine username and password are same so put one file like host.txt and put all ip's line by line there is no space on starting on line then give below command and it will run serially
PsExec.exe #C:\full_path\host.txt -c -s -u username -p password run.bat
**Parallel Running in All Remote Machines **
if you want to run parallel then give one more parameter -d then it will not wait to finish process until it finished and you can use for loop and put PSexec command inside it
Save Result in some file THREE Variation
**First Variation**
Below will copy the iname.bat file in remote system and execute it and save the result in success.txt inside local machine directory in which we are running PSexec
PsExec.exe \remote_ip -u username -p password -c -f "iname.bat">success.txt
**Second Variation**
below will run test.bat present on remote machine and make Success.txt on localmachine
PsExec.exe \remote_ip -u username -p passowrd cmd /C "C:\abhi\test.bat">success.txt
**Third Variation**
this will run test.bat present on remote machine and make Success.txt on remote machine
PsExec.exe \remote_ip -u username -p password -i cmd /C "C:\abhi\test.bat > C:\abhi\success.txt"

Related

Executing an application with Vboxmanage guestcontrol does not display on guest

I want to use VirtualBox vboxmanage to launch an application on many Guest machine
to perform tests.
In my case I have a Windows host and Windows guest machines.
Using vboxmanage does spawn the application process (in fact you can see it on Task Manager) but
does not show the application on the Guest screen.
Seems like my application does not have a screen to display or does have a different one...
Is possible to display the application using vboxmanage?
What am I missing?
Thanks
Example of a performed command:
"C:\Program Files\Oracle\Virtualbox\VBoxManage.exe" guestcontrol "Win64" --password pw --username admin run --exe c:\windows\system32\cmd.exe --putenv JAVA_PATH=c:\tests\jre -- cmd.exe/arg0 /C C:\tests\jre\bin\java.exe -jar c:\tests\sikulix -r c:\tests\test_app.sikuli
I managed to launch an application on Windows guest and to have the application show on the screen, so I will post here how to do if anyone needs something similar.
After putting in place the virtual machine with only host network in order to be able to connect from Host to Guest,
I used psexec to interact with guest as the follows:
psexec.exe \\ipaddress -i 1 -u WORKGROUP\username -p password c:\path\to\my\application.exe -d
Some notes about the command:
-i 1 is the options that allows to interact with the desktop of the specified session
-d could be used in order not to wait the process to terminate
WORKGROUP\username pay attention to specify the workgroup
In order to automate operation on multiple virtual machines you can determine the ip address parsing the result of this command:
"C:\Program Files\Oracle\Virtualbox\VBoxManage.exe" guestproperty enumerate vmname
or you can parse the result of a systeminfo on guest like the following:
"C:\Program Files\Oracle\Virtualbox\VBoxManage.exe" guestcontrol MyVMname run --username myusername --password my-password --wait-stdout --wait-stderr --exe "C:\Windows\System32\cmd.exe" -- cmd.exe/arg0 /C systeminfo

Using Plink, how to auto-input password into Ubuntu ssh?

I'm currently setting up a batch file to ssh from a Windows machine into a Ubuntu machine and issue a series of commands. I'm using plink, and I'm using the -m argument to pass a .txt file with a list of commands.
The batch file code that runs through cmd:
set PATH=c:\path\to\plink.exe
plink.exe -ssh -t user#ipaddress -pw <psw> -m c:\path\to\textFile\commands.txt
The commands.txt code:
sudo -s #access the root login
<root psw> #enter the password for the root login
command-1 #issue a command in linux as root
command-2 #issue a command in linux as root
command-3 #issue a command in linux as root
The issue I'm running into is that when I run this batch file, the output within command prompt still prompts the user to manually enter the password. Is there a means to input the password form the next line of the commands.txt file? Or does this process require something else?
As even your question says, the file commands.txt specified by -m switch should contain commands. A password is not a command.
Moreover, the commands in the file are executed one-by-one. The sudo (had it worked) would execute an interactive shell session and wait for a user input (commands). Only once the sudo exits, the following commands (command-1, etc) are executed.
Automating password input for sudo is generally a bad idea. If you need to run some commands that require root privileges, a better solution is to associate a dedicated private key with the commands in sudoers file. And then use sudo and the private key in Plink.
Anyway, to automate an input (of a password in this case) to a command, you need to use an input redirection. The same is true for commands to be executed within (not after) sudo.
Like:
(
echo passwod
echo command-1
echo command-2
) | plink.exe -ssh -t user#ipaddress -pw <psw> sudo -s
As now there's only one real top-level command - sudo, I'm specifying it directly on Plink command-line, instead of using -m switch. Functionally, it's identical.

Can't launch putty with remote command?

I'm attempting to launch putty via the command line in such a way that it runs a command on the server (I want to create a windows shortcut, to tail a log file)
So far I have a batch file containing this
"C:\Program Files (x86)\PuTTY\putty.exe" -ssh -t -pw -m tail_catalina_out -load "myprofile"
And within my server I have a file at the root directory named tail_catalina_out with the following contents.
tail -f /opt/tomcat/logs/catalina.out
Putty launches and my session starts successfully, but no command appears to be carried out despite this? Am I misunderstanding how this works?
You don't need -ssh with -load profile (and if you use a nonstandard port like my test it doesn't work at all); in fact you don't need it with [user#]host because it's the default
-pw -m tail_catalina_out uses -m as your password (which I hope is incorrect, so you should be reprompted unless publickey auth is set-up) and ignores tail_catalina_out
the file for -m must be local i.e. on the PuTTY machine not on the server (although the commands in it will be sent to, and must be valid on, the server)
Thus: "\path\to\putty" -t -m localcmdfile -load profile
You could also use plink which runs in the console and takes either -m localfile or the actual remote command on the command line after the last option (like the OpenSSH client ssh):
"\path\to\plink" -t -load profile tail -f remotefile
As usual, you can omit the quotes around the path if it contains no space. Personally I use \progra~2 instead of bothering with "\program files (x86)" but that's just me, and it may depend on a clean install (instead of upgrade).

installing programs on remote machines

I want to run an installer on remote computer remotely. This mean I first need to copy it somehwere on that remote machine and then run it using tools like psexec. I am using following command to run the program but is there anyway within psexec to copy the file first and then run it. I will appreciate any suggestions about it?
psexec \\RemoteComputer -u username -p something -i c:\PAthOnRemoteMachineMachine\SomeInstaller.msi
You could try PAExec. It supports the same syntax, but also has additional features like "upload-and-run"
paexec \\RemoteComputer -u username -p something -i -c -csrc c:\MyLocalDir\SomeInstaller.msi
The path after -csrc is the path of the source file from where paexec would copy the file from, on the source machine. To direct paexec to execute the file off a specific location on the remote machine we'd have additionally specify the "remote launch path" like c:\windows\abc.exe , optionally with arguments (x y and z below) i.e. copy abc.exe from c:\MyLocalDir on the source machine to c:\windows on the remote machine and launch it there (C:\windows on the remote) with x y and z arguments. The "Reached end of command before seeing expected parts" error is because the last part (remote launch specification) is missing.
paexec \\RemoteComputer -u username -p something -i -c -csrc c:\MyLocalDir\abc.exe c:\windows\abc.exe x y z

PsExec is not copying file over to execute

I want to run a script I called "systemInfo.vbs" that outputs to a logfile the system name and service pack.
In command prompt I am doing "PsExec.exe \REMOTECOMPUTER -c systemInfo.vbs".
I am running this from a directory on my local system that has ONLY PsExec.exe and systemInfo.vbs
I get the error
PsExec could not start systemInfo.vbs on REMOTESERVER: "The system
cannot find the file specified.
Any idea why this may be? I thought I could do this to run a remote script as if it is on the remote server?
You need to give the path to your script either on the remote pc or through a UNC path on a share on your pc or a netsworkdrive. So if the script has a copy on the remote c:\
PsExec.exe \\REMOTECOMPUTER -c c:\systemInfo.vbs
or if it is on the share \\mypc\shared
PsExec.exe \\REMOTECOMPUTER -c \\mypc\shared\systemInfo.vbs
Also you need to make sure you have administrator rights on the pc where you start the script and depending on what your script does possibly on the remote pc as well.
For anyone who might encounter this in the future, the -c flag does allow you to copy over a file for execution; the documentation didn't specify, but you need to follow it with the path on your local machine to the binary you want copied and executed. (I have submitted a pull request to the documentation.)
For example, this could be used to add the "Blend for Visual Studio SDK for .NET" to a remote installation of Visual Studio 2017 Professional by copying the web installer (named vs_professional.exe) to that machine (\\TargetMachine) with credentials, (note the DOMAIN is only if you're using a domain instead of local user), and executing it with appropriate parameters.
D:\PSTools\PsExec64.exe "\\TargetMachine" -u "DOMAIN\user" -p "pass" -h -c "D:\deploy\vs_professional.exe" vs_professional.exe modify --installPath "C:\Program Files (x86)\Microsoft Visual Studio\2017\Professional" --add Microsoft.Component.Blend.SDK.WPF --passive
Another contrived example:
PsExec64.exe \\Target -u user -p password -h -c "filetoremoteexec.exe" filetoremoteexec.exe --flag param1 param2

Resources