can't start notepad on remote machine using psexec - windows

I need execute some script in remote computer, I try to start notepad. I use psexec, this command
psexec -e -i 1 \\localhost -u domain\user -p password cmd /c notepad.exe
successfully opens notepad on my local machine, but doesn't do it on remote.
I can't see any error, output is the same as I see after executing on local machine:
PsExec v2.0 - Execute processes remotely
Copyright (C) 2001-2013 Mark Russinovich
Sysinternals - www.sysinternals.com
What could be a reason I can't execute notepad successfully on remote machine?

To start notepad on remote machine using psexec:
psexec \\RemoteserverHOSTNAMEorIPADDRESS -u domain\user -p password -d -i cmd /c notepad.exe
For more information.....PsExec

Related

PsExec and WindDirStat on a remote system - how to run

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"

Launch Notepad.exe using PsExec sysinternal tool

I am trying to launch notepad.exe on remote server A from local server B.
below is the command which works fine and I could see notepad.exe process on Task Manager however when I physically remote login to server I do not see notepad launched (GUI).
C:\Windows\System32>D:\SysInternals\psexec.exe \\serverB
-u Domain\user1 -p passXX -i -d notepad.exe
PsExec v1.98 - Execute processes remotely
Copyright (C) 2001-2010 Mark Russinovich
Sysinternals - www.sysinternals.com
notepad.exe started on serverB with process ID 3328.
How would I see notepad GUI when logged in ?
is serverB a terminal server ? if so you have to specify the user's session number, otherwise notepad will be opened in the console (session 0).
you can use for example query session to get the active session on you server :
query session /server:serverB user1
then pass the session number to -i parameter :
psexec \\serverB -u domain\user1 -i 2 notepad.exe
where 2 is the session of user1

Howto use psexec via powershell invoke-command on a remote computer? (invalid handle)

I have written a powershell script which creates a powershell script or a batch script depending on the remote host on which this script should be started remotely (either via powershell invoke-command or psexec).
The script creates either a powershell or a batch script, because not all hosts on which these created scripts should be run support WinRM (Windows Remote Management).
The created scripts include some psexec lines which executes a command on another remote host. The created batch script works as expected, but from the created powershell script i get the following errors from the psexec calls.
NotSpecified: (:String) [], RemoteException
+ CategoryInfo : NotSpecified: (:String) [], RemoteException
+ FullyQualifiedErrorId : NativeCommandError
+ PSComputerName : <HOSTNAME REPLACED>
PsExec v2.1 - Execute processes remotely
Copyright (C) 2001-2013 Mark Russinovich
Sysinternals - www.sysinternals.com
The handle is invalid.
Access is denied.
Connecting to 10.XXX.XXX.127...Couldn't access 10.XXX.XXX.127:
Starting PSEXESVC service on 10.XXX.XXX.127...Could not start PSEXESVC service on 10.XXX.XXX.127:
Connecting to 10.XXX.XXX.127...Starting PSEXESVC service on 10.XXX.XXX.127...
Here is a small overview of what is done:
Powershell script on deployment host creates the rollout script (ps1 or batch) depending on the destination host
Powershell script on deployment host starts the created rollout script on the destination host
Powershell will be started via Invoke-Command -ComputerName <destination host> -FilePath <path to created script> -Authentication default
Batch will be started via & psexec.exe \\<destination host> -n 60 -accepteula -c -f <path to created script>
Created rollout script on the destination host executes a psexec command to start a service on a third host (this fails only if the rollout script is powershell)
This is the psexec command which fails if executed via a remotely started powershell script.
& psexec.exe \\<destination host> -n 60 -accepteula -u <user> -p <password> net stop <servicename>
The same command psexec.exe \\<destination host> -n 60 -accepteula -u <user> -p <password> net stop <servicename> executed via a remotely started batch script works without problems.
Update #1
Also if i connect to the destination host with rdp and start a powershell shell and paste the command it works without issues. The problem only occurs if started remotely.
I already tried the following variants of starting psexec, all without luck!
& psexec.exe \\<destination host> -n 60 -accepteula -s -u <user> -p <password> net stop <servicename>
Start-Process cmd.exe -Credential "<domain>\<user>" -WorkingDirectory $env:systemdrive -ArgumentList "/C psexec.exe \\<destination host> -n 60 -accepteula -u <user> -p <password> net stop <servicename>"
Start-Process powershell.exe -WorkingDirectory $env:systemdrive -Verb Runas -ArgumentList "cmd.exe /C psexec.exe \\<destination host> -n 60 -accepteula -u <user> -p <password> net stop <servicename>"
can you try to replace your psexec command, and use cmd.exe like thisn also add -s to psexec so it will run as system user. My testing command :
icm -cn computer1 -ScriptBlock{ cmd.exe "/c psexec -s -u <login> -p <password> /accepteula /n 10 \\computer2 net start audiosrv"}
You are running into the Second Hop problem:
http://blogs.technet.com/b/heyscriptingguy/archive/2012/11/14/enable-powershell-quot-second-hop-quot-functionality-with-credssp.aspx
The answer is to enable the appropriate relationship between the two computers involved (see previous link or just search google for 'powershell' and 'second hop') and to add to Invoke-Command:
-Authentication Credssp -Credential
What worked for me was:
Start-Process -FilePath .\PsExec.exe -ArgumentList "/acceptEula /s \$Computer program.exe /arg"

PsExec hangs when executing batch file in bamboo continous integration server

I have a batch file on my bamboo server, that starts another batch file on an remote computer trough PsExec. If I double click the batch file on the bamboo sever everything is working fine, the batch file on the remote computer starts and PsExec exites with error code 0.
But if I start bamboo then PsExec hangs itself and the batch file on the remote computer don't start.
C:\PsTools>PsExec.exe \\<remote server> -u <user> -p <password> -s -i "C:\batchfile.bat"
PsExec v1.98 - Execute processes remotely
Copyright (C) 2001-2010 Mark Russinovich
Sysinternals - www.sysinternals.com
This is my output and where PsExec hangs.
I don't understand why it hangs only when bamboo starts the batch.
Hope someone can help me
[ Program output lost when passed through PsExec ]
there's a bug in psexec and it does redirects correctly when is called by everything different by cmd. You have few more options to start a process on remote machine:
1. http://feldkir.ch/xcmd.htm - it cannot be run on localhost
2. WMIC - also cannot be used on localhost , when host and and user/pass are given
2. SCHTASKS
This is an old question but maybe somebody has the same problem.
The first time you run psexec an eula dialog is shown. In order to avoid bamboo hanging with this dialog you may try the argument \accepteula. For instance:
PsExec.exe \\<remote server> -u <user> -p <password> -s -i "C:\batchfile.bat" -accepteula

How to execute a Windows command on a remote PC?

Is it possible to execute a Windows shell command on a remote PC when I know its login name and password?
Is it possible to do it using client PC's Windows shell?
If you are in a domain environment, you can also use:
winrs -r:PCNAME cmd
This will open a remote command shell.
psexec \\RemoteComputer cmd.exe
or use ssh or TeamViewer or RemoteDesktop!
This can be done by using PsExec which can be downloaded here
psexec \\computer_name -u username -p password ipconfig
If this isn't working try doing this :-
Open RegEdit on your remote server.
Navigate to HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Policies\System.
Add a new DWORD value called LocalAccountTokenFilterPolicy
Set its
value to 1.
Reboot your remote server.
Try running PSExec again from
your local server.
You can use native win command:
WMIC /node:ComputerName process call create “cmd.exe /c start.exe”
The WMIC is part of wbem win folder: C:\Windows\System32\wbem

Resources