LB Booster
« Associating files? »

Welcome Guest. Please Login or Register.
Apr 1st, 2018, 05:05am



ATTENTION MEMBERS: Conforums will be closing it doors and discontinuing its service on April 15, 2018.
We apologize Conforums does not have any export functions to migrate data.
Ad-Free has been deactivated. Outstanding Ad-Free credits will be reimbursed to respective payment methods.

Thank you Conforums members.
Speed up Liberty BASIC programs by up to ten times!
Compile Liberty BASIC programs to compact, standalone executables!
Overcome many of Liberty BASIC's bugs and limitations!
LB Booster Resources
LB Booster documentation
LB Booster Home Page
LB Booster technical Wiki
Just BASIC forum
BBC BASIC Home Page
Liberty BASIC forum (the original)

« Previous Topic | Next Topic »
Pages: 1  Notify Send Topic Print
 thread  Author  Topic: Associating files?  (Read 725 times)
datwill
Guest
xx Associating files?
« Thread started on: May 11th, 2015, 2:31pm »

I know people on the normal LB forum would be angry a million times over if they asked me this question (EDIT: OPPPPS grin grin if I asked this question to them!), and if it makes people here mad too, I'm sorry sad but how do you associate files with certain applications with code?
« Last Edit: May 11th, 2015, 2:32pm by datwill » User IP Logged

Richard Russell
Administrator
ImageImageImageImageImage


member is offline

Avatar




Homepage PM


Posts: 1348
xx Re: Associating files?
« Reply #1 on: May 11th, 2015, 5:13pm »

on May 11th, 2015, 2:31pm, Daniel Atwill wrote:
how do you associate files with certain applications with code?

You are quite right that the LB Community Forum forbids the discussion of Registry access (ridiculous, in my opinion, since it is no more 'dangerous' than many other things that are permitted there).

The code below (LBB only, although it could easily be adapted to run in LB) associates the extension specified as Extension$ (don't forget the dot) with the command Command$. The program assumes that the name of the file is passed as a simple command-line parameter to the application.

Naturally, this program will only work if it is 'Run As Administrator', and since it can change the association of an existing file type it should be used with care:

Code:
    Extension$ = ".xyz"
    ProgID$ = "xyzfile"
    Command$ = CHR$(34) + "C:\Temp\MyProg.exe" + CHR$(34) + " %1"

    ProgIDLen = LEN(ProgID$) + 1
    CommandLen = LEN(Command$) + 1

    STRUCT key, handle AS ULONG

    CALLDLL #advapi32, "RegCreateKeyExA", _HKEY_CLASSES_ROOT AS ULONG, _
      Extension$ AS PTR, 0 AS LONG, "" AS PTR, 0 AS LONG, _
      _KEY_WRITE AS LONG, 0 AS LONG, key AS STRUCT, _
      0 AS LONG, ret AS LONG
    IF ret THEN NOTICE "RegCreateKeyEx failed (ProgID)" : END

    CALLDLL #advapi32, "RegSetValueExA", key.handle.struct AS ULONG, _
      "" AS PTR, 0 AS LONG, _REG_SZ AS LONG, _
      ProgID$ AS PTR, ProgIDLen AS LONG, ret AS LONG
    IF ret THEN NOTICE "RegSetValueEx failed (ProgID)" : END

    CALLDLL #advapi32, "RegCloseKey", key.handle.struct AS ULONG, _
      ret AS LONG

    CALLDLL #advapi32, "RegCreateKeyExA", _HKEY_CLASSES_ROOT AS ULONG, _
      ProgID$ + "\shell\Open\command" AS PTR, 0 AS LONG, "" AS PTR, _
      0 AS LONG, _KEY_WRITE AS LONG, 0 AS LONG, key AS STRUCT, _
      0 AS LONG, ret AS LONG
    IF ret THEN NOTICE "RegCreateKeyEx failed (Command)" : END

    CALLDLL #advapi32, "RegSetValueExA", key.handle.struct AS ULONG, _
      "" AS PTR, 0 AS LONG, _REG_SZ	AS LONG, _
      Command$ AS PTR, CommandLen AS LONG, ret AS LONG
    IF ret THEN NOTICE "RegSetValueEx failed (Command)" : END

    CALLDLL #advapi32, "RegCloseKey", key.handle.struct AS ULONG, _
      ret AS LONG 

Richard.
User IP Logged

datwill
Guest
xx Re: Associating files?
« Reply #2 on: May 11th, 2015, 6:56pm »

on May 11th, 2015, 5:13pm, Richard Russell wrote:
You are quite right that the LB Community Forum forbids the discussion of Registry access (ridiculous, in my opinion, since it is no more 'dangerous' than many other things that are permitted there).


I've heard you say that before! wink laugh
And thanks a lot for the code and I will take a look at it right away!
User IP Logged

datwill
Guest
xx Re: Associating files?
« Reply #3 on: May 11th, 2015, 7:27pm »

It doesn't seem to be working sad The first function returns an error cry
User IP Logged

RobM
Junior Member
ImageImage


member is offline

Avatar




PM


Posts: 91
xx Re: Associating files?
« Reply #4 on: May 11th, 2015, 11:11pm »

Did you try running it as an admin as Richard said you must do? If not you will get an 'access denied' error.
« Last Edit: May 11th, 2015, 11:12pm by RobM » User IP Logged

datwill
Guest
xx Re: Associating files?
« Reply #5 on: May 12th, 2015, 08:47am »

I know, I just remembered last night as I was going to bed, I'll make an app and run as admin (even though I am one on my own computer...)
User IP Logged

Richard Russell
Administrator
ImageImageImageImageImage


member is offline

Avatar




Homepage PM


Posts: 1348
xx Re: Associating files?
« Reply #6 on: May 12th, 2015, 09:28am »

on May 12th, 2015, 08:47am, Daniel Atwill wrote:
I'll make an app and run as admin

You don't have to make an EXE to test it - you can run LBB 'as administrator' and do it that way (although it would be wise to quit LBB as soon as you have finished testing so you don't leave it running with admin privileges for too long).

