/*********************************************************************** Created: 5th June 2001 Last Modified: 28th June 2001 ***********************************************************************/ /** SCRIPT SPECIFIC VARIABLES **/ var File; //used for input argument var LFile = "status.log"; //log file create (OK to change!) var Title = "Creating WinPE Images"; //title on all dialogs created (OK to change!) var Arch = "32"; //what arch to use, default to 32-bit var Temp_Loc = "WinPE.temp.build"; //where it temp copies files from opk (OK to change!) var Default_Dest_Name = "CustWinPE"; //default location to build WinPE. (OK to change!) var Default_ISO_Name = "WinPEImage.iso" //default ISO image name var OPK_Location = "d:"; //defaults to d: var XP_Location = "d:"; //default to d: var startfile = "winpesys.inf"; //the file which has the reg key for startnet.cmd var alphabet = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";//used for checking drive avalibility on net usage var Max_Components = 10; //dufault number of maximum components var std_size = 80; //approx target size of the image in MB (used to check if it expanded files) var Drive_Space_Needed = 300; //space for build location (in MB) /** VARIABLE CONSTANTS **/ var vbCritical = 16; var vbQuestion = 32; var vbExclam = 48; var vbInfo = 64; var vbOKOnly = 0; var vbOKCancel = 1; var vbAbort = 2; var vbYesNoCancel = 3; var vbYesNo = 4; var vbRetryCancel = 5; var drtype = new Array(5);//array for drive types drtype[0] = " Unknown "; drtype[1] = " Removable "; drtype[2] = " Fixed "; drtype[3] = " Remote "; drtype[4] = " CDROM "; drtype[5] = " RAMDisk "; var netdrive = new Array(2); //array for network connections netdrive[0] = ""; netdrive[1] = ""; var Component = new Array(Max_Components); var HelpMsg = "Usage: [/?] "+WScript.ScriptName+" \nTo generate a parameter file please run CreateWinPE.hta (double click it)"; // vars used internally (Don't change these) var In_File; var OPK_Drive; var OPK_Loc; var XP_Loc; var XP_Drive; var Dest_Name; var Dest_Option; var CommandLine =""; var Wasnet="0"; var Image_Destination; var line; var temp_dest; var temp_mkdir; var oDrive; var Startup="startnet.cmd"; //don't change this var Winbomp="winbom.ini"; //don't change this var ReturnVal; var Com_Count = 0; var count = 0; var delaywait = 15; var Home_Drv="c:"; var Wallpaper="winpe.bmp"; var Done_All = 1; //used for making sure each section in the parameter file is only entered once. //creating WSH object var wshShell = WScript.CreateObject("WScript.Shell"); var wshNet = WScript.CreateObject("WScript.Network"); var objEnv = wshShell.Environment("Process"); //doing this so that it uses current HOMEDRIVE Home_Drv = objEnv("HOMEDRIVE"); Temp_Loc=Home_Drv+"\\"+Temp_Loc; Default_Dest_Name = Home_Drv+"\\"+Default_Dest_Name; //default location to build WinPE. (OK to change!) Default_ISO_Name = Home_Drv+"\\"+Default_ISO_Name; //default ISO image name //checking number of args. It HAS to be 1 else error out if(WScript.Arguments.length != 1) { wshShell.popup(HelpMsg,0,Title,vbInfo); WScript.Quit(); } File=WScript.Arguments.Item(0); // saving 1st arg as File if (File == "/?" || File == "help") //checking of 1st arg is help { wshShell.popup(HelpMsg,0,Title,vbInfo); WScript.Quit(); } //creating unique logfile name (comment this to disable) //LFile = "status_"+wshNet.UserName+".log"; //creating objects necessary var fso=new ActiveXObject("Scripting.FileSystemObject"); //create file sys obj try{ var logfile=fso.OpenTextFile(LFile,2,true); //logfile } catch(e){ wshShell.Popup("ERROR: "+LFile+" is either write protected or being used by another program.\nTerminating Script!",0,Title,vbCritical); WScript.Quit(); } logfile.WriteLine(Date()+"\tLOG FILE created!"); logfile.WriteLine(Date()+"\tComputer Name=" + wshNet.ComputerName+",User Name=" + wshNet.UserName); logfile.WriteBlankLines(1); //checking if file exists if (!fso.FileExists(File)) CleanUp("File "+ File + " does not exist!."); In_File = fso.OpenTextFile(File); // calling all function to operate now Read_Settings(); //reads the settings file for inputs to the script Copy_OPK_Files(); //copies OPK files to temp location Change_Startup(); //makes changes to add custom startnet.cmd Change_Wallpaper(); //adds custom wallpaper Change_Winbom(); //makes changes to add custom winbom.ini Image_Dest(); //runs mkimg.cmd in here CleanUp("OK"); /*END OF MAIN*/ /*********************** FUNCTIONs*****************************************/ /* FUNCTION: Read_Settings() This function reads the parms from the parameter file, and saves them to local variables. IT also does some minimal error checking on those parms */ function Read_Settings() { while (!In_File.AtEndOfStream) { switch (In_File.ReadLine().substring(0,5)) { case "[Arch": //looks for [Architecture] //reading arch type (can be IA64, I386 32 or 64) Arch=In_File.ReadLine(); Arch=Arch.toUpperCase(); if (Arch != "32" && Arch != "64" && Arch != "I386" && Arch != "IA64" && Arch != "X86" ) CleanUp("Arch type invalid! "); if (Arch == "32" || Arch == "x86" || Arch == "I386") Arch = "I386"; else Arch = "IA64"; logfile.WriteLine(Date()+"\t(*) Arch Type = "+Arch); Done_All = Done_All*2; //for verification break; case "[Imag": //looks for [Image Destination] Image_Destination = In_File.ReadLine(); //where to put it ex CD/HDD if(Image_Destination.toUpperCase() != "CD" && Image_Destination.toUpperCase() != "HDD") CleanUp("Image Dest not valid! Must be CD or HDD."); Dest_Name = In_File.ReadLine(); // name of dest if(Image_Destination.toUpperCase() == "HDD") { var d = fso.GetDrive(Dest_Name.substring(0,1)); if (d.DriveType != 2) CleanUp("Can't create an image on a "+drtype[d.DriveType]+"drive. It must be a FIXED drive.\nPlease Change the [Image Destination] section in "+File+ " file to correct this."); } //checking the file extension ...if not .iso then making it so if(Dest_Name.substring(Dest_Name.length -4,Dest_Name.length).toLowerCase() != ".iso") { if(Image_Destination.toUpperCase() == "CD") Dest_Name=Dest_Name+".iso"; } else { if(Image_Destination.toUpperCase() == "HDD") CleanUp("Image Name "+Dest_Name+" is invalid for HDD."); } //for special case when no option and its the end of the file. try{ Dest_Option = In_File.ReadLine(); //will be NULL otherwise if(Dest_Option.toLowerCase() == "bootable") { wshShell.Popup("You have choosen to make this image bootable.\nThis may take longer to run.\nYou will be notified when the scrpit is complete.",delaywait,Title,0); } }catch(e) { CleanUp("Add an extra blank line to the end of "+File); } Done_All = Done_All*3; //for verification break; case "[OPK ": //looks for [OPK Location] OPK_Loc = In_File.ReadLine(); if (OPK_Loc == "") CleanUp("OPK Location not specified!"); logfile.WriteLine(Date()+"\t(*) OPK Locatoin = "+ OPK_Loc); Done_All = Done_All*5; //for verification break; case "[WinX": //looks for [WinXP Location] XP_Loc = In_File.ReadLine(); if (OPK_Loc == "") CleanUp("Windows XP Location not specified!"); logfile.WriteLine(Date()+"\t(*) Windows XP Locatoin = "+ XP_Loc); Done_All = Done_All*7; //for verification break; case "[Star": //for [Startup] , where startnet.cmd stuff goes Startup = In_File.ReadLine(); if (Startup.toLowerCase() != "startnet.cmd" && Startup != "") if (!fso.FileExists(Startup)) //checking if file exists CleanUp(Startup+" -- Startup file not found!"); Done_All = Done_All*11; //for verification break; case "[Winb": //for [Winbom] , where custom winbom.ini info is placed try{ Winbom = In_File.ReadLine(); }catch(e) {CleanUp("Must have [Winbom] section in "+File);} if (Winbom.toLowerCase() != "winbom.ini" && Winbom != "") if (!fso.FileExists(Winbom)) CleanUp(Winbom+" -- winbom file not found!"); Done_All = Done_All*13; //for verification break; case "[Opti": //for [Optional Components] count = 0; Component[count]=In_File.ReadLine(); while(Component[count] != "" && count < 10) //loop which look at optional component { count++; try { Component[count]=In_File.ReadLine(); } catch(e) { CleanUp("parmater file is incorrect!"); } } if (count > 10) { CleanUp("Maximum optional components allowed is "+Max_Components); } Com_Count=count; for(count=0;count-1;i--) { drivefound=alphabet.substring(i,i+1); if (!fso.DriveExists(drivefound)) return drivefound; } CleanUp("No net connections can be made cause all drive letters are used."); }/*FindDrive()*/ function Install_COM() { /////////////////////// //calling component scripts if (Image_Destination.toUpperCase()=="CD") temp_dest = Home_Drv+"\\testimage"; else temp_dest = Dest_Name; if (Com_Count != 0) { for(count=0;count1>nul",1,true); wshShell.Run("cmd /c cd "+Temp_Loc+" && dskimage.exe a: efisys.bin 2>1>nul",1,true); wshShell.Run("cmd /c cd "+Temp_Loc+" && oscdimg.exe -n -befisys.bin "+Home_Drv+"\\testimage \""+Dest_Name+"\"",1,true); } else { CommandLine="cmd /c cd "+Temp_Loc+" && oscdimg.exe -n -betfsboot.com "+Home_Drv+"\\testimage \""+Dest_Name+"\""; wshShell.Run(CommandLine,1,true); } logfile.WriteLine(Date()+"\t(S) Created ISO image file!"); } function CleanUp(parm) { if (Wasnet == "1") { if (netdrive[0] != "") { CommandLine="net use "+netdrive[0]+" /del"; wshShell.Run(CommandLine); wshShell.SendKeys("y"); } if (netdrive[1] != "") { CommandLine="net use "+netdrive[1]+" /del"; wshShell.Run(CommandLine); wshShell.SendKeys("y"); } } if (parm == "OK") { logfile.WriteBlankLines(1); logfile.WriteLine(Date()+"\tThe new image of WinPE can be found at "+Dest_Name); logfile.WriteLine(Date()+"\tCOMPLETE"); wshShell.Popup("Script Complete! \n",0,Title,vbInfo); } else { logfile.WriteLine(Date()+"\t(E) "+parm); logfile.WriteBlankLines(1); logfile.WriteLine("Script Terminated @ "+Date()); wshShell.Popup(parm+"\n\n Terminating Script!",0,Title,vbCritical); } // deleting temp storage folder if (fso.FolderExists(Temp_Loc)) { try{fso.DeleteFolder(Temp_Loc); } catch(e){ wshShell.Popup("Can't delete "+Temp_Loc,0,Title,vbInfo);} } logfile.Close(); //closing logfile WScript.Quit(); }/*CleanUp(parm)*/