BatchPatch Forums Home › Forums › BatchPatch Support Forum › .bat Deployment – Exit Code 1 or 87
- This topic has 7 replies, 2 voices, and was last updated 4 years ago by doug.
-
AuthorPosts
-
October 26, 2020 at 6:37 am #12564mheimgarParticipant
Hello,
I’m trying to deploy a robocopy script within a batch file but there seems to be a problem with it. The content is as follows:
IF NOT EXIST "G:\Meine Ablage\" GOTO :CANCELLED robocopy \\server\Users\HomeDrives\%username% "G:\Meine Ablage\HomeDrive" /MIR /LOG:"\\server\__homeDriveJobs\%username%.log" GOTO :EXIT :CANCELLED echo Google Drive File Stream seems to be mapped to another drive letter >> "\\server\__homeDriveJobs\%username%-cancelled.log" :EXIT
When I deploy this without output log, I get an exit code 1. When output log is activated I get an exit code 87.
Deployment
* Cmd CopyHomeDriveToFileStream *
. . . . . . . . . .
FileToDeploy:: C:\batchpatch\appz\homeDriveCopy.bat
CopyEntireFolder:: FALSE
LeaveEntireFolder:: FALSE
RetrieveConsoleOutput:: FALSE
Command:: cmd.exe /c “homeDriveCopy.bat”
Parameters::
Deployment Output Log
Could not find file ‘\\client\C$\Program Files\BatchPatch\deployment\BatchPatchDeploymentOutput795518669.log’.All Messages
10/26 11:29:32> Deployment: Exit Code: 1
10/26 11:29:32> Deployment: Executing \\CLIENT -h -w “C:\Program Files\BatchPatch\deployment\temp” cmd.exe /c “C:\Program Files\BatchPatch\deployment\temp\homeDriveCopy.bat”
10/26 11:29:32> Deployment: Initiating execution…
10/26 11:29:31> Deployment: Copying file(s) to CLIENT …
10/26 11:29:31> Deployment: Queued file copy operation…
10/26 11:29:31> Deployment: Establishing connection…
10/26 11:29:31> Deployment: Queued…10/26 11:27:47> Deployment: Exit Code: 87
10/26 11:27:46> Deployment: Executing \\CLIENT -h -w “C:\Program Files\BatchPatch\deployment\temp” cmd.exe /c “C:\Program Files\BatchPatch\deployment\temp\hello.bat”
10/26 11:27:46> Deployment: Initiating execution…
10/26 11:27:46> Deployment: Copying file(s) to CLIENT …
10/26 11:27:46> Deployment: Queued file copy operation…
10/26 11:27:46> Deployment: Establishing connection…
10/26 11:27:45> Deployment: Queued…I can deploy it with SYSTEM execution context but then the %username% is filled with the hostname. All other user contexts result in the above errors.
Running the .bat locally is no problem.October 26, 2020 at 6:55 am #12565mheimgarParticipantThe main problem seems to be the UNC paths. When I set them to local paths, the deployment runs through. But as soon as I e.g. set the log path to the UNC path, I get the exit codes. Which I don’t understand because the batch jobs work fine when running them locally.
October 26, 2020 at 10:50 am #12567mheimgarParticipantIs batchpatch handling user credentials and UNC paths somehow different? Because the main problem seems to be that when I deploy the batch job, the %username% is correctly filled and the job is run but the network UNC path is not accessible:
——————————————————————————-
ROBOCOPY :: Robustes Dateikopieren fr Windows
——————————————————————————-Gestartet: Montag, 26. Oktober 2020 15:48:16
2020/10/26 15:48:16 FEHLER 5 (0x00000005) Dateisystemtyp der Quelle wird ermittelt \\server.local\Users\HomeDrives\adm_mycomp\
Zugriff verweigert (Access restricted)October 26, 2020 at 2:56 pm #12568dougModeratorAuthentication to a remote location can be different when going over two hops instead of one. So instead of making a single remote connection, you are effectively making a remote connection to the target computer and then asking it to make a remote connection to the network share, so it’s not an identical procedure. I would suggest you try a couple of things:
1. Try entering ‘Alternate credentials’ in BatchPatch (Actions > Specify alternate logon credentials). See if that makes a difference as compared to when you just use ‘integrated security’.
2. Maybe you can use the BatchPatch action “Copy file/folder” to accomplish your goal?
3. Maybe you can use a BatchPatch local command to accomplish your goal? In this case instead of running the script remotely, you could have a script that runs on the BatchPatch computer (Actions > Execute local process/command), and then there won’t be two hops of authentication, in case the two hops is what is causing the problem.
Also one more thing to note that I’m not sure if you are considering or not… the credentials that you are using to connect BatchPatch to the remote machine (whether that is with integrated security or with ‘alternate credentials’) is not necessarily the account name that you want to be inserted into %username% is it? Because the %username% variable will be the account that is running the script, which I suspect is not the account that you are wanting it to be, though I’m unsure because I don’t know the exact details of what you are trying to accomplish. I just figured I’d mention it here in case that helps at all.
Also, in cases where you use SYSTEM, I don’t think it will ever work properly because SYSTEM only has local privileges, so you would need to use ‘Elevated token’ I think to have a chance at it working properly.
-Doug
October 27, 2020 at 3:33 am #12575mheimgarParticipantThanks for your hints. But in the paragraph after your tips you stated the main problem: I’m trying to deploy a script that reads the currently logged on %username% and copy their network homedrive to another destination.
I found another forum topic, where it was sugessted to also have %username% available for scripts, additionally to %computer%. But I guess, this was never implemented? (which I don’t understand why, since it’s a vital functionality, to do something as the current user.)
So I guess what I want to do, simply won’t be possible with BatchPatch at all?
October 27, 2020 at 4:38 pm #12576dougModeratorFor what you are trying to accomplish… where you want the actual logged-on user to perform a task, I think the primary ways to do this are as follows:
1. If you want to use BatchPatch, then in BatchPatch you can get the list of users who are logged-on to the target computer by using ‘Actions > Get info > Get logged on users’. You could then manually take this information and input it into the ‘Notes’ column in BatchPatch in the format that you need/want it to be. And then you could send $notes as a parameter in your deployment configuration so that $notes gets passed into your script that runs on the target computer. In your script you could then handle the parameter in whatever way you want.
2. Instead of using BatchPatch for this task you could setup your script to run as an active directory logon script for the end-user so that when he/she logs on to the computer, the script runs in the context of his/her logon account.
3. Another option if you want to use BatchPatch is you could incorporate into your script the ability for the script to get the logged-on users directly with your own code, so that you could then use that information in your script to accomplish your end-goal. In this case you would either need to know for sure that there is only a single user who will ever be logged-on to the computer, or you would have to have logic that makes a determination for what to do when multiple logged-on users are detected. Furthermore, you would have to decide how you would obtain the list of logged-on users in the first place. There is not one set way to accomplish this task. Different methods have different advantages and disadvantages.
———————-
The idea that BatchPatch should have a %username% variable is not so straightforward as you imply. For one thing, there can be multiple users logged-on to a computer, so who is %username% in that case? Additionally, something like the $computer variable that BatchPatch currently supports along with $notes, $notes2, $description, $category, and $location… these are variables for use inside of BatchPatch … where these values exist or are inputted by you into the corresponding BatchPatch columns… such that you can then send them as parameters into your scripts/commands that you execute from/in BatchPatch. However, it’s very different for BatchPatch to see that you have used $username inside of a script that will be run remotely (or even just as a parameter sending into the command/script), and then have BatchPatch on-the-fly make a remote connection to the target computer, figure out the logged-on user, then insert that into your command (or modify your script and replace the value for you), and then execute your command/script remotely in a separate action. While this is theoretically possible to do, it’s a very customized kind of action, and it’s applicability would need to be tweaked on a per-use basis, depending on the specific need of the administrator for any particular given task. We try to make BatchPatch as flexible as possible for administrators to then be able to customize for their own needs, so that when they have particular tasks that they need to perform as part of their job, they can get something up and running with minimal effort. However, there are some tasks, such as what you are trying to accomplish, that don’t lend themselves well to having us pre-build in complete end-to-end functionality to accomplish due to the fact that they are quite specific… your exact need will not be identical to someone else’s exact need.
October 29, 2020 at 12:34 pm #12581mheimgarParticipantI see, thank you for the detailed explanation and suggestions!
October 29, 2020 at 12:40 pm #12582dougModeratorYou’re very welcome! 🙂
-
AuthorPosts
- You must be logged in to reply to this topic.