Can’t get .bat file to work

BatchPatch Forums Home Forums BatchPatch Support Forum Can’t get .bat file to work

Viewing 8 posts - 1 through 8 (of 8 total)
  • Author
    Posts
  • #14095
    etudenc
    Participant

    Hello – I’m new to BatchPatch and am hoping to get a little help.

    I’m trying to run a simple script (it works in a different application) and I suspect I’ve written it incorrectly or have left something vital out.

    My larger aim is to use BP to kick off software installations but for now I’m just trying to get familiar with how to start an app.

    Here are the details:
    The same user Administrator account is logged in for two PCs. The Target machines is running W11, the local machine is W10.
    I’m using “Deploy .msi…” to execute the script.
    The .bat script contents are as follows:

    cd /d "C:\Program Files\Google\Chrome\Application\"
    start chrome.exe

    In the Task Manager I see like 9 instances of Chrome (which is also the number when starting it locally from the Target computer). However, no Chrome window pops up, and the Taskbar icon doesn’t indicate it’s started. To my eye everything looks the same in the Task Manager.

    For the script I also tried

    cd /d "C:\Program Files\Google\Chrome\Application\"
    chrome.exe

    chrome.exe

    I’ve had success making some changes to the Registry and I see the file appear in the Target folder so I feel confident that BP is setup correctly.

    Thanks for any pointers!
    Phil

    #14096
    doug
    Moderator

    Everything is working as expected. Applications launched remotely will run hidden, not interactively, which is why you see the exe appear in Task Manager but the Chrome window does not appear to the logged-on user.

    #14097
    etudenc
    Participant

    Thanks for the quick reply!

    “…but the Chrome window does not appear to the logged-on user.”

    Even though the logged-on user is the same account as the one executing the script from BP?

    It sounds like I need to add something to the script to force the program to run interactively.

    #14098
    doug
    Moderator

    Interesting… so I just tested a bunch more options and was able to get it work. I’m glad you brought this up because I thought this was no longer possible. It used to work without anything special in the syntax, but starting with Win 10 it had stopped working like that. I discovered now that to get it work requires some extra care with the syntax.

    Ok so in the past we used to be able to just execute a BatchPatch ‘Remote command’ with the interactive flag enabled in PsExec with -i. However, now the correct session ID must also be specified for the remote user.

    In BatchPatch the ‘Remote Execution Context’ (under ‘Tools > Settings > Remote Execution Context’) can be set to either ‘SYSTEM’ or ‘Elevated token’ (I would recommend Elevated token for most uses), but in either case ‘Interactive’ must be UNchecked because the -i Interactive switch has to instead be added into the command directly.

    Then in a BatchPatch remote command you can use this syntax below where 2 is the session ID of the target user (you can see the correct session ID in Task Manager process details on the target computer by adding the Session ID column and then looking for the value next to one of the processes that is being executed by the logged-on user. In my test machine right now it’s 2, but it might be something different in your situation):

    -d -i 2 notepad

    -d -i 2 "C:\Program Files\Google\Chrome\Application\chrome.exe"

    =================================

    For a BatchPatch deployment action you would need to modify the “Command to execute” field directly and insert at the beginning of that field

    -i 2

    so that the entire field reads like this (with your own .bat filename and the correct session ID for your remote logged-on user:

    -i 2 cmd.exe /c "test.bat"

    #14099
    etudenc
    Participant

    Thank you again for looking into this and posting some solutions, very much appreciated!

    Unfortunately I was unable to get any of this to work, so now I’m concerned there may be a setup issue on my end, although as mentioned, I’ve successfully made registry changes and copied files, so I know it’s working to some degree.

    I ran chrome on the target machine – session ID is consistently 1. So in the “Deploy .msi…” section I pointed to the same script as above, adding “-i 1” to “cmd.exe /c “start_CHROME.cmd” and ran it. Unfortunately it doesn’t even start Chrome, though it returns an Exit Code of 0. “Interactive” has always been unchecked, the Remote Execution Context has always been set to Elevated.

    Likewise, in trying to send the command you posted via “Execute Remote Process/Command”
    -d -i 1 notepad.exe
    it briefly opens the Notepad process, no interactive window, and reports back random error codes each time I run it.

    If I remove the “-d” it also starts Notepad for a second but without errors. Still no interactivity.

    I’ll keep poking around, but thanks for your help!

    #14100
    etudenc
    Participant

    FWIW, I just discovered that by adding an “-s” to the Command Execute line so it reads
    -s -i 1 cmd.exe /c "start_CHROME.cmd
    it actually opens chrome for me, but as System (no surprise) and the icon in the taskbar is white.

    This also worked but takes much longer to execute
    -u USERNAME -p PASSWORD -i 1 cmd.exe /c "start_CHROME.cmd

    I don’t get why I’d have to provide the username/password when the local machine and target machine are both logged in with the same accountname/password, but at least perhaps I’m getting closer!

    EDIT: I restarted my local admin machine and all of the above still applies BUT now
    -u USERNAME -p PASSWORD -i 1 cmd.exe /c "start_CHROME.cmd
    opens Chrome immediately.

    #14104
    doug
    Moderator

    I wouldn’t be able to provide any further guidance. Your guess is as good as mine. What you’re trying to do is rather kludgy in the first place. I did see one example through Google searching of someone encountering the same or similar to what you’re describing, but just that one example with no solutions offered. The only thing I can think that might have an impact is the OS of the BP console computer as compared to the OS of the target. It might be that certain OS version/build combos between console and target could be the cause of the issues. Or maybe you have some type of HIPS/AV software on the target that is immediately shutting down the program that’s being executed?

    I’m curious why do you want to remotely start an app in the logged-on session? What purpose does this serve? Maybe it would be better served with a logon script that runs on the target computer at logon without having to be remotely triggered? Similarly you can put a shortcut in the Windows startup folder to trigger any app to start when the computer is logged-on. This is typically how this would be accomplished, and it’s how we do it here for one of our servers that needs to run some apps at logon. It’s unusual to need to do it remotely, and if you’re trying to do it on many computers simultaneously then you’ll also have the extra issue of which Session ID to use for each target computer since they presumably won’t all be the same Session ID.

    FYI:

    The -d tells PsExec to not wait for the process to end before returning. Without the -d then BatchPatch will remain ‘Executing…’ indefinitely until the app is closed on the target computer.

    The random exit codes that you’re seeing are normal… that’s what I see when I do it here and everything works properly. That seemingly random exit code is not an error code. It’s actually the PID (Process ID) of the remote process.

    As you know -s tells PsExec to run as SYSTEM. If you remove the -s from your command and then instead change the Remote Execution Context in BatchPatch to SYSTEM, then BatchPatch will insert the -s into the command for you automatically.

    Instead of using -u and -p directly in your command, if you specify alternate logon credentials for the row on BP (Actions > Specify alternate logon credentials), BP will insert the -u and -p with those credentials for you.

    #14113
    etudenc
    Participant

    I’m curious why do you want to remotely start an app in the logged-on session? What purpose does this serve?

    I teach 3D and have used Network Administrator for years to distribute scripts, install applications, update registries and occasionally open software so the students don’t have to wait. I am in the process of testing BP as a replacement for Network Admin. It was such an asset the other day when I needed to update a registry setting and couldn’t get it done with NA.

    Once again, thanks so much for all you’ve shared. Very informative and helpful!

Viewing 8 posts - 1 through 8 (of 8 total)
  • You must be logged in to reply to this topic.