0
我想做一個批處理文件,這將有助於在啓動時映射驅動器 基本上它會寫一個批處理文件到它運行的計算機的啓動文件夾。批處理文件,創建另一個批處理文件
@Echo Off
cls
title Set Network drive 1.0
color 0A
rem "rem" is a message that can only bee seeing when editing a batch file. It will not be includded when running a batch file.
rem =====saving log file to your desktop==========
set log="%USERPROFILE%\Desktop\Set Network Drive 1.0.log"
echo.>>%log%
echo Starting log at %date% %time%>>%log%
echo.>>%log%
rem ==================Detecting OS type===========================
echo.
echo =====================Detection OS type=================
echo =====================Detection OS type=================>>%log%
echo.
echo.>>%log%
color 0c
echo One second please.......
echo.
for /f "tokens=2 delims=:" %%a in ('systeminfo ^| find "OS Name"') do set OS_Name=%%a
for /f "tokens=* delims= " %%a in ("%OS_Name%") do set OS_Name=%%a
for /f "tokens=3 delims= " %%a in ("%OS_Name%") do set OS_Name=%%a
rem ===========Setting OS type to use as variable %variable%=====
if "%os_name%"=="XP" set verssion=xp
if "%os_name%"=="7" set version=7
if "%version%"=="XP" set desktop=xp
if "%version%"=="7" set desktop=7
cls
color 0A
echo.
echo Operating system detected.............. Windows %version%
echo Operating system detected.............. Windows %version% >>%log%
echo.>>%log%
rem ===============Gathering information=========================
echo ===============Drive information==============>>%log%
echo.
echo.>>%log%
set /p driveletter=Drive letter to assign to:
echo Drive Letter................................ %driveletter%>>%log%
echo.>>%log%
echo.
set /p IP=Ip address device:
echo IP address of remote device................. %IP%>>%log%
echo.>>%log%
echo.
set /p path=Path on remote machine:
echo Path on remote machine set to............... %path% >>%log%
echo.>>%log%
echo.
set /p Username=Username (will be viewable in the log file and batch file):
echo Username.................................... %username%>>%log%
echo.
echo.>>%log%
set /p pass=Password (will be viewable in the batch file):
echo Password.................................... **********>>%log%
echo. >>%log%
echo ============================================================>>%log%
echo.>>%
rem ====================================================================
rem ====Writing batch file to startup folder as Map %driveletter%.bat===
rem ========windows 7==================
:win7
set startup="C:\ProgramData\Microsoft\Windows\Start Menu\Programs\Startup\Map %driveletter%.bat"
pause
echo @echo off >>%startup%
echo title Mapping network drive %driveletter%:>>%startup%
echo color 0A>>%startup%
echo cls>>%startup%
echo echo.>>%startup%
echo echo Wating for connection to drive location.........>>%startup%
echo goto loop>>%startup%
echo.>>%startup%
echo :loop>>%startup%
echo.>>%startup%
echo echo Pinging %ip%.........>>%startup%
echo cd c:\windows\system32\>>%startup%
這是我在哪裏遇到問題。這個命令不會輸出到批處理文件的創建,並關閉該批處理文件
echo ping %ip% -n 1 | find "TTL">>%startup%
echo if not errorlevel 1 goto up>>%startup%
echo if errorlevel 1 goto loop>>%startup%
echo.>>%startup%
echo.>>%startup%
echo :up>>%startup%
echo cls>>%startup%
echo echo.>>%startup%
echo echo Device is up>>%startup%
echo echo.>>%startup%
echo echo Mapping drive......>>%startup%
echo c:\windows\system32\net use %driveletter%: \\%ip%\%path% %pass% /USER:%username% >>%startup%
echo if not errorlevel 1 goto up>>%startup%
echo if errorlevel 1 goto end>>%startup%
echo echo.>>%startup%
echo :end>>%startup%
echo echo Drive was mapped>>%startup%
echo echo.>>%startup%
rem ==========REMOVE THE FOLOWING LINE TO HAVE THE BATCH FILE GO AWAY WHEN COMPLETE======
echo pause>>%startup%
start notepad %log%
pause
不知道,也許是一個轉義字符問題http://www.robvanderwoude.com/escapechars.php –
'ping%ip%-n 1^|'<---需要用'^轉義管道的轉義' – foxidrive
是的,它做到了。謝謝。 – user3246197