Richard.
User IP Logged

datwill
Guest
xx Re: Associating files?
« Reply #7 on: May 12th, 2015, 10:32am »

OK!
Also, I've tried to look up ways of finding out a users status (i.e. Admin or not), and I got as far as finding a user name... I'll keep looking in MSDN but do you know how to do this?

EDIT: Would GetTrusteeTypeA fit my need? MSDN
Quote:
The GetTrusteeType function retrieves the trustee type from the specified TRUSTEE structure. This value indicates whether the trustee is a user, a group, or the trustee type is unknown.

I've found a whole list of security API calls, but don't know which one to use huh
https://msdn.microsoft.com/en-us/library/windows/desktop/aa446674%28v=vs.85%29.aspx
« Last Edit: May 12th, 2015, 10:50am by datwill » User IP Logged

Richard Russell
Administrator
ImageImageImageImageImage


member is offline

Avatar




Homepage PM


Posts: 1348
xx Re: Associating files?
« Reply #8 on: May 12th, 2015, 11:35am »

on May 12th, 2015, 10:32am, Daniel Atwill wrote:
I've tried to look up ways of finding out a users status (i.e. Admin or not)

Code:
    CALLDLL #shell32, "IsUserAnAdmin", admin AS LONG
    IF admin THEN
      PRINT "User is an admin"
    ELSE
      PRINT "User is not an admin"
    END IF 

(The function is deprecated, but seems to work in Windows 8.1. It is not available in Windows 2000.)

Richard.
« Last Edit: May 12th, 2015, 11:38am by Richard Russell » User IP Logged

datwill
Guest
xx Re: Associating files?
« Reply #9 on: May 12th, 2015, 4:03pm »

Wow, I didn't know it was that easy...
embarassed I'm a bit ashamed actually...
Thanks
« Last Edit: May 12th, 2015, 4:03pm by datwill » User IP Logged

Pages: 1  Notify Send Topic Print
« Previous Topic | Next Topic »


This forum powered for FREE by Conforums ©
Terms of Service | Privacy Policy | Conforums Support | Parental Controls