Get hard drive letters

Deploying to Windows? Utilizing VB Script execution? This is the place to ask Windows-specific questions.

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller

alemrantareq
Posts: 203
Joined: Wed Jul 23, 2008 8:46 am

Get hard drive letters

Post by alemrantareq » Wed Nov 12, 2008 8:18 am

hi everybody, i need some help. my application has a scrolling field which needs to show the available hard drive letters and each drive have a check box. what will be the script to do that in simple? pls help me...thanks

Mark
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 5150
Joined: Thu Feb 23, 2006 9:24 pm
Contact:

Post by Mark » Wed Nov 12, 2008 10:33 am

Hi alemrantareq,

Doesn't the volumes function work for you?

Best,

Mark
The biggest LiveCode group on Facebook: https://www.facebook.com/groups/livecode.developers
The book "Programming LiveCode for the Real Beginner"! Get it here! http://tinyurl.com/book-livecode

alemrantareq
Posts: 203
Joined: Wed Jul 23, 2008 8:46 am

Post by alemrantareq » Sun Nov 16, 2008 9:52 am

hi mark,

i just need the script to do that as i cant understand what will be that script, so that the scroll field contains the drive letters with checkboxes. pls, give me the script in details. thanks ...

Mark
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 5150
Joined: Thu Feb 23, 2006 9:24 pm
Contact:

Post by Mark » Sun Nov 16, 2008 12:03 pm

Dear Alemrantareq,

Always when I see this kind of questions, I wonder whether people have already read the documentation and have made sure they possess the basic skills they need to use Revolution.

What you need is the volumes function, a field and the put command.

Best regards,

Mark
The biggest LiveCode group on Facebook: https://www.facebook.com/groups/livecode.developers
The book "Programming LiveCode for the Real Beginner"! Get it here! http://tinyurl.com/book-livecode

alemrantareq
Posts: 203
Joined: Wed Jul 23, 2008 8:46 am

Post by alemrantareq » Mon Nov 17, 2008 7:50 am

excuse me mark, but i think you could not understand my problem. But I got your point. I've posted it when the documentation is not enough for me. Let me clear my problem:
for example, I have a scroll field "Test". Now, I make the script:

put volumes() into tPath

My question is that what i've to type in the brakets and whether it will be the stack script with "on preOpenstack" or the field script?

Janschenkel
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 977
Joined: Sat Apr 08, 2006 7:47 am
Contact:

Post by Janschenkel » Mon Nov 17, 2008 9:06 am

That depends upon what you want to achieve - do you want to click on a button to fill up the list, or do you want it done automatically as soon as the card opens?
If you want it done when the card opens, place the following in the card script:

Code: Select all

on openCard
  put the volumes into field "Test"
end openCard
HTH,

Jan Schenkel.
Quartam Reports & PDF Library for LiveCode
www.quartam.com

mwieder
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 3581
Joined: Mon Jan 22, 2007 7:36 am
Contact:

Post by mwieder » Mon Nov 17, 2008 10:31 pm

There's more to this as well. Do you really need checkboxes in the scrolling field or will some other way of selecting drives work?

What I would do would be to place a scrolling field on the card, then check its "listBehavior" property and check the "multipleHilites" and "nonContiguousHilites" and "toggleHilites" checkboxes (all three that become enabled when you select the list behavior). Then in your "openCard" or "preOpenCard" handler have the command

put the volumes into field "xyz"

or whatever your field is named. That way you'll have the list of drives in a scrolling field and the user can select them by highlighting lines in the field.

Of course there are many ways of accomplishing any given task, but this one's pretty simple to implement.

alemrantareq
Posts: 203
Joined: Wed Jul 23, 2008 8:46 am

Post by alemrantareq » Thu Nov 20, 2008 5:50 am

actually i need to learn how to get only the hard drive volumes. But none replied the accurate solution. pls, show me the way to get i) only the hard drive volumes, ii) only the cd rom volumes and iii) only the removable drives. pls.......... :cry:

SparkOut
Posts: 2945
Joined: Sun Sep 23, 2007 4:58 pm

Post by SparkOut » Thu Nov 20, 2008 11:04 am

alemrantareq wrote:actually i need to learn how to get only the hard drive volumes. But none replied the accurate solution. pls, show me the way to get i) only the hard drive volumes, ii) only the cd rom volumes and iii) only the removable drives. pls.......... :cry:
Well nowhere in your original question did you ask about any of this. People have been trying to help, but you don't give all the information about what you want to do and what you have tried. You seem to be just begging for code, not looking for answers or understanding.

If the volumes function isn't helpful enough for you, then I think (as you've posted this in the Windows forum) then you will need to use Rev to do a vbscript (look up "do" in the dictionary) which uses the Windows Management Interface to obtain system information.

