'psexec remote computer name

I am mostly new to this kind of stuff and running into a problem I don't know how to solve. Basically, it's looking at test.txt and using the list of computer names inside it, and running the batch file on each of them. If I could figure out a way to plug in the remote computer name I would be good to go but I don't know how to do that. I have researched a bit and saw that some people say you can use %COMPUTERNAME^% with the ^ giving it the ability to return the remote computer name rather than the one I'm running the command from. This works if I do something like:

psexec @c:\test.txt cmd /c echo %COMPUTERNAME^%

However, if I try to use that in the path of the file I want to run it does not work and just tries to use "%COMPUTERNAME%" as the actual name instead of resolving it. Here is the command I'm trying to use:

psexec @c:\test.txt elevate \\%COMPUTERNAME%\c$\IE10fix.bat

I'm trying to run this batch file on a long list of computer names, and it must be run as local administrator which is why I'm using elevate. If anyone can provide a solution to the remote computer name issue, or even another approach all together I would be very thankful.



Solution 1:[1]

You should use a network administrator account instead of using Local account if you are trying to execute UNC path executable.

psexec @c:\test.txt -u domain\username \\server\c$\IE10fix.bat

The reason UNC path failed because the local account do not have permission to the network resources

Solution 2:[2]

You could also just use the system account to bypass restrictions but as far as the path you can just point to where the script is being run from instead of coping to the local computer then trying to run from there.

psexec @c:\test.txt -s "%~DP0IE10fix.bat"

This pulls from the text and runs as system account (mostly used if you want it to be silent to the user) then runs IE10fix.bat from the location of the batch file your're executing. So you'll have to put the IE10fix.bat in the same location as the .bat running this command.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Aaron Ooi
Solution 2 user4802845