0

I am coding a program in C# to communicate with a remote PC in an Wifi AdHoc network. I execute a BATCH file in the remote that will send to the local a CHECK.txt file. I use PsExec.

Everything works fine in my C# program when I execute this batch file remotely with PsExec from the local PC to copy the CHECK.txt file in any of the remote's directories. The problem comes when I modify this BATCH to copy the text file to the LOCAL:

copy C:\Windows\CHECK.txt \\192.168.1.10\C$\Windows

It seems that the process PsExec, used to execute the BATCH in remote, blocks the communication of the network when the BATCH tries to send back to the local the text file. Ports 445 and 139 problem? Any idea of what is blocking the file to be sent back?

Everything is set for a transparent dialog between remote and local (no firewall, etc).

Thanks in advance...

Yomismo
  • 3
  • 2
  • What error(s) are you getting? – aphoria Oct 01 '14 at 11:42
  • Hi Aphoria, and thanks for answering. In fact I'm not having any error... It is just my batch file: when it is correctly executed in the remote PC, the text file is not sent to the local PC as it would do by executing it directly from the remote. Local and Remote work both with win7 and are both in the same WorkGroup (wifi adhoc). – Yomismo Oct 02 '14 at 18:24
  • Does the user id that `PSEXEC` is running the batch as have permissions to write to the admin share (`\\192.168.1.10\C$`)? – aphoria Oct 02 '14 at 18:48
  • Yes it might have them, as when the user id executes the batch directly, it copies the file in the admin share C$ correctly (please correct me if I am wrong)... – Yomismo Oct 03 '14 at 09:22

1 Answers1

0

I just noticed the -s parameter on your PSEXEC command. The -s means Run the remote process in the System account.. Removing it should allow your batch script to write back to local computer.

aphoria
  • 19,796
  • 7
  • 64
  • 73
  • Thanks a lot again aphoria. In fact I am executing the batch file remotely correctly using this parameters: //////////// .ProcessStartInfo("cmd", "/C\\psexec" + " \\\\" + this.tb_ip.Text.ToString() + " -u " + this.tb_name.Text.ToString() + " -psswd " + this.tb_password.Text.ToString() + " -i -d -s C:\\COPY_CHECK2.bat");////////////////////// and everything works ok... I insist, the problem is when the batch is executed... the file is not sent back to the local... :( – Yomismo Oct 03 '14 at 11:16
  • Are you sure the batch file is actually running and just the `COPY` line is failing? Or is the entire batch file failing to run? – aphoria Oct 03 '14 at 11:34
  • In fact, the BATCH just make that, it execute the COPY line, and it works when I execute it manually from what is going to be my remote PC (always connected to my adhoc)... It is just when I execute it using PsExec from the local that it does not send the file back to the local... the IP is correct as is fixed by default (I configured it)... – Yomismo Oct 03 '14 at 12:16
  • Are you saying that the `COPY` line is the only line in the batch file? What happens if you run the `PSEXEC` line from a command prompt on your local machine (not from your C# program)? Open a cmd prompt and run your command...`PSEXEC \\RemoteComputerIP -u YourUserId -p YourPassword -i -d -s C:\COPY_CHECK2.bat`. – aphoria Oct 03 '14 at 12:30
  • Yes, that is completly right. To copy the file is the only porpose. If I execute it from my local's prompt I get exactly the same thing: the batch is correctly executed in the remote but the file is not sent back to the local. – Yomismo Oct 03 '14 at 12:56
  • I just noticed the `-s` parameter, which means `Run the remote process in the System account.`. Try removing that. – aphoria Oct 03 '14 at 13:11
  • 1
    Aphoria, thank you very much for your marvellous diagnostic but also for your generous attitud. It works perfectly. I have removed de "-s" parameter and the file has been sent back. That will allows me to continue with my project. May I invite you to have some beers? See you next time! – Yomismo Oct 04 '14 at 08:41
  • I'm glad you got it working. Thanks for the invitation for a beer. :) – aphoria Oct 04 '14 at 11:23