Use the WMI Scripting Primer here for more information:
http://www.microsoft.com/technet/script ... x?mfr=true

and specifically the section here on Identifying Drives and Drive Types has code (listing 10.4 at the bottom) that you can use and adapt to return the information you need.
http://www.microsoft.com/technet/script ... x?mfr=true

alemrantareq
Posts: 203
Joined: Wed Jul 23, 2008 8:46 am

Post by alemrantareq » Thu Dec 04, 2008 7:21 am

Hi SparkOut,
Thanks for your reply and comments. I've visited both the sites you've provided. As I've no knowledge about wmi scripting, I request you to provide an example for wmi scripting to get only the hard drive letters. Pls, make me pleasure... :lol:

SparkOut
Posts: 2945
Joined: Sun Sep 23, 2007 4:58 pm

Post by SparkOut » Thu Dec 04, 2008 9:16 am

The second link I posted shows exactly that code.

SparkOut
Posts: 2945
Joined: Sun Sep 23, 2007 4:58 pm

Post by SparkOut » Thu Dec 04, 2008 5:19 pm

still, here is a modified version of that script for you to use from Rev.

make a button that you will use to interrogate the drives.
give it a custom property (say cVBScript) and the contents of the property as follows:

Code: Select all

intDriveType = <<intDriveType>>
strComputer = "."
result = ""
Set objWMIService = GetObject("winmgmts:" & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
Set colDisks = objWMIService.ExecQuery ("SELECT * FROM Win32_LogicalDisk")
For Each objDisk in colDisks
  Select Case objDisk.DriveType
  Case intDriveType
    result = result & objDisk.DeviceID & vblf
  End Select
Next
Set colDisks = nothing
Set objWMIService = nothing
(note that some of the lines are quite long and have probably wrapped around. I took out the line concatenators from the original script in case Rev didn't like them).

You will need to replace the "<<intDriveType>>" placeholder with the drive type that you want to get the info for:

Type 1 you can probably ignore, as it is for drives with no root directory, so probably unformatted or unreadable foreign types.

Type 2 is for removable disks (and card readers and the like). Note that Windows will usually not report an empty drive at all - so you will likely only get results from drives with media inserted.

Type 3 is for local hard disks.

Type 4 is for network drives.

Type 5 is for CD and DVD drives.

Type 6 is for RAM disks, so you probably won't need that in your environment.

To return the drive letters for local hard disk drives, you need to replace "<<intDriveType>>" with "3" in the script. I made a radio group and got the mouseUp handler to copy the custom property code to a variable tScript and then replaced the placeholder with the right number value according to the properties of the hilitedButton of the radio group.

Then you can

Code: Select all

do tScript as "vbscript"
put the result into field "fldDrives"
I have put a test stack on my RevOnline space, in Utilities section, titled WMI disk info.

alemrantareq
Posts: 203
Joined: Wed Jul 23, 2008 8:46 am

Post by alemrantareq » Sat Dec 06, 2008 5:17 am

Hi SparkOut,
Thanks for your reply. From your script, I've made the following for a btn -

Code: Select all

set the custompropertyset of me to cVBScript
  intDriveType = 3
strComputer = "." 
result = "" 
Set objWMIService = GetObject("winmgmts:" & "{impersonationLevel=impersonate}!\\" & 
strComputer & "\root\cimv2") 
Set colDisks = objWMIService.ExecQuery ("SELECT * FROM Win32_LogicalDisk") 
For Each objDisk in colDisks 
  Select Case objDisk.DriveType 
  Case intDriveType 
    result = result & objDisk.DeviceID & vblf 
  End Select 
Next 
Set colDisks = nothing 
Set objWMIService = nothing


on mouseUp
do cVBScript as "vbscript"
put the result into field "fldDrives"
end mouseUp
It shows the result into the field - "alternate language not found". I think there lies one or more error(s) in this script. Would you pls correct and make it fresh for me?

SparkOut
Posts: 2945
Joined: Sun Sep 23, 2007 4:58 pm

Post by SparkOut » Sat Dec 06, 2008 7:40 am

No I won't. There's a perfectly workable stack that I made for you to examine and tell how it works on my revOnline space.
It really now is up to you to learn about Rev and understand what it is that you're doing, rather than just beg for code.
Everything is there that you need. You really must do your own learning about how to use it.

alemrantareq
Posts: 203
Joined: Wed Jul 23, 2008 8:46 am

Post by alemrantareq » Sat Dec 06, 2008 12:04 pm

Hi SparkOut,
I've posted the code just for checking the error(s) as I'm tring to learn. Well, would you pls give your revonline space address? Thanks for your reply and in advance...

Post Reply