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

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:"



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?

Sorry for my English language.
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.
"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
User avatar
Posts: 1513
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:
NeoSoft Support
Neosoft Support
NeoSoft Team
Posts: 5620
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.

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

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

2Neosoft Support
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


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 ;)
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 !
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 1 guest