0

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.

user3229528
  • 29
  • 1
  • 4
  • 8
  • Why do you think you need to substitute the computer name in each command? If the batch file is on each target machine, just use a local path, e.g. `psexec @c:\test.txt elevate C:\IE10fix.bat`. If it's on a single server, use the path to the server, e.g. `psexec @c:\test.txt elevate \\server\c$\IE10fix.bat`. – nobody Apr 09 '14 at 19:44
  • It doesn't work if you try to use a UNC path. I read somewhere else that this was a limitation of psexec. I was just having a brain fart through. Using a local path works just fine. Thanks! – user3229528 Apr 09 '14 at 20:12

2 Answers2

0

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

Aaron Ooi
  • 139
  • 1
  • 5
  • 15
  • That makes sense, but I have a specific reason for needing to use the local admin account for this specific task. Thanks for that information though, it will be useful in the future. – user3229528 Apr 11 '14 at 13:53
  • Try create a folder c:\test\IE10fix.bat and share this folder to 'everyone'. Then try: `psexec @c:\test.txt \\server\test\IE10fix.bat` – Aaron Ooi Apr 12 '14 at 06:40
0

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.