Results 1 to 9 of 9
  1. #1
    Silver Lounger
    Join Date
    Jan 2001
    Location
    Long Beach, California, USA
    Posts
    1,912
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Another lapse in logic -- VBS

    I am having a problem getting this to correct assign the shell command...

    ' define FileType variables
    sKey = "HKCR." & sExt & ""
    sType = oWshShell.RegRead(sKey)
    sTypeKey = "HKCR" & sType & ""
    sTypeName = oWshShell.RegRead(sTypeKey)
    sShell = oWshShell.RegRead(sTypeKey & "shell")

    If VarType(sShell) And vbString Then
    sShell2 = sShell
    Else
    sShell2 = "open"
    End If

    MsgBox sShell2
    ----------------------------

    The way I see it, the message box should display either "open" or the string that is in the (Default) shell value -- but it does not. HELP. Thanks.

  2. #2
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Another lapse in logic -- VBS

    The (Default) entry under Shell is ALWAYS of type REG_SZ (string), but for many types, the value has not been set, so retrieving it will raise an error. So instead of checking VarType, you should build in error checking.

  3. #3
    Silver Lounger
    Join Date
    Jan 2001
    Location
    Long Beach, California, USA
    Posts
    1,912
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Another lapse in logic -- VBS

    Thanks. I agree about the error checking -- but not in this exact case! <img src=/S/smile.gif border=0 alt=smile width=15 height=15> Essentially every desired File Type should have a "shell" key -- so no error should be generated.

    Yeah, I finally figured out that NO MATTER if the shell (Default) values is ( value not set ) or '"" -- the VarType result is still an 8 (vbString). DUH!!! I knew I had a lapse in logic...

    The correct method (eh, or at least a functional method) to do this is here:
    ---------------------------------------

    ' assign sShell2 to sShell or "open"

    If sShell <> "" Then
    sShell2 = sShell
    Else
    sShell2 = "open"
    End If
    ------------------------------------------

    This correctly assigns the shell value whether it is "" or ( value not set ) -- or if it is a unique string.

    Here is my entire test code. Give it a try... if you wish.
    -------------------------------------------------------

    Dim sShell, sShell2

    Set oWshShell = WScript.CreateObject("WScript.Shell")

    ' obtain the file extention from the user
    sExt = InputBox("Enter File Extension:" & vbCRLF & _
    "(Do not include the preceding period)" & vbCRLF & "Example: txt")

    ' obtain the File Type key from the file extention
    sKey = "HKCR." & sExt & ""
    sType = oWshShell.RegRead(sKey)
    sTypeKey = "HKCR" & sType & ""

    ' read shell (Default) value
    sShell = oWshShell.RegRead(sTypeKey & "shell")

    MsgBox "sShell is: " & sShell & vbCRLF & _
    "VarType(sShell) is :" & VarType(sShell)

    ' assign Shell2 to sShell or "open"

    If sShell <> "" Then
    sShell2 = sShell
    Else
    sShell2 = "open"
    End If

    MsgBox "sShell2 is: " & sShell2

    ' release the object
    Set oWshShell = Nothing

  4. #4
    Silver Lounger
    Join Date
    Jan 2001
    Location
    Long Beach, California, USA
    Posts
    1,912
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Another lapse in logic -- VBS

    Duh, and I really don't need two varibles -- I can simply reassign the first one:
    ---------------------------

    ' reassign sShell to sShell or "open"

    If sShell <> "" Then
    sShell = sShell
    Else
    sShell = "open"
    End If
    ------------------------------

    Like I said, I don't know much about VBScript... Nothing like learning by experience! <img src=/S/smile.gif border=0 alt=smile width=15 height=15> Cheers and Thanks.

  5. #5
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Another lapse in logic -- VBS

    When I run your code (in VBA, not VBScript), I get an error message if I enter txt as extension - see screenshot.
    Attached Images Attached Images
    • File Type: png x.PNG (6.9 KB, 0 views)

  6. #6
    Silver Lounger
    Join Date
    Jan 2001
    Location
    Long Beach, California, USA
    Posts
    1,912
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Another lapse in logic -- VBS

    I am not using VBA (nor do I know anything significant about it) -- so I am not sure. Perhaps the terminal "" is causing the problem??

    The "textfile/shell" key must exist on your computer, so unless your computer somehow prevents it from opening, then I must assume the "" is causing the error.

  7. #7
    Silver Lounger
    Join Date
    Jan 2001
    Location
    Long Beach, California, USA
    Posts
    1,912
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Another lapse in logic -- VBS

    Regardless, in VBS -- eh, still without error correction (I know, but I am still working on gathering all the correct information, then I'll work on that) -- I can use the script to collect a lot of information about a file extension. See the example for a .pdf file. This is not complete -- for example, I still need to add on more EditFlag info...
    ____________________

    Some of this information is very helpful when tyring to figure out why Windows works the way it does. For example, on this computer when IE opens a link to a .CSV file, it checks EditFlags in both the Excel.CSV key AND the Excel.Sheet.# key!! If an EditFlags value exists in Excel.CSV, that one takes precedence -- otherwise, IE uses the EditFlags for the MIME Content Type extension's File Type or the CLSID's ProgID's File Type.

    Additionally, when IE downloaded a .CSV file, it took the executable path from CLSID LocalServer32 value -- IE never once queried the Excel.CSVshellopencommand -- which is what you might expect it to do...

    The .pdf data in the image is of interest because the MIME data is used by IE to open an Acrobat Reader file inside IE. The ActiveX control responsible for this is Identified in the InprocServer32 line.
    Attached Images Attached Images

  8. #8
    Silver Lounger
    Join Date
    Jan 2001
    Location
    Long Beach, California, USA
    Posts
    1,912
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Another lapse in logic -- VBS

    Lastly, attached is the bloated, incomplete, and non-error corrected code. There are unneeded and unused fragments scattered through out. (And even a Typo <img src=/S/frown.gif border=0 alt=frown width=15 height=15> -- flie = file). But, at least it is working! <img src=/S/smile.gif border=0 alt=smile width=15 height=15>

    I am flying back across the country today, so I can work on eliminating the bloat then -- and maybe even add some error correction!
    Attached Files Attached Files

  9. #9
    Silver Lounger
    Join Date
    Jan 2001
    Location
    Long Beach, California, USA
    Posts
    1,912
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Another lapse in logic -- VBS

    Here is a perfect example of why this stuff gets so confusing. Create an HTML file (.htm) and include a link to a .txt file. For example:

    <HTML>
    <A HREF=C:WindowsDesktopjunk.txt>Click me to download or open a .txt file.</A>
    </HTML>

    Next, check your Folder Options | File Type information. You will see that is says "Confirm open after download" for "Text Document". If you remember, this means that IE should display a Download Dialog box and ask you if you want to Open or Download the file, right?

    Well, give it a try. Open the .htm file and click the link. What did you find? Gee, IE simply display the junk.txt file inside IE. Why? What happened to the "Confirm open..." part?

    It got ignorred. How and why? Because IE did NOT follow the non-existent EditFlags for "txtfile". You see, by default, if IE finds NO EditFlags for a give File Type, it assume you want to see the Download Dialog box. If you remove the check from "Confirm open...", then the Explorer shell ADDS in the "EditFlags=00 00 01 00" value for the specified File Type.

    What did IE do instead? Well, it looked at the EditFlags for htmlfile -- which, lo and behold, happen to be 00 00 01 00 -- which indicates the flag to NOT display the Download Dialog box is set.

    Why did it use the htmlfile EditFlags? Well, it got it from this rather convoluted association:

    .txt Content Type = text/plain
    MIME text/plain CLSID = {235569... etc}
    CLSID{235569... etc} ProgID = htmlfile
    htmlfile EditFlags = 00 00 01 00

    Thus demonstrating the inter-relationship between the File Type, MIME, and CLSID data...
    Attached Images Attached Images

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •