Leaked source code of windows server 2003
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

169 lines
5.4 KiB

  1. @echo off
  2. echo.
  3. echo.
  4. setlocal ENABLEDELAYEDEXPANSION ENABLEEXTENSIONS
  5. set AUTOLOGON=%SYSTEMDRIVE%\TOOLS\autologon.exe
  6. set CS=%SYSTEMROOT%\system32\cscript.exe /NOLOGO
  7. set FG=%SYSTEMROOT%\system32\findstr.exe /i
  8. set OSF=%SYSTEMDRIVE%\TOOLS\OpShellFolder.wsf
  9. set AAS=%SYSTEMDRIVE%\TOOLS\wsh.iexplore.dialog.input.wsf
  10. set SLEEP=%SYSTEMDRIVE%\TOOLS\sleep.exe
  11. set WMIC=%SYSTEMROOT%\system32\WBEM\wmic.exe /INTERACTIVE:OFF
  12. set DIAG=%SYSTEMDRIVE%\TOOLS\wsh.dialoger.wsf
  13. set BT_A=
  14. :: Box architecture
  15. set BT_B=%SYSTEMDRIVE%\TOOLS\muibvt.exe
  16. :: binary tol execute MUI BVT
  17. set BT_C=User Interface Pack
  18. :: MUI package name to prevent conflicts
  19. set BT_D=%USERDOMAIN%
  20. :: domain to refer the user from
  21. set BT_H=STARTUP
  22. :: home directory to follow up after reboot
  23. set BT_L=
  24. :: language to MUI install
  25. set BT_N=
  26. :: Build number
  27. set BT_P=
  28. :: password for the default install user
  29. set BT_O=%SYSTEMDRIVE%\BVT
  30. :: output log directory for MUI BVT
  31. set BT_R=
  32. :: registry path to exchange information with MUI BVT
  33. SET BT_T=Remote Desktop Users
  34. ::Group to allow the Terminal Service Client access to the MUI BVT machine
  35. set BT_U=
  36. :: MUI BVT user name
  37. set BT_V=HKLM
  38. :: registry hive to store the MUI BVT status info
  39. set BT_W=SYSTEM\CurrentControlSet\Control\Terminal Server\fDenyTSConnections
  40. :: registry path to switch the machine terminal client settings
  41. set DEBUG=0
  42. set INTERACTIVE=%1
  43. IF NOT "%INTERACTIVE%"=="0" set INTERACTIVE=1
  44. FOR /F %%. in ('%CS% %OSF% /op:MapFolder /Path:"%~DP0"') do (
  45. IF /I "%%."=="%BT_H%" set INTERACTIVE=0
  46. )
  47. FOR /F "skip=1 tokens=2" %%. in ('%WMIC% OS') do (
  48. IF /I NOT "BuildNumber"=="%%." SET BT_N=%%.
  49. )
  50. SET BT_A=%PROCESSOR_ARCHITECTURE%
  51. IF NOT DEFINED BT_A (
  52. FOR /F "skip=1 tokens=4" %%. in ('%WMIC% CPU') do (
  53. IF /I NOT "Caption"=="%%." SET BT_A=%%.
  54. )
  55. )
  56. IF /I "!BT_A!"=="x86" (
  57. set BT_I=\\NTDEV\release\main\misc\!BT_N!\mui\x86\cd1
  58. set BT_R=Software\Microsoft\MUIBVT
  59. )
  60. IF /I "!BT_A!"=="ia64" (
  61. set BT_R=SOFTWARE\Wow6432Node\Microsoft\MUIBVT
  62. set BT_I=\\NTDEV\release\main\misc\!BT_N!\mui\ia64\cd1
  63. )
  64. IF "!INTERACTIVE!"=="1" (
  65. echo Step 1. Define MUI BVT language, build number, arch, user and password...
  66. %WMIC% 1>NUL
  67. FOR /F "tokens=*" %%. in ('%WMIC% product get name^, IdentifyingNumber ^| %FG% /ic:"%BT_C%"') do (
  68. echo %%.
  69. %CS% %OSF% /op:cpl /comment:"Manually delete the previously installed MUI packages" /file:appwiz.cpl
  70. goto :eof
  71. )
  72. FOR /F "tokens=1,2,3" %%1 in ('%CS% %AAS% /showinput:LANG 2^>NUL') do (
  73. if NOT "%%2"=="=" echo "ERROR:" "%%2" & goto :EOF
  74. if "%%1"=="BT_U" set BT_U=%%3
  75. if "%%1"=="BT_P" set BT_P=%%3
  76. if "%%1"=="BT_L" set BT_L=%%3
  77. )
  78. FOR %%_ in (BT_P BT_U BT_L BT_N BT_I BT_O BT_R) do call :ALLTRIM %%_
  79. SET BT_B=!BT_B! !BT_L! !BT_O! !BT_I!
  80. rem The remote access user
  81. %CS% %OSF% /op:add2grp /user:!BT_U! /domain:!BT_D! /group:"%BT_T%"
  82. %CS% %OSF% /op:DeleteValue /hive:%BT_V% /path:"%BT_W%"
  83. FOR /F "tokens=*" %%. in ('net localgroup "%BT_T%" ^| %FG% \') do @echo %%.
  84. echo Step 2. Establish AutoLogon
  85. %CS% %OSF% /op:SetKey /path:"%BT_R%" /hive:%BT_V%
  86. %CS% %OSF% /user:!BT_U! /password:!BT_P! /domain:!BT_D! /op:autologon
  87. %AUTOLOGON% /MIGRATE /QUIET
  88. IF ERRORLEVEL 1 (
  89. echo !BT_P!|%AUTOLOGON% /set /username:!BT_D!\!BT_U!
  90. )
  91. echo Step 3. Reset startup folder reference to %%SELF%%
  92. FOR /F "tokens=*" %%. in ('%WMIC% startup get command^|%FG% %~nx0') do (
  93. call :CLEARSTARTUP
  94. )
  95. call %CS% %OSF% /op:CopyFileTo /path:Startup /file:%~dpnx0
  96. echo Step 4. Run !BT_B!
  97. PUSHD %~dp0
  98. md %BT_O% 1>NUL 2>NUL
  99. %SLEEP% 3
  100. ECHO ON
  101. call !BT_B!
  102. @ECHO OFF
  103. POPD
  104. echo Step 5. Finish
  105. call %CS% %DIAG%
  106. %SLEEP% 5
  107. goto :EOF
  108. )
  109. IF NOT "!INTERACTIVE!"=="1" (
  110. set FGA=
  111. FOR /F %%. in ('%CS% %OSF% /op:QueryValue /path:"%BT_R%\Status" /hive:%BT_V%') do @SET FGA=%%.
  112. IF "%DEBUG%"=="1" ( echo DEBUG: ^^!FGA^^! = !FGA! & %SLEEP% 5)
  113. IF "!FGA!"=="0" (
  114. echo Step 1. Clear the Autologon data
  115. call :CLEARLOGON
  116. %CS% %OSF% /op:ClearKey /path:"%BT_R%" /hive:%BT_V%
  117. call :CLEARSTARTUP
  118. echo Step 2. Finish
  119. %SLEEP% 5
  120. goto :EOF
  121. )
  122. )
  123. echo.
  124. goto :EOF
  125. :CLEARSTARTUP
  126. START /MIN CMD /C %SLEEP% 1 ^& %CS% %OSF% /op:DelFile /path:Startup /file:"%~nx0"
  127. GOTO :EOF
  128. :CLEARLOGON
  129. %AUTOLOGON% /DELETE /QUIET
  130. %CS% %OSF% /op:clean
  131. goto :EOF
  132. :ALLTRIM
  133. set .=%1
  134. FOR /F "tokens=*" %%. IN ('echo !%.%!') do set .=%%. & set %.%=!.: =!
  135. goto :EOF
  136. ENDLOCAL