network programming - Batch file over netwok path -
i have following batch script make life easier @ work.
here supposed work:
1- drag , drop file onto .bat
2- choose file's destination on "menu"
3- script copy's files destination folder
4- script executes remote procedure (that's psexec line)
5- script copy's result of remote procedure other folders.
and works fine... except "small" detail need help.
when try copy network location \10.250.39.116\d%... if haven't logged machine wont work.
i've been looking 'net use' command overcome this, i'm not sure if suits needs.
there total of 4 different machines need authenticate, dependent on choice of menu.
actual question:
can log in such machines batch, , avoid creating duplicate connections every time run script ? if so, how?
thank time! :)
i know paths have point same place :)
@echo off setlocal enabledelayedexpansion echo. echo ............................................... echo press 1, 2 or 3 select task, or 4 exit. echo ............................................... echo. echo 1 - compilar em qualidade echo 2 - compilar na hsdev echo 3 - compilar nas demos echo 4 - exit echo. set /p m=type 1, 2, 3, or 4 press enter: if %m%==1 goto :qual if %m%==2 goto :hsdev if %m%==3 goto :demo if %m%==4 goto eof :qual set "pathforms6=\\10.250.39.116\d$\glintthsias\glintths\compilador\fmb6i\gh\" set "pathforms10=\\10.250.39.116\d$\glintthsias\glintths\compilador\fmb10\gh\" set pathcompilador=\\10.250.39.116 -u administrator -p password1 cmd "/c d: & cd d:\glintthsias\glintths\compilador & gh_priv_10_02_forms.bat" set pathdestinopriv=\\10.250.39.116\d$\glintthsias\glintths\priv\gh set pathdestinopub=\\10.250.39.116\d$\glintthsias\glintths\pub\gh goto :processa goto eof :hsdev set "pathforms6=\\10.250.39.116\d$\glintthsias\glintths\compilador\fmb6i\gh\" set "pathforms10=\\10.250.39.116\d$\glintthsias\glintths\compilador\fmb10\gh\" set pathcompilador=\\10.250.39.116 -u administrator -p password1 cmd "/c d: & cd d:\glintthsias\glintths\compilador & gh_priv_10_02_forms.bat" set pathdestinopriv=\\10.250.39.116\d$\glintthsias\glintths\priv\gh set pathdestinopub=\\10.250.39.116\d$\glintthsias\glintths\pub\gh goto :processa goto eof :demo set "pathforms6=\\10.250.39.116\d$\glintthsias\glintths\compilador\fmb6i\gh\" set "pathforms10=\\10.250.39.116\d$\glintthsias\glintths\compilador\fmb10\gh\" set pathcompilador=\\10.250.39.116 -u administrator -p password1 cmd "/c d: & cd d:\glintthsias\glintths\compilador & gh_priv_10_02_forms.bat" set pathdestinopriv=\\10.250.39.116\d$\glintthsias\glintths\priv\gh set pathdestinopub=\\10.250.39.116\d$\glintthsias\glintths\pub\gh goto :processa goto eof :processa set argcount=0 %%x in (%*) ( set /a argcount+=1 set "argvec[!argcount!]=%%~nx" set "pathvec[!argcount!]=%%~dpx" ) rem echo number of processed arguments: %argcount% /l %%i in (1,1,%argcount%) ( echo vou compilar %%i - "!argvec[%%i]!" if exist %pathforms6%!argvec[%%i]!.* del /q %pathforms6%!argvec[%%i]!.* if exist %pathforms10%!argvec[%%i]!.* del /q %pathforms10%!argvec[%%i]!.* robocopy "!pathvec[%%i]!." %pathforms6% !argvec[%%i]!.fmb > nul ) c: cd c:\pstools psexec %pathcompilador% /l %%i in (1,1,%argcount%) ( if exist "%pathforms10%!argvec[%%i]!.fmx" ( xcopy %pathforms10%!argvec[%%i]!.fmx %pathdestinopriv% /y xcopy %pathforms10%!argvec[%%i]!.fmx %pathdestinopub% /y) ) pause
how testing have done net use
? try running twice @ command line. notice how output changes @ second running:
as can see, connection has been established, net use
output summary of connection rather creating duplicate connection.
if prefer, use conditional execution or errorlevel checking. using method, can avoid calling net use
until xcopy
fails, should first time. here's short example, illustrate mechanics:
@echo off setlocal ping -n 1 10.250.39.116 | find /i "ttl=" >nul || ( echo 10.250.39.116 offline. unable continue. press key exit. pause >nul goto :eof ) call :xcopy "%~1" "destination" echo press key exit. pause >nul net use \\10.250.39.116\d$ /delete >nul 2>nul goto :eof :xcopy <source> <dest_dir> xcopy /l "%~1" "%~2" 2>nul || ( net use \\10.250.39.116\d$ /user:username password >nul 2>nul xcopy /l "%~1" "%~2" ) goto :eof