Batch file - Remote Copy and Execute issue - windows

I have a batch file that part of it copies a folder and its content to a local directory and then continues through the batch process which then tries to execute the contents of the folder . locally run it works on all wintel os and copies the files from \networkshare\folder*.* to %systemdrive%\temp\ .
I have attempted to use e.g psexec #serverlist.txt -c batfile.bat -s -f -d to copy the file and then execute it remotely how ever the issue is that this will not copy the files when run remotely . I think its a authentication issues after you a have remotely executed the batch file the remote system will not allow me to access/authenticate the networkshare
i have tried xcopy , copy , robocopy .

AFAIK you can only authenticate against the next hop using implicit credentials. Connection attempts from the first hop to a second hop will fail, even if your user has the required permisssions. See e.g. here for an explanation.
Try this:
psexec #serverlist.txt -u %USERDOMAIN%\%USERNAME% -d -c batfile.bat
Use explicit credentials so you're authenticated against the remote host. With that the second hop will be the next hop for your authenticated session. Don't run the script as LOCAL SYSTEM (-s), because that account is restricted to local resources.

I've had this issue in the past. Instead of trying to copy/run the BAT file just run the script things from a UNC path if you are able to. I think the problem lies in the BAT file not actually able to run through PSEXEC and copy like you think. Does it give an exit code?
Here's an example I used a while ago to install Adobe reader. I tried to do it through a batch file but no dice. I could not get it to run within the batch file whether I copied it or not. I can't remember the exact reason, I think it had something with the way a batch file is called in the system and runs in some sort of local context. Don't quote me on that though as I can't remember the exact why.
Here is my code example:
psexec /accepteula \\%computer% -s cmd /c msiexec /i "\\UNC\Software\adobe\Adobe Reader 7.0.9.msi" TRANSFORMS="acrobat7.mst" /qn

Related

Proper syntax for psexec.exe hostname with filename to start

I'm trying to use psexec.exe to fire up Excel and then use Excel to open a specific .xlsx file.
I've just started learning psexec and I have written commands that work 'incrementally' in order to be sure my initial building blocks were correct along the way. Decided to actually start with NOTEPAD and a specific TEXT FILE to start:
(Please note, my goal is to execute this process on the local machine, not a remote machine, and for it to be Interactive, thus the -i switch)
This Works (just opens a blank Notepad window)
"C:\Users\Username\OneDrive - OrgName\Desktop\RunAs Test\psexec.exe" -i -u domain\username -p Password C:\Windows\system32\notepad.exe
This does not work - and I am positive the exe path and the file path are correct, I've tried them separately
"C:\Users\Username\OneDrive - OrgName\Desktop\RunAs Test\psexec.exe" -i -u domain\username -p Password C:\Windows\system32\notepad.exe \\server\data\mpsc-users\UserName\Test\sadf.txt
(It just returns the boilerplate 3 lines copyright, but with no mention of Error Code or results at all. Nothing else happens)
PsTools.chm is very clear on why it wont work
"Arguments to pass (note that file paths must be absolute paths on the
target system)"
"psexec.exe" -i \\somewhere.... C:\Windows\system32\notepad.exe c:\users\Isaac\desktop\hello.txt
should work (if the file exists on the remote system)

Opening Cygwin with Windows bat file and running script file

I require a tunnel between my windows machine to a UNIX server and wish to automate the process so that on startup the tunnel will be generated for me.
I installed Cygwin with ssh and autossh to connect to the remote server, built up the connection manually, and have confirmed that the connection works. The process involves 3 commands, which isn't a lot but something that would be great to have automated.
After creating a .sh script file, which includes my autossh connection commands, and saving it using Notepad ++ as a UNIX document (to avoid any potential conflicts regarding the file ending), I can navigate to this script in Cygwin and call bash script.sh. After which the connection is made and I can work on my server.
My problem comes when creating my bat file:
start /d "C:\cygwin\bin\" mintty.exe "C:\Users\user\Documents\Dev\" script.sh
The first part up to and including the .exe file works to open the Cygwin window, but I have been unsuccessful in feeding the script into it. I even tried including a --bash command before referencing the script file as follows, but I received an error that the command is unknown:
start /d "C:\cygwin\bin\" mintty.exe --bash "C:\Users\andrew\Documents\Development\" tunnel.sh
Does anyone know if and how it is possible to open a Cygwin window and call a script file within this window? This is my first time creating a bat file, so I hope this is perhaps a newbie problem that no one even bothers to post a solution online for...
you don't need start.
assuming your Cygwin is in C:\cygwin
you need just:
chdir c:\cygwin\bin
mintty /usr/bin/bash -l -c /cygdrive/c/Users/user/Documents/Dev/script.sh

"ERROR: Invalid syntax. Default option is not allowed more than '2' time(s)." using SETX

I thought I had this working at one time but recently my command quit working. My research here and abroad is not turning up anything I have not attempted already. Perhaps there is some other variable I am missing that SETX is looking at?
My command:
setx /s servername PATH "%Path%";"c:\program files (x86)\java\jre7\bin";"c:\program files (x86)\java\jre7\bin\client" /m
I have tried the same command against a couple of Win2k8 servers to no avail. This has worked but is now producing the error above. I usually run this within a batch file against a list of several servers to push Java out. (Path to java is not being set unless we manually create the entries when remotely installed.)
The existing path on the server I am attempting to update is this:
%SystemRoot%\system32;%SystemRoot%;%SystemRoot%\System32\Wbem;%systemroot%\System32\WindowsPowerShell\v1.0\;C:\BMC\Patrol3\bin;C:\BMC\common\globalc\bin\Windows-x86;C:\BMC\common\globalc\bin\Windows-x86-64;C:\BMC\Patrol3\BEST1\9.5.00\bgs\bin
I did clean up a couple duplicate path entries. Aside from that I did not find anything unusual to me.
Edit:
Tweaking the command to remove some of the quotation marks does allow it to run but with that, it imports the path of the local system replacing the remote systems path and appends the desired path entries.
The revised command:
setx /s servername PATH "%Path%;c:\program files (x86)\java\jre7\bin;c:\program files (x86)\java\jre7\bin\client" /m
In hopes of fixing this new problem, I am attempting to run the command with psexec. Doing so brings me back to my original problem, "Default option is not allowed more than '2' time(s)". Depending on how I modify the quotes when using psexec I can get "To many Arguments" or command succeeded, path truncated which ends up being the local path being applied on the remote server once again.
The most promising of my attempts:
psexec \\servername -u domain\user -p p#ssw0rd "c:\windows\system32\setx" "Path "%Path%;c:\program files (x86)\java\jre7\bin;c:\program files (x86)\java\jre7\bin\client" /M"
Using the "-s" option on psexec produces the same error, just less detail.
I was able to update the path value on remote systems by creating a batch file to be executed remotely.
Contents of "setJava7path.cmd"
setx Path "%Path%";"%ProgramFiles(x86)%\java\jre7\bin";"%ProgramFiles(x86)%\java\jre7\bin\client" /m
To execute I utilized psexec which copied the batch file to the remote system and executed the command.
psexec \\systemname -c setJava7path.cmd
It adds / changes a line to my overall deployment script but that is livable.

Aws S3 cp will not run through r system function (windows) -- Unable to locate credentials

I have a batch file that looks like the following (call it "awsCopy.bat"):
"C:\Program Files\Amazon\AWSCLI\Aws.exe" s3 cp "s3://xxxs3bucketxxx/file.csv" "\\networkDrive\folder\file.csv"
When I run this batch file it works perfectly, copying my file from s3 and downloading it to my specified directory. (I have run AWS configure already to store my keys in the .../user/.aws/config file).
When I try to run the batch file from R with system("awsCopy.bat"), however, the command completes with status 1, does not copy the file and I get the following message:
Unable to locate credentials
Completed 1 part(s) with ... file(s) remaining
I've tried adding set commands in the batch file to no avail:
set aws_access_key_id = xxxxxxx
set aws_secret_access_key = yyyyyy
Has anyone else had (and solved) this issue? (I'm running windows 7) Thanks.
According to the system documentation (on a language I have no idea what it is) on Windows, System does NOT invoke the shell (unlike Unix). It says to use the shell command.
Or in other languages we could use your system call like so (but the docs say use System2 call as it's easier)
cmd /c "c:\somedfolder\batch.bat
I finally figured out the issue. I was executing this script from a network drive, but my credentials were set up only on my local machine. (I guess the setting the keys was just re-setting them locally.) Saving "awsCopy.bat" locally does the trick. Running system, shell and system2 on the batch file path all work.

Batch file doesn't execute specified .exe on remote computer

I am trying to install a program on a remote computer using a command line argument and a batch script. For testing, I'm installing Notepad++ as the program.
Here is the command line I'm using to access the remote computer:
psexec \\comp-2 -h -u localAdmin -p password -c -f C:\install-npp.bat
This is the batch file code I've written:
#echo off
#echo Hello this creates a pointless temp file >C:\temp\EmptyFile.txt
xcopy \\FILESVR\Shared\npp.exe C:\temp\npp.exe
start C:\temp\npp.exe
pause
(Please note: the second line is only to make sure that the script is in fact doing something).
When I run the psexec command listed above from my first computer, the EmptyFile.txt is created, and npp.exe is copied over to the temp directory, but the executable is never run.
What am i doing wrong? the machines are in a windows workgroup.
Thanks in advance!
the start command is waiting a title as first argument so try start "" c:\temp\npp.exe.
BTW looking at http://coreworx.blogspot.fr/2010/07/unattended-installation-notepad.html I saw you will have to add /S to make a silent install of npp

Resources