0

I have a batch file running on Windows 7 x86. I am trying to script a connection to a share and then once that is done to execute an app.

net use \\appserver001\mycompany.ptshare\OPS /user:geek xyz!@# /persistent:yes
echo %errorlevel%
if errorlevel 2 goto message
if errorlevel 1 goto message

start "" "\\appserver001\mycompany.ptshare\OPS\OPSapp.exe"
echo %errorlevel%
if errorlevel 2 goto message
if errorlevel 1 goto message

goto end

:message
cls
echo ERROR IN CONNECTING TO SERVER

:end

The NET USE connection is made as the command window says "The command completed successfully". Then when it reaches the line to execute the app I get a pop-up message "Invalid location for program!".

I swear I have done his before but cant figure out why it will not run my app.

sinDizzy
  • 1,300
  • 7
  • 28
  • 60

1 Answers1

1

"Invalid location for program!" sounds like an error message that could come from OPSapp.exe itself. You could verify that by opening Task Manager and checking whether OPSapp is listed in the Processes tab when the error pops. If that's not the case then you may ignore the rest of this post.

Some programs require to be launched from a drive-letter based path (e.g. X:\etc\app.exe) rather than a UNC path (e.g. \\srv\etc\app.exe). Such a program can check at startup the location where it's been started from, then pop an error message and exit if it's a UNC path, instead of the drive-letter based one it expects.

The workaround in such cases is to (temporarily) map a drive letter to the network share, then use it to launch the program. For example, in your case replace

start "" "\\appserver001\mycompany.ptshare\OPS\OPSapp.exe"

with

pushd "\\appserver001\mycompany.ptshare\OPS"
start "" "OPSapp.exe"

If this still doesn't work, then it's possible that OPSapp expects more than just a drive-letter based path, perhaps a particular directory structure someplace, or registry entries etc - in other words it may not be portable enough to be simply runnable by path.

dxiv
  • 16,984
  • 2
  • 27
  • 49
  • You may be right. I will check the source code as it's an app written in my department. The wierd thing is if I set the /D switch to give it the starting path, it works. I will report once I find out more info. – sinDizzy Dec 08 '15 at 00:53
  • 1
    It was the app itself. The developer was looking for where it was running from. Since it had no starting directory it assumed it was the sys drive or C:\ which he didn't want. After adding the starting directory in the sctipt, it all worked. – sinDizzy Dec 10 '15 at 16:29