Jump to content

One last problem with my config


Recommended Posts

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 this

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:") && 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 by tcarman
Link to comment
Share on other sites


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 by mritter
Link to comment
Share on other sites

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 by tcarman
Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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;
}

Link to comment
Share on other sites

@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.

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...