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.

887 lines
24 KiB

  1. #---------------------------------------------------------------------
  2. package AutoBoottest;
  3. # Copyright (c) Microsoft Corporation. All rights reserved.
  4. #
  5. # Version: 1.00 (01/01/2002) : TSanders
  6. #
  7. # Purpose: Collection of tools used in autoboottest.pl
  8. #---------------------------------------------------------------------
  9. use vars qw($VERSION);
  10. $VERSION = '1.00';
  11. use lib $ENV{RAZZLETOOLPATH} . "\\PostBuildScripts";
  12. use lib $ENV{RAZZLETOOLPATH};
  13. use Logmsg;
  14. use Win32::OLE;
  15. use Win32::OLE::Enum;
  16. use strict;
  17. my $ABTShare = "ABTRelease";
  18. my $ABTWorkDir = "AutoBoottest";
  19. #---------------------------------------------------------------------
  20. # Copy - copy file to dest
  21. #
  22. # In: $file, $dest
  23. #
  24. #---------------------------------------------------------------------
  25. sub Copy($$)
  26. {
  27. my($file, $dest) = @_;
  28. if( `copy $file $dest` =~ /0 file/ )
  29. {
  30. errmsg("Couldn't copy $file to $dest");
  31. return 0;
  32. }
  33. return 1;
  34. }
  35. #---------------------------------------------------------------------
  36. # RebootAndWait - Shutdown $target & wait for it to reboot
  37. #
  38. # In: Machine, user, pass
  39. #
  40. #---------------------------------------------------------------------
  41. sub RebootAndWait($$$$)
  42. {
  43. my($target, $user, $pass) = @_;
  44. }
  45. #---------------------------------------------------------------------
  46. # WaitForTask - wait for scheduled task $name to start
  47. #
  48. # In: Machine, task name, timeout, user pass
  49. #
  50. #---------------------------------------------------------------------
  51. sub WaitForTask($$$)
  52. {
  53. my($target, $name, $timeout) = @_;
  54. my ($res, $time);
  55. $res = `schtasks /query /s $target`;
  56. if($res !~ /$name/){
  57. errmsg "Task: $name doesn't exist on $target";
  58. return 0;
  59. }
  60. if($res =~ /Could not start/){
  61. errmsg "Task: $name failed to start";
  62. return 0;
  63. }
  64. print("\nWaiting on task $name to start.");
  65. $time = $timeout;
  66. while($time--)
  67. {
  68. $res = `schtasks /query /s $target`;
  69. my($tm, $stat) = ( $res =~ /$name\s{1,40}(.{0,25})\s{2,25}(.*)/i );
  70. last if ($stat =~ /running/i);
  71. if($tm =~ /never/i){
  72. errmsg "Task: $name didn't schedule correctly";
  73. return 0;
  74. }
  75. if( $tm =~ /(.+):(.+):.+,.+/ ){
  76. my($s, $m, $h, $d) = localtime;
  77. if( $h >= $1 && $m >= $2 && ( $stat !~ /running/i ))
  78. {
  79. errmsg "Task: $name didn't start";
  80. return 0;
  81. }
  82. }
  83. print ".";
  84. sleep 1;
  85. }
  86. if(0 >= $time && $timeout > 0){
  87. print("timeout hit.\n");
  88. return 0;
  89. }
  90. #print("\nWating on task to complete.");
  91. #while($timeout--)
  92. #{
  93. # $res = `schtasks /query /s $target`;
  94. # last if ($res =~ /$name\s*never\s*running.*/i ||
  95. # $res =~ /$name\s*never\s*/i ||
  96. # (!($res =~ /$name/)));
  97. # #last if ($res =~ /$name/);
  98. # print ".";
  99. # sleep 1;
  100. #}
  101. print "\n";
  102. return 1;
  103. }
  104. #---------------------------------------------------------------------
  105. # WaitForProcess - wait for $processname to begin
  106. #
  107. # In: Machine, process name to wait on, timeout, user, pass
  108. # Note: timeout < 0 == infinity
  109. #---------------------------------------------------------------------
  110. sub WaitForProcess($$$$$)
  111. {
  112. my ($target, $procname, $timeout, $user, $pass) = @_;
  113. my (@res, $oADSIDom, $wbemLocator, $remote_services, $oServ, $res, $proc, $resultArray, $resultRef);
  114. my $Time = $timeout;
  115. defined($procname) or return 0;
  116. $wbemLocator = Win32::OLE->new('WbemScripting.SWbemLocator');
  117. (OLE_errmsg("Could not instatiate WbemScripting.SWbemLocator") && return 0 ) if ( !defined $wbemLocator );
  118. print("\nWaiting for process to begin: $procname.");
  119. while($Time--){
  120. eval{
  121. defined($user) ? $remote_services = $wbemLocator->ConnectServer( "$target", "root\\cimv2", $user, $pass ):
  122. $remote_services = $wbemLocator->ConnectServer("$target");
  123. $resultArray = $remote_services->ExecQuery("Select * From Win32_Process Where Name ='$procname'");
  124. $resultRef = [ (in $resultArray) ];
  125. last if( shift(@$resultRef));
  126. print ".";
  127. sleep 1;
  128. undef $remote_services;
  129. };
  130. if($@){
  131. print("x");
  132. sleep 1;
  133. undef $remote_services;
  134. }
  135. }
  136. undef $remote_services;
  137. undef $wbemLocator;
  138. if(0 >= $Time && $timeout > 0)
  139. {
  140. print("timeout hit.\n");
  141. return 0;
  142. }
  143. print("done\n");
  144. return 1;
  145. }
  146. #---------------------------------------------------------------------
  147. # WaitOnProcess - wait on $processname till it ends
  148. #
  149. # In: Machine, process name to wait on, user, pass
  150. #
  151. #---------------------------------------------------------------------
  152. sub WaitOnProcess($$$$$)
  153. {
  154. my ($target, $procname, $timeout, $user, $pass) = @_;
  155. my (@res, $oADSIDom, $wbemLocator, $remote_services, $oServ, $res, $proc, $resultArray, $resultRef);
  156. my $Time = $timeout;
  157. defined($procname) or return 0;
  158. $wbemLocator = Win32::OLE->new('WbemScripting.SWbemLocator');
  159. (OLE_errmsg("Could not instatiate WbemScripting.SWbemLocator") && return 0 ) if ( !defined $wbemLocator );
  160. defined($user) ? $remote_services = $wbemLocator->ConnectServer( "$target", "root\\cimv2", $user, $pass ):
  161. $remote_services = $wbemLocator->ConnectServer( "$target");
  162. (OLE_errmsg("Couldn't connect to $target") && return 0 ) if (!defined $remote_services);
  163. print("\nWaiting on process: $procname.");
  164. while($Time--){
  165. eval{
  166. $resultArray = $remote_services->ExecQuery("Select * From Win32_Process Where Name ='$procname'");
  167. last if( ! defined $resultArray );
  168. $resultRef = [ (in $resultArray) ];
  169. last if( ! shift(@$resultRef));
  170. print ".";
  171. sleep 2;
  172. };
  173. if($@){
  174. OLE_errmsg("Fatal error: $@");
  175. undef $remote_services;
  176. undef $wbemLocator;
  177. return 0;
  178. }
  179. }
  180. undef $remote_services;
  181. undef $wbemLocator;
  182. if(0 >= $Time && $timeout > 0)
  183. {
  184. print("timeout hit.\n");
  185. return 0;
  186. }
  187. print("done\n");
  188. return 1;
  189. }
  190. #---------------------------------------------------------------------
  191. # CreateUserShare - Create a temporary 'autoboottest' user & grant
  192. # read access to autoboottest share.
  193. #
  194. # In: User, target Machine, host machine, source to share, local tools share
  195. # Out: Password
  196. #
  197. #---------------------------------------------------------------------
  198. sub CreateUserShare($$$$$)
  199. {
  200. my ($sUser, $target, $host, $sShare, $sLocShare) = @_;
  201. my ($res, $Pass, $oNewUser, $oShare, $oADSIObj, $oADSIDom, $oNewUser, $oGroup);
  202. #Generate random pass
  203. $Pass = sprintf("%s%i%s", "!a", rand(10000), "a!");
  204. #DEBUGUG
  205. $Pass = "_Monday_";
  206. #If we're not dealing w/ a DFS source
  207. #if($sShare ne ""){
  208. #Create Boottest User on Target machine & Add to administrators
  209. $oADSIDom=Win32::OLE->GetObject("WinNT://$target");
  210. if (!defined $oADSIDom){
  211. OLE_errmsg("Can't connect to $target:");
  212. return 0;
  213. }
  214. if ($oNewUser = Win32::OLE->GetObject("WinNT://$target/$sUser")){
  215. logmsg("User $target\\$sUser already exists");
  216. $oNewUser->SetPassword($Pass);
  217. $oNewUser->SetInfo();
  218. undef $oNewUser;
  219. logmsg("Successfully updated pass for $target\\$sUser");
  220. }
  221. else{
  222. if ($oNewUser = $oADSIDom->Create("user",$sUser)) {
  223. $oNewUser->{FullName} = "Autoboottester";
  224. $oNewUser->{Description} = "Autoboottest account";
  225. $oNewUser->{PasswordExpired} = 0;
  226. $oNewUser->SetInfo();
  227. $oNewUser->SetPassword($Pass);
  228. $oNewUser->SetInfo();
  229. undef $oNewUser;
  230. logmsg ("Successfully created $target\\$sUser");
  231. }
  232. }
  233. $oGroup = Win32::OLE->GetObject("WinNT://$target/Administrators");
  234. OLE_errmsg("Can't get Administators group") if(!defined $oGroup);
  235. if($oGroup->Add("WinNT://$target/$sUser")){
  236. if(Win32::OLE->LastError() =~ /is already a/i){
  237. logmsg("$target\\$sUser is already a member of the Administrators group");
  238. }else{
  239. OLE_errmsg("Couldn't add $target\\$sUser to Administrators group");
  240. return 0;
  241. }
  242. }
  243. undef $oGroup;
  244. undef $oADSIDom;
  245. #}
  246. #Now create local user for Boottest dir
  247. $oADSIDom=Win32::OLE->GetObject("WinNT://$host");
  248. if (!defined $oADSIDom){
  249. OLE_errmsg("Can't connect to $host:");
  250. return 0;
  251. }
  252. if ($oNewUser = Win32::OLE->GetObject("WinNT://$host/$sUser")){
  253. logmsg("User $host\\$sUser already exists");
  254. $oNewUser->SetPassword($Pass);
  255. $oNewUser->SetInfo();
  256. undef $oNewUser;
  257. logmsg("Successfully updated pass for $target\\$sUser");
  258. }
  259. else{
  260. if ($oNewUser = $oADSIDom->Create("user",$sUser)) {
  261. $oNewUser->{FullName} = "Autoboottester";
  262. $oNewUser->{Description} = "Autoboottest account";
  263. $oNewUser->{PasswordExpired} = 0;
  264. $oNewUser->SetInfo();
  265. $oNewUser->SetPassword($Pass);
  266. $oNewUser->SetInfo();
  267. undef $oNewUser;
  268. logmsg ("Successfully created $host\\$sUser");
  269. }
  270. }
  271. undef $oADSIDom;
  272. #Grant read access to release share if not DFS share
  273. if($sShare ne ""){
  274. $res = `rmtshare \\\\$host\\release /GRANT $sUser:r`;
  275. if($res =~ /error|failed/i) {
  276. errmsg("Couldn't grant access to \\\\$host\\release for $sUser: $res");
  277. return 0;
  278. }
  279. logmsg("User $sUser successfully granted read access");
  280. }
  281. #Create local tools share
  282. $res = `rmtshare \\\\$host\\Boottest=$sLocShare`;
  283. if($res =~ /error|failed/i) {
  284. if($res =~ /2118/){
  285. logmsg("\\\\$host\\Boottest already exists");
  286. }else{
  287. errmsg("Couldn't create share \\\\$host\\Boottest: $res");
  288. return 0;
  289. }
  290. }
  291. $res = `rmtshare \\\\$host\\Boottest /GRANT $sUser:r`;
  292. if($res =~ /error|failed/i) {
  293. errmsg("Couldn't grant access to \\\\$host\\Boottest for $sUser: $res");
  294. return 0;
  295. }
  296. `rmtshare \\\\$host\\Boottest /remove everyone`;
  297. logmsg("Successfully created \\\\$host\\Boottest");
  298. return $Pass;
  299. }
  300. #---------------------------------------------------------------------
  301. # CleanupUserShare - Delete user & remove autoboottest share.
  302. #
  303. # In: User, Machine, source to share
  304. #
  305. #---------------------------------------------------------------------
  306. sub CleanupUserShare($$$$$)
  307. {
  308. #NEED TO WORK ON THIS!!!###
  309. my ($sUser, $sDomain, $sShare, $sLocShare, $target) = @_;
  310. my ($res, $oADSIDom);
  311. #Remove access to release & tools shares
  312. $res = `rmtshare \\\\$sDomain\\$sShare /grant $sUser:`;
  313. if($res =~ /error|failed/i) {
  314. errmsg("Couldn't deny access for $sUser to share \\\\$sDomain\\$sShare: $res");
  315. return -1;
  316. }
  317. logmsg("Successfully removed access for $sUser to \\\\$sDomain\\$sShare");
  318. $res = `rmtshare \\\\$sDomain\\$sLocShare /grant $sUser:`;
  319. if($res =~ /error|failed/i) {
  320. errmsg("Couldn't deny access for $sUser to share $sLocShare: $res");
  321. return -1;
  322. }
  323. logmsg("Successfully removed access for $sUser to $sLocShare");
  324. #Delete User
  325. $oADSIDom=Win32::OLE->GetObject("WinNT://$sDomain");
  326. OLE_errmsg("Can't connect to $sDomain:") if (!defined $oADSIDom);
  327. if(!Win32::OLE->GetObject("WinNT://$sDomain/$sUser")){
  328. OLE_errmsg("User $sUser doesn't exist");
  329. }
  330. else{
  331. $oADSIDom->Delete("user",$sUser);
  332. logmsg ("Successfully deleted $sDomain\\$sUser");
  333. }
  334. if(!Win32::OLE->GetObject("WinNT://$target/$sUser")){
  335. OLE_errmsg("User $sUser doesn't exist");
  336. }
  337. else{
  338. $oADSIDom->Delete("user",$sUser);
  339. logmsg ("Successfully deleted $target\\$sUser");
  340. }
  341. #Delete temp dir
  342. logmsg ("removing $sLocShare dir");
  343. print `rd /s /q $sLocShare`;
  344. #Clean any residual connections
  345. for my $i (`net use`){
  346. ($i =~ /\w*\s*(\\\\$target\\\w*\$+).*/) &&
  347. `net use $1 /delete /y 2>&1`;
  348. }
  349. return 1;
  350. }
  351. #---------------------------------------------------------------------
  352. # EncryptPK - Wrap NTBCrypt.exe for encrypting ProductKeys
  353. #
  354. # In: ProductKey
  355. #
  356. #---------------------------------------------------------------------
  357. sub EncryptPK
  358. {
  359. my ($sData, $bLabKey) = @_;
  360. my ($res, $sUser, $sPKout);
  361. $res = `where NTCrypt.exe`;
  362. if($res =~ /Could not/){
  363. errmsg("NTCrypt.exe is necessary") && exit(1);
  364. }
  365. if($sData eq ""){
  366. errmsg("Usage: EncryptPK(<PID>, <bLabKey>)");
  367. return 0;
  368. }
  369. $sUser = lc($ENV{'USERNAME'});
  370. errmsg("Invalid data") if($sData !~ /\W+/);
  371. $sPKout = (defined($bLabKey) ? $sUser."LAB.epk"
  372. : "$sUser.epk");
  373. mkdir($ABTWorkDir) if(! (-e $ABTWorkDir));
  374. $res = `NTCrypt.exe -e \"$sData\" -t:$ABTWorkDir\\$sPKout`;
  375. if($res =~ /error/i ){
  376. errmsg("Couldn't encrypt key: $res");
  377. return -1;
  378. }
  379. else {
  380. logmsg("Successfuly created key file: $ABTWorkDir\\$sPKout");
  381. }
  382. return 1;
  383. }
  384. #---------------------------------------------------------------------
  385. # GetPK -
  386. #
  387. # Out: ProductKey
  388. #
  389. #---------------------------------------------------------------------
  390. sub GetPK
  391. {
  392. my ($bLabKey) = @_;
  393. my ($res, $sUser, $sPK) = "";
  394. $sUser = lc($ENV{'USERNAME'});
  395. $sPK = (defined($bLabKey) ? $sUser."LAB.epk"
  396. : "$sUser.epk");
  397. if(-e "$ABTWorkDir\\$sPK"){
  398. $res = `NTCrypt.exe -r -t:$ABTWorkDir\\$sPK`;
  399. if($res =~ /error/i ){
  400. errmsg("Couldn't decrypt key file: $ABTWorkDir\\$sPK");
  401. return -1;
  402. }
  403. else {
  404. logmsg("Successfuly decrypted key file: $ABTWorkDir\\$sPK");
  405. }
  406. }
  407. else{
  408. errmsg("Couldn't find encrypted product key file. Run AutoBoottest::EncryptPK() to create an encrypted product key file");
  409. #print "Enter ProductKey: ";
  410. #$res = <STDIN>;
  411. #print "\n";
  412. #chomp($res);
  413. }
  414. return $res;
  415. }
  416. #---------------------------------------------------------------------
  417. # VerifyBT - Verify the boottestmachine meets the following criteria:
  418. # 1) test for WMI access
  419. # 2) current or specified user has admin access
  420. # 3) BTM has a second partion w/ space > 2BG to install test build
  421. #
  422. # In: Target
  423. #
  424. #---------------------------------------------------------------------
  425. sub VerifyBT($)
  426. {
  427. my ($sTarget) = @_;
  428. my (@res, $oADSIDom, $wbemLocator, $remote_wbem_services);
  429. @res = ();
  430. #check for ADSI access
  431. $oADSIDom=Win32::OLE->GetObject("WinNT://$sTarget");
  432. push(@res, Get_OLE_errmsg("Failed to access \\\\$sTarget via ADSI:")) if (!defined $oADSIDom);
  433. undef $oADSIDom;
  434. #check for WMI access
  435. $wbemLocator = Win32::OLE->new('WbemScripting.SWbemLocator');
  436. if(!defined($wbemLocator)){
  437. push(@res, Get_OLE_errmsg("Could not instatiate WbemScripting.SWbemLocator"));
  438. }else{
  439. $remote_wbem_services = $wbemLocator->ConnectServer( $sTarget );
  440. push(@res, Get_OLE_errmsg("Failed to access \\\\$sTarget via WMI:")) if (!defined $remote_wbem_services);
  441. }
  442. if(@res){
  443. undef $remote_wbem_services;
  444. undef $wbemLocator;
  445. errmsg("The following steps failed when verifing the boottest machine:");
  446. for my $i (@res) { errmsg($i);}
  447. return 0;
  448. }
  449. #Check partitioning scheme
  450. if(defined($remote_wbem_services)){
  451. my ($c, $d, $dspace, $drive) = 0;
  452. my $ResultArray = $remote_wbem_services->ExecQuery("Select * From Win32_LogicalDisk Where DriveType=3");
  453. my $ResultArrayRef = [(in $ResultArray)];
  454. while($drive = shift @$ResultArrayRef){
  455. if($drive->{DriveType} == 3)
  456. {
  457. $c = 1 if($drive->{Name} =~ /c/i);
  458. if($drive->{Name} =~ /d/i)
  459. {
  460. $d = 1;
  461. $dspace = 1 if($drive->{FreeSpace} > 2097152); #what should this val be ?
  462. }
  463. }
  464. }
  465. push(@res, "\\\\$sTarget drives aren't correctly configured.") if(!($c && $d && $dspace));
  466. }
  467. else{
  468. push(@res, "Unable to verify partitioning scheme on \\\\$sTarget");
  469. }
  470. #Make sure we're in the safe build
  471. #my($remProc, $res);
  472. #$remProc = $remote_wbem_services->InstancesOf('Win32_BootConfiguration') || push(@res, "Couldn't get a Win32_BootConfiguration");
  473. #if($remProc->{BootDirectory} !~ /c:\\/i){
  474. # push(@res, "Not in safe build");
  475. #Verify services are running on target, if not start
  476. my @tres = AutoBoottest::QueryTarget($sTarget, "Win32_Service", "Schedule", "", "");
  477. if(((!(grep {/State=Running/} @tres)) &&
  478. !AutoBoottest::StartService($sTarget, "Schedule", "","")))
  479. {
  480. push(@res, "Task Scheduler service isn't running on $sTarget.
  481. Enable service through mmc->Services");
  482. }
  483. undef $remote_wbem_services;
  484. undef $wbemLocator;
  485. if(@res){
  486. errmsg("The following steps failed:");
  487. for my $i (@res) { errmsg($i);}
  488. return 0;
  489. }
  490. logmsg("\\\\$sTarget correctly configured.");
  491. return 1;
  492. }
  493. #---------------------------------------------------------------------
  494. # StartService - start a service on a remote machine
  495. #
  496. # In: target machine, service name, [user, pass]
  497. #---------------------------------------------------------------------
  498. sub StartService
  499. {
  500. my ($target, $service, $user, $pass) = @_;
  501. my (@res, $oADSIDom, $wbemLocator, $remote_services, $oServ, $res, $srvc, $resultArray, $resultRef);
  502. defined($service) or return -1;
  503. $wbemLocator = Win32::OLE->new('WbemScripting.SWbemLocator');
  504. (OLE_errmsg("Could not instatiate WbemScripting.SWbemLocator") && return 0 ) if ( !defined $wbemLocator );
  505. defined($user) ? $remote_services = $wbemLocator->ConnectServer( "$target", "root\\cimv2", $user, $pass ):
  506. $remote_services = $wbemLocator->ConnectServer( "$target");
  507. (OLE_errmsg("Couldn't connect to $target") && return 0 ) if (!defined $remote_services);
  508. $resultArray = $remote_services->ExecQuery("Select * From Win32_Service Where Name ='$service'");
  509. $resultRef = [(in $resultArray)];
  510. while ($srvc = shift @$resultRef)
  511. {
  512. logmsg "Starting service: $srvc->{Name}";
  513. $srvc->ChangeStartMode("Manual") if ($srvc->{StartMode} eq "Disabled");
  514. if($srvc->{State} eq "Stopped")
  515. {
  516. $res = $srvc->StartService();
  517. ($res) ? errmsg("$srvc->{Name} could not start: $res") :
  518. logmsg("$srvc->{Name} started.");
  519. return 1;
  520. }
  521. else
  522. {
  523. logmsg("$srvc->{Name} is already running");
  524. return 1;
  525. }
  526. }
  527. undef $remote_services;
  528. undef $wbemLocator;
  529. errmsg("Service $service not found on $target");
  530. return 0;
  531. }
  532. #---------------------------------------------------------------------
  533. # QueryTarget - query WMI provider on a remote machine
  534. #
  535. # In: target machine, service name, [user, pass]
  536. #---------------------------------------------------------------------
  537. sub QueryTarget
  538. {
  539. my ($target, $service, $name, $user, $pass) = @_;
  540. my (@res, $oADSIDom, $wbemLocator, $remote_services, $oServ, $res, $srvc, $resultArray, $resultRef);
  541. defined($service) or return -1;
  542. $wbemLocator = Win32::OLE->new('WbemScripting.SWbemLocator');
  543. (OLE_errmsg("Could not instatiate WbemScripting.SWbemLocator") && return 0 ) if ( !defined $wbemLocator );
  544. defined($user) ? $remote_services = $wbemLocator->ConnectServer( "$target", "root\\cimv2", $user, $pass ):
  545. $remote_services = $wbemLocator->ConnectServer( "$target");
  546. (OLE_errmsg("Couldn't connect to $target") && return 0 ) if (!defined $remote_services);
  547. $resultArray = $remote_services->ExecQuery("Select * From $service Where Name='$name'");
  548. $resultRef = [(in $resultArray)];
  549. undef $remote_services;
  550. undef $wbemLocator;
  551. while ($srvc = shift @$resultRef)
  552. {
  553. logmsg("$service - $name is available");
  554. return 1;
  555. }
  556. errmsg("$service $name not found on $target");
  557. return 0;
  558. }
  559. #---------------------------------------------------------------------
  560. # WriteUnattendFile - Generate Unattend File
  561. #
  562. # In: target, out file, lang, pid, [username, password]
  563. # Out: success = 1, fail = 0
  564. #---------------------------------------------------------------------
  565. sub WriteUnattendFile {
  566. my($target, $OutFile, $lang, $pid, $user, $pass) = @_;
  567. my(@Identification, $computername);
  568. my $Administrators = ($lang =~ /ger/i) ?
  569. "Administratoren" :
  570. "Administrators";
  571. if($user){
  572. #if($pass =~ /\*/){
  573. # $pass = comlib::GetPassword($username);
  574. #}
  575. @Identification = ( "[Identification]\n",
  576. "JoinDomain=NTDEV\n",
  577. "DomainAdmin=$user\n",
  578. "DomainAdminPassword=$pass\n",
  579. "CreateComputerAccountInDomain = Yes\n\n");
  580. }
  581. !$OutFile && ($OutFile = "unattend.txt");
  582. !$target && errmsg( "Must specify target." ) && return 0;
  583. !$pid && errmsg( "Must specify pid.") && return 0;
  584. $computername = $target."1";
  585. open(of, ">$OutFile") || die "Can't open $OutFile for writing";
  586. print of <<UnattendFile;
  587. [data]
  588. Unattendedinstall=yes
  589. msdosinitiated="0"
  590. [Unattended]
  591. UnattendMode = fullUnattended
  592. OemSkipEula = yes
  593. TargetPath=test
  594. Filesystem=LeaveAlone
  595. NtUpgrade=no
  596. ConfirmHardware = No
  597. Repartition = No
  598. [branding]
  599. brandieusingunattended = yes
  600. [Proxy]
  601. Proxy_Enable = 1
  602. Use_Same_Proxy = 1
  603. HTTP_Proxy_Server = http://itgproxy:80
  604. Secure_Proxy_Server = http://itgproxy:80
  605. [GuiUnattended]
  606. AutoLogon =Yes
  607. AutoLogonCount = 1
  608. TimeZone=04
  609. AdminPassword=password
  610. oemskipregional = 1
  611. oemskipwelcome = 1
  612. [UserData]
  613. FullName="$ENV{"_BuildBranch"}"
  614. OrgName="Microsoft"
  615. ComputerName=$computername
  616. ProductID=$pid
  617. [LicenseFilePrintData]
  618. AutoMode = "PerServer"
  619. AutoUsers = "50"
  620. [Display]
  621. BitsPerPel=0x10
  622. XResolution=0x400
  623. YResolution=0x300
  624. VRefresh=0x3C
  625. Flags=0x0
  626. AutoConfirm=0x1
  627. [RegionalSettings]
  628. LanguageGroup = 1, 7, 8, 9, 10, 11, 12, 13
  629. SystemLocal = 00000409
  630. UserLocal = 00000409
  631. [Terminalservices]
  632. Allowconnections = 1
  633. [Networking]
  634. InstallDefaultComponents=Yes
  635. @Identification
  636. [SetupData]
  637. OsLoadOptionsVar="/fastdetect /debug /baudrate=115200"
  638. [GuiRunOnce]
  639. #command0: Create the SAFE reboot shortcut
  640. command0="\%SYSTEMROOT\%\\SYSTEM32\\cscript.exe \%SYSTEMDRIVE\%\\TOOLS\\addlink.wsf -x:'\%SYSTEMROOT\%\\SYSTEM32\\cscript.exe \%SYSTEMDRIVE\%\\TOOLS\\bootsafe.wsf' -i:13"
  641. UnattendFile
  642. #end of main Unattend.txt
  643. #begin post BT stuff
  644. print of <<BVT if $lang !~ /usa/i;
  645. ; command1: Create the BVT shortcut
  646. command1="\%SYSTEMROOT\%\\SYSTEM32\\cscript.exe \%SYSTEMDRIVE\%\\TOOLS\\addlink.wsf -x:\%SYSTEMDRIVE\%\\TOOLS\\bvtm.cmd -l:'BVT Test.lnk'"
  647. ; command2: Add the winbld to ADMINISTRATORS
  648. command2="\%SYSTEMROOT\%\\SYSTEM32\\cscript.exe \%SYSTEMDRIVE\%\\TOOLS\\add2grp.wsf /u:'winbld' /d /g:$Administrators"
  649. ; command3: Clean the unattend* files
  650. command3="\%SYSTEMROOT\%\\SYSTEM32\\cmd.exe /c del /q \%SYSTEMDRIVE\%\\TOOLS\\unattend.*"
  651. ; command4: add the REGISTRY entries for automatic logon of the winbld
  652. ; command4="\%SYSTEMROOT\%\\SYSTEM32\\cscript.exe \%SYSTEMDRIVE\%\\TOOLS\\fixlogon.wsf /u:winbld /y:NTDEV /p:$pass"
  653. ; command5: reboot the machine. use traditional way.
  654. ; command5="\%SYSTEMROOT\%\\SYSTEM32\\shutdown.exe -r -t 0"
  655. ; command6: Do the cleanup and indirect cleanup.Not yet implemented.
  656. BVT
  657. #end post BT stuff
  658. close(of);
  659. logmsg("Successfully created unattend file: $OutFile");
  660. return 1;
  661. }
  662. #---------------------------------------------------------------------
  663. # GetCommand - extract executable from command string
  664. #
  665. # In: command string
  666. # Algorithm - take string up to first <whitespace> or <switch> where <switch> is '/' or '-'
  667. #
  668. #---------------------------------------------------------------------
  669. sub GetCommand($)
  670. {
  671. my ($txt) = @_;
  672. $txt =~ /(.*)\/|-| /;
  673. return $1;
  674. }
  675. #---------------------------------------------------------------------
  676. # GetPassword - eventually get a masked password
  677. #
  678. # In: item to get password for
  679. #
  680. #---------------------------------------------------------------------
  681. sub GetPassword($)
  682. {
  683. print "Enter password for @_: ";
  684. my $pass = <STDIN>;
  685. print "\n";
  686. chomp($pass);
  687. return $pass;
  688. }
  689. #---------------------------------------------------------------------
  690. # Get_OLE_errmsg - Wrapper for OLE errors
  691. #
  692. # In: Error text
  693. #---------------------------------------------------------------------
  694. sub Get_OLE_errmsg
  695. {
  696. my $text = shift;
  697. return "$text (". Win32::OLE->LastError(). ")";
  698. }
  699. #---------------------------------------------------------------------
  700. # OLE_errmsg - Wrapper for OLE errors
  701. #
  702. # In: Error text
  703. #
  704. #---------------------------------------------------------------------
  705. sub OLE_errmsg
  706. {
  707. errmsg(Get_OLE_errmsg(shift));
  708. }
  709. #---------------------------------------------------------------------
  710. # FatalError- Wrapper for error + exit
  711. #
  712. # In: Error text
  713. #
  714. #---------------------------------------------------------------------
  715. sub FatalError
  716. {
  717. my $text = shift;
  718. errmsg("Fatal error: $text");
  719. exit(1);
  720. }
  721. #---------------------------------------------------------------------
  722. __END__
  723. =head1 NAME
  724. <<mypackage>> - <<short description>>
  725. =head1 SYNOPSIS
  726. <<A short code example>>
  727. =head1 DESCRIPTION
  728. <<The purpose and functionality of this module>>
  729. =head1 AUTHOR
  730. <<your alias>>
  731. =head1 COPYRIGHT
  732. Copyright (c) Microsoft Corporation. All rights reserved.
  733. !AutoBoottest::StartService($starget, "Schedule", "","")))
  734. =cut