Script for mappings doesn't work on Win7?
-
15. března 2012 11:08
Hello,
I have a Domain managed by Windows 2003R2 SP2 servers with Windows XP SP3 Pro workstations.
I use the script "RenUse.bat" (copy below) via GPO to map the network drives required for each user, and it works fine.
I just added new stations Windows 7 Ultimate (32bits) to the Domain, and and the mappings do not appear.
Could you help me fix this problem?
"RenUse.bat" script
@echo off setlocal if {%3}=={} @echo Syntax: RenUse Name Drive: Server\Share [Options] &goto done if not "%OS%"=="Windows_NT" goto W9x set arg=%1 set arg=%arg:"=% set drive=%2 set drivel=%drive:~0,1% if "%drivel%:" NEQ "%drive%" @echo Syntax: RenUse Name Drive: Server\Share [Options] &goto done for /f "Tokens=5,6 Delims=[. " %%i in ('ver') do @set osv=%%i.%%j if "%osv:~0,3%" LSS "5.0" goto w9x if "%osv:~0,3%" GTR "5.0" goto wxp set uni=!21#23$24'27(28)29*2A+2B,2C-2D.2E/2F030131232333434535636737838939?3F@40A41B42C43D44E45F46G47H48I49J4AK4BL4CM4DN4EO4FP50Q51R52S53T54U55V56W57X58Y59Z5A[5B\5C]5D_5F`60a61b62c63d64e65f66g67h68i69j6Ak6Bl6Cm6Dn6Eo6Fp70q71r72s73t74u75v76w77x78y79z7A{7B}7D~20~20 set cachefill=000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000## set cache= set /a cachecnt=0 if exist %drive% net use %drive% /D>nul 2>&1 net use %drive% %3 %4 %5 %6 %7 %8>nul 2>&1 set arg=%arg: =~% set file=%TEMP%\Renuse.tmp set file="%file:"=%" if exist %file% del /q %file% for /l %%i in (0,3,249) do call :build %%i set /a cnt=0 goto :parse :build for /f "Tokens=*" %%j in ('@echo %%uni:~%1^,3%%') do @echo %%j>>%file% goto :EOF :parse for /f "Tokens=*" %%n in ('@echo %%arg:~%cnt%^,1%%') do set char=%%n if "%char%" EQU "ECHO is on." goto end set /a cnt=%cnt% + 1 for /f "Tokens=*" %%t in ('findstr /B /L /C:%char% %file%') do set unit="%%t" if %unit% EQU "" set unit="~20" set cache=%cache%%unit:~2,2%00 set /a cachecnt=%cachecnt% + 4 set cachefill=%cachefill:0000##=##% if %cachecnt% GEQ 128 goto end goto parse :wxp if exist %drive% net use %drive% /D>nul 2>&1 set key=%3 set key=HKCU\Software\Microsoft\Windows\CurrentVersion\Explorer\MountPoints2\%key:\=#% reg ADD %key% /v _LabelFromReg /d "%arg%" /f>nul 2>&1 :wxpqry reg QUERY %key% /v _LabelFromReg>nul 2>&1 if %ERRORLEVEL% EQU 1 goto :wxpqry net use %drive% %3 %4 %5 %6 %7 %8>nul 2>&1 endlocal goto :EOF :w9x if exist %2 net use %2 /D>nul 2>&1 net use %2 %3 %4 %5 %6 %7 %8>nul 2>&1 endlocal goto :EOF :end set cachefill=%cachefill:##=% set cache=%cache%%cachefill% :query set key=HKCU\Software\Microsoft\Windows\CurrentVersion\Explorer\MountPoints\%drivel%\_LabelFromReg reg QUERY %key% /v Cache>nul 2>&1 if %ERRORLEVEL% EQU 1 goto :query reg QUERY %key% /v Version>nul 2>&1 if %ERRORLEVEL% EQU 1 goto :query reg ADD %key% /v Cache /t REG_BINARY /d %cache% /f>nul 2>&1 reg ADD %key% /v Version /t REG_DWORD /d 3 /f>nul 2>&1 :done Endlocal
Thank you,
Chris
- Upravený chrbar 15. března 2012 11:09
Všechny reakce
-
15. března 2012 11:30Do you have UAC enabled on Windows 7 machines. If you do try to disable that and run the script, I would presume that UAC prevents the script from making registry changes.
-
15. března 2012 14:47Moderátor
Hi,
That script is very difficult to decipher. You need to pare it down to the bare minimum that fails. In addition, when you say that something didn't work, you have to say how it didn't work.
Bill
-
15. března 2012 14:59
Do you have UAC enabled on Windows 7 machines. If you do try to disable that and run the script, I would presume that UAC prevents the script from making registry changes.
UAC has nothing to do with login scripts and will not affect printer and drive mappings which never need elevation.
The issue is likely due to the async nature of the login script under Win7.
Under WS2008R2 domain it is much better to do drive and printer mappings with Group Policy preferences. They will apply to all OSs and work correctly on both XP and Win7.
The script that is posted does not do drive mappings but uses registry edits. This is very odd and not at all necessary. Just replace this with NET USE <drive> <share> /persistent:yes
The batch file was written for W95 and updated to work with NT4.
On Win 7 these lines will fail:
for /f "Tokens=5,6 Delims=[. " %i in ('ver') do @set osv=%i.%j
if "%osv:~0,3%" LSS "5.0" goto w9x
if "%osv:~0,3%" GTR "5.0" goto wxp
The version woll not match anything and the updates added for XP will be skipped. I believe you need to use the XP code on Win7 as the old NT4 section will likely fail.
¯\_(ツ)_/¯
- Navržen jako odpověď Rich PrescottModerator 15. března 2012 23:11
- Upravený jrvMicrosoft Community Contributor 15. března 2012 23:38
- Označen jako odpověď Richard MuellerMVP, Moderator 22. března 2012 0:28
-
15. března 2012 15:19
The batch file was written for W95 and updated to work with NT4.
On WInc 7 these lines will fail:
for /f "Tokens=5,6 Delims=[. " %i in ('ver') do @set osv=%i.%j
if "%osv:~0,3%" LSS "5.0" goto w9x
if "%osv:~0,3%" GTR "5.0" goto wxp
The version will not match anything and the updates added for XP will be skipped. I believe you need to use the XP code on Win7 as the old NT4 section will likely fail.
I highly recommend setting up a GPO tied to only the Win7 machines and use preferences to map drives. It will be muxh easier and more maintainable.
¯\_(ツ)_/¯