Run command in background within PSEXEC

2

Command below works fine and releasing, renewing remote IP address.

PsExec.exe \\10.10.1.12 -accepteula -u Administrator -p 1 cmd /c "ipconfig /release && ipconfig /renew"

However, since the IP connection is lost after release, PsExec is waiting some time until generating error. I know I could specify timeout, but to distinguish between real errors, I would like to run above commands in background. I would like to use start /B, but my attempts failed, such as:

PsExec.exe \\10.10.1.12 -accepteula -u Administrator -p 1 "cmd /c start /B "ipconfig /release && ipconfig /renew""

Looking for correct way to use start /B.

Pablo

Posted 2015-10-25T16:54:06.367

Reputation: 4 093

Might be worthwhile to use option -d Don't wait for process to terminate (non-interactive). You will still get an error code for a fail and a process ID if it starts – Shaun Vermaak – 2015-10-25T17:09:16.680

Answers

2

Create a batch file with a name such as ReleaseRenewIP.cmd with the following:

@ECHO OFF
IPCONFIG /release && IPCONFIG /renew

Once this is complete run the below remotely:

PSEXEC \\10.10.1.12 -s -c ReleaseRenewIP.cmd

These PSExec command options do the following:

-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.

-s  Run the remote process in the System account.

Pimp Juice IT

Posted 2015-10-25T16:54:06.367

Reputation: 29 425

0

You can't just double-quote double quotes (nested quotes); you need to 'escape' the inner quotes so that they're not seen as termination for the current statement.

In Windows' command line, you escape double quotes by doubling them up. So try:

PsExec.exe \\10.10.1.12 -accepteula -u Administrator -p 1 "cmd /c start /B ""ipconfig /release && ipconfig /renew"""

I think you may also have to wrap cmd /c's command argument in quotes as well, so perhaps:

PsExec.exe \\10.10.1.12 -accepteula -u Administrator -p 1 "cmd /c ""start /B ""ipconfig /release && ipconfig /renew"""""

Ƭᴇcʜιᴇ007

Posted 2015-10-25T16:54:06.367

Reputation: 103 763

PsExec could not start cmd /c "start /B "ipconfig /release && ipconfig /renew"" on 10.10.1.12: The system cannot find the path specified. – Pablo – 2015-10-25T17:14:11.807

The examples may not be exactly right (I hadn't tested them fully), but the point of the answer still stands. :) Please update your question to include the various command versions you've tried, and what the resulting errors for each one were. – Ƭᴇcʜιᴇ007 – 2015-10-25T17:17:33.790

Also, have you gotten the start /b command (by itself) to work as intended in testing? – Ƭᴇcʜιᴇ007 – 2015-10-25T17:19:10.203

-2

guy's basic principals first please. crawling, walking then running please!

Remember single instructions first, learn how it works, understanding what u are trying to do...from asking the question till getting the answer u need to understand what u are doing!

It needs to make sence, okay.

The same with giving commands, u need to know what must or should be your intended result, the question, the answer, the command or instruction, and how to get it. It must be able to repeatedly give the same or similar results. Please note that different OS'ses and versions of software can give different results on the same command!

U do need to know and remember this.

When u understand the single instruction or command, then try combining or stringing commands.

Here again remember commands can, may or may not interfere with each other and also react differently on different OS'ses and, or other versions of software or combinations there off (including other machines on the network may, when on or off, in or out, sometimes both, alter or give different results on the local machine you are working on).

Burnt my fingers many times.

NB: Try on one pc with a single OS in a fixed setup to be able to do or get concice or repededly the same results or outcome, before going to the next step.

With these simple steps u will be able to do anything on every type of system, new, old, even in another language than your own. Because U understand what U want and need to do.

Yes i can give the command to u ... but will u be able to give it over to another to use, or use it elswere?

Try to eliminate to many variables.

Be precise!

Enjoy what u are trying to do....happy hunting ;-)

crelikus

Posted 2015-10-25T16:54:06.367

Reputation: 1