简体   繁体   中英

Windows batch file to connect to share and execute app

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.

"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 (eg X:\\etc\\app.exe) rather than a UNC path (eg \\\\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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM