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
Related
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"
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).
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
I've created and scheduled a batch file in Windows 8.1 (to perform rsync offsite backups through an SSH tunnel) and I can run it:
manually
through task scheduler manually when I right click -> Run
through task scheduler automatically when I am logged on and it's scheduled to run at a given time
... but when I'm not logged on, it just sits at "Running" even though I've set it as follows:
user=me (I'm a member of admin group)
run whether logged on or not
run with highest privileges
I can see in Task Manager that rsync.exe and ssh.exe are running, so it must be hanging on the rsync/ssh call. That leads me to believe the problem is that, even though I've explicitly set the user name, something isn't really running as me?
(sidebar: I've also tried running the task as SYSTEM user - no luck there either)
The command I'm issuing looks like this:
rsync --archive --verbose --human-readable --hard-links --delete --exclude '*.log' --exclude '*log*.*' -e "%CWRSYNCBIN%\ssh -p 22103 -i C:\Users\test\.ssh\id_rsa" "/cygdrive/c/Users/test/Downloads" admin#1.2.3.4:/path/to/remote 1> %REPORTLOG% 2> %ERRORLOG%
Any ideas? (thanks!)
This seems to be problem with home directory and non-interactive environment in scheduled jobs in newer Windows version (starting from Server 2008 and Vista?). I find it in few discussions, but with not much info to solve it:
http://answers.google.com/answers/threadview/id/528721.html
Rsync for Windows cannot run on Task Scheduler
https://serverfault.com/questions/207118/cwrsync-on-server-2008-r2-as-a-scheduled-task
https://superuser.com/questions/368828/rsync-on-windows-xp-works-fine-on-demand-but-hangs-when-run-as-a-scheduled-task
My solution was:
set task to run under user that is proven to be able to finish rsync, set run whenever user are logged on or not, I also set to does not save password,
find location of .ssh folder under this user (in his home directory),
copy .ssh to simplier path to use it in HOME variable (SET HOME=D:\CWRSYNC\HOME),
use following script to run rsync:
#ECHO OFF
SETLOCAL
SET CWRSYNCHOME=D:\CWRSYNC
SET HOME=D:\CWRSYNC\HOME
SET CWOLDPATH=%PATH%
SET PATH=%CWRSYNCHOME%;%PATH%
rsync.exe -rtvz --delete /cygdrive/b/ user#192.168.1.2:/volume1/NetBackup/ >> D://nas-backup-log.txt
When I experienced this problem on Windows Server 2012 R2, I found SSH.exe was experiencing a permissions error when attempting to create a known_hosts file, despite the task running with an admin's credentials and with highest privileges.
The solution was to point to the user's existing known_hosts file using the UserKnownHostsFile SSH option:
rsync -e "ssh -i sshkey -o UserKnownHostsFile path/to/known_hosts" source dest
I'm trying to run this from my win7 CMD (as Admin):
psexec IpAddress -u domain\user -p pword c:\Autobatch\ClientJobSender.exe http://reportserver.net:8070/JobExecutor.asmx c:\AutoBatch\backup\trigger.xml
but am getting a "the system cannot find the file specified" error.
I've also tried it this way:
psexec IpAddress -u domain\user -p pword c:\Autobatch\ClientJobSender.exe http://reportserver.net:8070/JobExecutor.asmx c:\AutoBatch\backup\trigger.xml
but get a unknown user or bad password.
What's weird is that I can connect via Remote desktop with the same IP address and user/pass.
Make sure the server has the settings below:
a) Admin share is enabled: run services.msc and check the Service "Server" is enabled
b) Add the key for the share in the registry and restart:
reg add "HKLM\SYSTEM\CurrentControlSet\Services\LanmanServer\Parameters" /v AutoShareServer /t REG_DWORD /d 1
And then use:
psexec \\IpAddress -u domain\user -p pword -w "c:\Autobatch" "ClientJobSender.exe http://reportserver.net:8070/JobExecutor.asmx c:\AutoBatch\backup\trigger.xml"
Actually, I don't see a difference between your 2 command lines. However, the error from the first command is because your syntax is incorrect. You must use
PsExec \\a.b.c.d ...
instead of
PsExec a.b.c.d ...
I got it to work by elevating the local batch file to execute with administrator privileges, that is to say, the terminal window was operating with administrator privileges.
If you're trying to use automation services, you can use the ClientJobSender.exe on the local machine (or on the machine where you set up the scheduling). Just copy the ClientJobSender.exe and the related config file from the install pack to the scheduler server and refer it locally.
You might have the directory path wrong. Try change the .exe path into cmd.exe and cd into your intended path to see if it is actually the correct path.