September 20, 200619 yr I have nearly perfected my server build but am having issues with one last thing.I have created a script to create a D: partition and want WPI to disable the checkbox if D: is not present.At the moment I have the following, which for some reason does not disable the checkbox if D: is a CD-ROM. The CDROM Dependancy currently maps the CD-Rom to X:prog[pn]=['Create D: Partition'];ordr[pn]=[2];uid[pn]=['CREATEDPARTITION'];dflt[pn]=['yes'];cat[pn]=['System'];forc[pn]=['no'];deps[pn]=['CDROM'];gcond[pn]=['DriveExists("D:") && FileExists("D:\\pagefile.sys")'];cmd1[pn]=['hidecmd /w cscript c:\\build\\scripts\\partition.vbs //B'];pn++;Ideally I would like a DriveType() function to determine what type of drive D: is, like thisprog[pn]=['Create D: Partition'];ordr[pn]=[2];uid[pn]=['CREATEDPARTITION'];dflt[pn]=['yes'];cat[pn]=['System'];forc[pn]=['no'];deps[pn]=['CDROM'];gcond[pn]=['DriveExists("D:") && DriveType("Fixed")'];cmd1[pn]=['hidecmd /w cscript c:\\build\\scripts\\partition.vbs //B'];pn++;Am I missing something, why is my config not disabling the option when D: is a CD-ROM?Cheers. Edited September 21, 200619 yr by tcarman
September 21, 200619 yr This wasn't too hard to implement so I went ahead and created two functions: DriveExists(drive) and DriveType(drive). Pass a drive letter (no colon[:]) to DriveExists() and it will return true or false.Pass a drive letter (no colon[:]) to DriveType() and it will return one of six values:UNKNOWN - The drive exists, but the type is unknown.REMOVEABLE - The drive exists and is removeable (i.e. USB attached drive)FIXED - The drive exists and is a fixed hard drive partition.NETWORK - The drive exists and is mapped to a network share.CDROM - The drive exists and is an optical drive.RAMDISK - The drive exists and is a memory allocated drive.NULL - The drive does not exist.Note: All returned values from DriveType() are in uppercase.Here are the two functions. Either add them to core.js or download the modified core.js.function DriveExists(dr){ position="core.js"; whatfunc="DriveExists()"; var en, ite; en = new Enumerator(fso.Drives); for(; !en.atEnd(); en.moveNext()) { ite = en.item(); if (ite.DriveLetter == dr.toUpperCase()) return true; } return false;}function DriveType(dr){ position="core.js"; whatfunc="DriveType()"; var driv; if(DriveExists(dr)) { driv = fso.GetDrive(dr); switch(driv.DriveType) { case 0: return 'UNKNOWN'; case 1: return 'REMOVEABLE'; case 2: return 'FIXED'; case 3: return 'NETWORK'; case 4: return 'CDROM'; case 5: return 'RAMDISK'; } } return NULL;}@tcarman your gcond would be the following:gcond[pn]=['DriveType("D")=="FIXED"'];This will check if the drive exists and if it is a fixed partition.Modified core.js file: Edited September 22, 200619 yr by mritter
September 22, 200619 yr Author This works great. Thanks.I want to learn to write my own functions based on WMI queries. I am a total noob in JScript but can understand VBScript.Someone had mentioned WPI has some WMI built in ??How do I go about writing my own functions in Jscript for WPI?Thanks for the help. Edited September 22, 200619 yr by tcarman
September 22, 200619 yr If you know VBScript then you should be good. JScript and VBScript are interchangeable except for some syntax differences. I'm not a JScript expert by far. I just kind of learn things as I need them.I guess the best thing to do is go through all of the WPI code to get a feel for how to do things. It takes a while to do, but thats how I learned.
September 22, 200619 yr Author function DriveExists(dr){ position="core.js"; whatfunc="DriveExists()"; var en, ite; en = new Enumerator(fso.Drives); // This is the line that I need further clarification on ?!? for(; !en.atEnd(); en.moveNext()) { ite = en.item(); if (ite.DriveLetter == dr.toUpperCase()) return true; } return false;}
September 22, 200619 yr Nice code, Zorphnog. But I have already written code for those functions. Use the above code if you want, but it won't be the same for 5.5.
September 22, 200619 yr @tcarman: I don't know how much you know about programming or what languages you know, but an enumerator is a common operator across all languages. It basically allows you to step through a list of results one item at a time. In this case fso.Drives (fso is a FileSystemObject that is declared globally in WPI) is a list of all drives on the system. The for loop steps through each drive using the moveNext() function. When en.item() is called it returns a Drive object and we can then compare the drive letter to the one that was passed to the function.@mritter: I figured you would already be working on these, but he needed a solution and it only took me a couple of minutes to put together.
Create an account or sign in to comment