Source language: Translate to:

How detect if the app is running in a USB stick

Questions about using NeoBook's scripting language

Moderator: Neosoft Support

How detect if the app is running in a USB stick

Postby sombra » Tue May 15, 2007 11:30 pm

Hi,
Currently, I have a problem for detect if a compiled pub is running in a "removable drive". The reason: If the app is in local drive, I could write in Registry for autorun the program at startup.
But it the app is in a usb stick, this option should be disabled.

My temporal solution is this code:
Code: Select all
ExtractFileDrive "[commandline]" "[unidadpub]"
If "[unidadpub]" "<>" "C:"

Else

EndIf

But it isn't enough for me. I was looking for values in Registry, files into windows and system directorys without luck :(

Anybody know an alternative method?
TIA

Sorry for my English language.
sombra
 
Posts: 93
Joined: Sat Apr 02, 2005 3:09 pm
Location: Spain

Postby Wrangler » Wed May 16, 2007 7:56 am

You could have the app write to a dummy file when starting, and deleting the file when shut down. Then you could check for the presence of the file to determine if it is running.
Wrangler
--------------
"You never know about a woman. Whether she'll laugh, cry or go for a gun." - Louis L'Amour

Windows 7 Ultimate SP1 64bit
16GB Ram
Asus GTX 950 OC Strix
Software made with NeoBook
http://highdesertsoftware.com
User avatar
Wrangler
 
Posts: 1505
Joined: Thu Mar 31, 2005 11:40 pm
Location: USA

Postby Neosoft Support » Wed May 16, 2007 10:22 am

A plug-in called rtFileSystemMgt includes an action (rtGetDriveType) that can be used to determine drive type. For a USB drive it returns "Removable", for a hard drive it returns "Fixed". You can download a copy of rtFileSystemMgt from the link below:

http://www.neosoftware.com/neobook/modules/plugins/singlefile.php?cid=16&lid=43
NeoSoft Support
Neosoft Support
NeoSoft Team
 
Posts: 5593
Joined: Thu Mar 31, 2005 10:48 pm
Location: Oregon, USA

Postby edunaway » Wed May 16, 2007 2:33 pm

If you don't want to buy Ronnie's excellent plugin (which I highly recommend) you could take a guess that if it's not running from C: or D: the odds are in your favor that it's not running from a local hard drive. Not 100% accurate, but should be ok the majority of cases.

-eric
edunaway
 
Posts: 88
Joined: Wed May 04, 2005 9:17 am

Postby sombra » Thu May 17, 2007 3:17 pm

2Wrangler
2Neosoft Support
2edunaway
Thank you very much for the tips. :)

rtFileSystemMgt really is a good plugin. With it, I have the solution for the problem, but in this case isn't convenient for me. I can't buy the plugin now only for this case. This "neobook application" simply is a pastime. Perhaps a day... I will buy it.

Well, investigating a bit, I found this code in visual basic script:
Code: Select all
strComputer = "."
Set objWMIService = GetObject("winmgmts:" _
    & "{impersonationLevel=impersonate}!\\" _
    & strComputer & "\root\cimv2")
Set colDisks = objWMIService.ExecQuery _
    ("Select * from Win32_LogicalDisk")
For Each objDisk in colDisks
    Wscript.Echo "DeviceID: "& vbTab _
        &  objDisk.DeviceID       
    Select Case objDisk.DriveType
        Case 1
            Wscript.Echo "No root directory. " _
                & "Drive type could not be " _
                & "determined."
        Case 2
            Wscript.Echo "DriveType: "& vbTab _
                &  "Removable drive."
        Case 3
            Wscript.Echo "DriveType: "& vbTab _
                &  "Local hard disk."
        Case 4
            Wscript.Echo "DriveType: "& vbTab _
                &  "Network disk."     
        Case 5
            Wscript.Echo "DriveType: "& vbTab _
                &  "Compact disk."     
        Case 6
            Wscript.Echo "DriveType: "& vbTab _
                &  "RAM disk."   
        Case Else
            Wscript.Echo "Drive type could not be" _
                & " determined."
    End Select
Next

source: http://msdn2.microsoft.com/en-us/library/aa394592.aspx

I can save it in a file and execute from neobook "cscript detectdrive.vbs > unidades.txt"
Late, I can to parse unidades.txt

I am not sure if this example work in all OS (work fine with WXP SP2)

-
Regards from Spain ;)
sombra
 
Posts: 93
Joined: Sat Apr 02, 2005 3:09 pm
Location: Spain

Postby Luke » Fri May 18, 2007 1:47 pm

I have a simple command line utility.
Run it from the pub directory , and returns the result to a text file
as " Removable " , " Fixed " , "CDROM", "NETWORK ", "RAMDRIVE ".

and it is free . If you want it . let me now !
Luke
 
Posts: 30
Joined: Thu Nov 17, 2005 6:24 am


Return to NeoBook Action Commands

Who is online

Users browsing this forum: No registered users and 4 guests