Jump to content

Sky Slate Blueberry Blackcurrant Watermelon Strawberry Orange Banana Apple Emerald Chocolate
Photo

FileGet/Set or FileGetProperties


  • Please log in to reply
28 replies to this topic
majkinetor
  • Moderators
  • 4512 posts
  • Last active: May 20 2019 07:41 AM
  • Joined: 24 May 2006
You missed.

http://www.autohotke... ... M_Wrappers
Posted Image

Tekl
  • Members
  • 814 posts
  • Last active: May 03 2009 03:28 PM
  • Joined: 24 Sep 2004
Ahh ... very great. Thanks for that.
Tekl

raven-gm
  • Members
  • 44 posts
  • Last active: Nov 20 2011 09:40 AM
  • Joined: 25 Mar 2007
So wait...
We'd just need to find someone who knows COM well enough to show us how to use it for file get/set properties in ahk?

BoBo
  • Guests
  • Last active:
  • Joined: --

We'd just need to find someone who knows COM well enough to show us how to use it for file get/set properties in ahk´?

So you're now out for hunting? Good luck :)

raven-gm
  • Members
  • 44 posts
  • Last active: Nov 20 2011 09:40 AM
  • Joined: 25 Mar 2007

We'd just need to find someone who knows COM well enough to show us how to use it for file get/set properties in ahk´?

So you're now out for hunting? Good luck :)

K, to be more specific...
From what I've seen/heard, ahk runs off of c++.
So I should find someone who can do COM in c++, or find a way to recieve and/or edit metadata in c++ at all?
I would like to think that I know what I'm doing, but there's just to much stuff I've yet to learn...

Sean
  • Members
  • 2462 posts
  • Last active: Feb 07 2012 04:00 AM
  • Joined: 12 Feb 2007

CACLS is no solution as it is language dependent: http://www.autohotke... ... datacommon

Although I have a little experience with a securable object, I have currently little time to delve further into this big subject. So, I just wrote a script to convert between name and SID. So, you may use it with cacls.exe until AHK natively supports the functions.

MsgBox % sName := LookupAccountSid("S-1-1-0")
MsgBox % sSid  := LookupAccountName(sName)


LookupAccountName(sName, sSystem = "")
{
	DllCall("advapi32\LookupAccountNameA", "str", sSystem, "str", sName, "Uint", 0, "UintP", nSizeSID, "Uint", 0, "UintP", nSizeRDN, "UintP", eUser)
	VarSetCapacity(SID, nSizeSID, 0)
	VarSetCapacity(RDN, nSizeRDN, 0)
	DllCall("advapi32\LookupAccountNameA", "str", sSystem, "str", sName, "str", SID, "UintP", nSizeSID, "str", RDN, "UintP", nSizeRDN, "UintP", eUser)

	DllCall("advapi32\ConvertSidToStringSidA", "str", SID, "UintP", pString)
	VarSetCapacity(sSid, DllCall("lstrlen", "Uint", pString))
	DllCall("lstrcpy", "str", sSid, "Uint", pString)
	DllCall("LocalFree", "Uint", pString)
	Return sSid
}

LookupAccountSid(sSid, sSystem = "")
{
	DllCall("advapi32\ConvertStringSidToSidA", "str", sSid, "UintP", pSid)

	DllCall("advapi32\LookupAccountSidA", "str", sSystem, "Uint", pSid, "Uint", 0, "UintP", nSizeNM, "Uint", 0, "UintP", nSizeRD, "UintP", eUser)
	VarSetCapacity(sName, nSizeNM, 0)
	VarSetCapacity(sRDmn, nSizeRD, 0)
	DllCall("advapi32\LookupAccountSidA", "str", sSystem, "Uint", pSid, "str", sName, "UintP", nSizeNM, "str", sRDmn, "UintP", nSizeRD, "UintP", eUser)

	DllCall("LocalFree", "Uint", pSid)
	Return sName
}
BTW, if the name contains accented characters, you may also need to convert it to OEM codepage using Ansi2Oem() in
http://www.autohotke...topic17343.html

toralf
  • Moderators
  • 4035 posts
  • Last active: Aug 20 2014 04:23 PM
  • Joined: 31 Jan 2005
Thanks Sean,
these are exactly the functions I was looking for for a different project. Thanks for sharing. Since these are very basic and useful functions I suggest to post them in the functions section of this forum too.
Ciao
toralf
 
I use the latest AHK version (1.1.15+)
Please ask questions in forum on ahkscript.org. Why?
For online reference please use these Docs.

Sean
  • Members
  • 2462 posts
  • Last active: Feb 07 2012 04:00 AM
  • Joined: 12 Feb 2007

Thanks Sean,
these are exactly the functions I was looking for for a different project. Thanks for sharing. Since these are very basic and useful functions I suggest to post them in the functions section of this forum too.

Thanks. I've done it.

Tekl
  • Members
  • 814 posts
  • Last active: May 03 2009 03:28 PM
  • Joined: 24 Sep 2004
Where have I to user Ansi2Oem? LookupAccountSid or LookupAccountName?
Tekl

Sean
  • Members
  • 2462 posts
  • Last active: Feb 07 2012 04:00 AM
  • Joined: 12 Feb 2007

Where have I to user Ansi2Oem? LookupAccountSid or LookupAccountName?

Like this:

sName := Ansi2Oem(LookupAccountSid("S-1-1-0"))
Then, use sName with cacls.exe.

raven-gm(but not logged i
  • Guests
  • Last active:
  • Joined: --
Alright, went through and read it.

I don't know enough c++ (Or any COM), but the example provided
http://msdn2.microso...y/aa380387.aspx
looks comprehendable.
Anyone who knows what they're talking about want to take a look?

raven-gm
  • Members
  • 44 posts
  • Last active: Nov 20 2011 09:40 AM
  • Joined: 25 Mar 2007
(oops, I suppose I should say that "it" is the link that majkinetor provided:
http://msdn2.microso...y/aa379968.aspx )

And the example code looks like this:
//+===================================================================
//
//      To build:
//      cl /GX WriteRead.cpp
//
//+===================================================================


#define WIN32_LEAN_AND_MEAN
#define UNICODE
#define _UNICODE

#include <stdio.h>
#include <windows.h>
#include <ole2.h>

// Implicitly link ole32.dll
#pragma comment( lib, "ole32.lib" )


// From uuidgen.exe:
const FMTID fmtid = { /* d170df2e-1117-11d2-aa01-00805ffe11b8 */
    0xd170df2e,
    0x1117,
    0x11d2,
    {0xaa, 0x01, 0x00, 0x80, 0x5f, 0xfe, 0x11, 0xb8}
  };


EXTERN_C void wmain()
{
   HRESULT hr = S_OK;
   IPropertySetStorage *pPropSetStg = NULL;
   IPropertyStorage *pPropStg = NULL;
   WCHAR *pwszError = L"";
   PROPSPEC propspec; 
   PROPVARIANT propvarWrite; 
   PROPVARIANT propvarRead;

   try
   {

        // Create a file and a property set within it.

        hr = StgCreateStorageEx( L"WriteRead.stg",
                   STGM_CREATE|STGM_SHARE_EXCLUSIVE|STGM_READWRITE,
                   STGFMT_STORAGE,
                   // STGFMT_STORAGE => Structured Storage 
                                     // property sets
                   // STGFMT_FILE    => NTFS file system 
                                     // property sets
                   0, NULL, NULL,
                   IID_IPropertySetStorage,
                   reinterpret_cast<void**>(&pPropSetStg) );
        if( FAILED(hr) ) throw L"Failed StgCreateStorageEx";

        hr = pPropSetStg->Create( fmtid, NULL, PROPSETFLAG_DEFAULT, 
                    STGM_CREATE|STGM_READWRITE|STGM_SHARE_EXCLUSIVE,
                    &pPropStg );
        if( FAILED(hr) ) throw L"Failed IPropertySetStorage::Create";

        // Write a Unicode string property to the property set

        propspec.ulKind = PRSPEC_LPWSTR;
        propspec.lpwstr = L"Property Name";

        propvarWrite.vt = VT_LPWSTR;
        propvarWrite.pwszVal = L"Property Value";

        hr = pPropStg->WriteMultiple( 1, &propspec, &propvarWrite, 
                                      PID_FIRST_USABLE );
        if( FAILED(hr) ) 
            throw L"Failed IPropertyStorage::WriteMultiple";

        // Not required, but give the property set a friendly 
        // name.

        PROPID propidDictionary = PID_DICTIONARY;
        WCHAR *pwszFriendlyName = 
                     L"Write/Read Properties Sample Property Set";
        hr = pPropStg->WritePropertyNames( 1, &propidDictionary, 
                                           &pwszFriendlyName );
        if( FAILED(hr) ) 
            throw L"Failed IPropertyStorage::WritePropertyNames";

        // Close and reopen everything.
        // By using the STGFMT_ANY flag in the StgOpenStorageEx call,
        // it does not matter if this is a Structured Storage 
        // property set or an NTFS file system property set 
        // (for more information see the StgCreateStorageEx 
        // call above).

        pPropStg->Release(); pPropStg = NULL;
        pPropSetStg->Release(); pPropSetStg = NULL;

        hr = StgOpenStorageEx( L"WriteRead.stg",
                             STGM_READ|STGM_SHARE_DENY_WRITE,
                             STGFMT_ANY,
                             0, NULL, NULL, 
                             IID_IPropertySetStorage,
                             reinterpret_cast<void**>(&pPropSetStg) );
        if( FAILED(hr) ) 
            throw L"Failed StgOpenStorageEx";

        hr = pPropSetStg->Open( fmtid, STGM_READ|STGM_SHARE_EXCLUSIVE,
                                &pPropStg );
        if( FAILED(hr) ) 
            throw L"Failed IPropertySetStorage::Open";

        // Read the property back and validate it

        hr = pPropStg->ReadMultiple( 1, &propspec, &propvarRead );
        if( FAILED(hr) ) 
            throw L"Failed IPropertyStorage::ReadMultiple";

        if( S_FALSE == hr )
          throw L"Property didn't exist after reopening the 
                                                     property set";
        else if( propvarWrite.vt != propvarRead.vt )
          throw L"Property types didn't match after reopening the 
                                                     property set";
        else if( 0 != wcscmp( propvarWrite.pwszVal, 
                              propvarRead.pwszVal ))
          throw L"Property values didn't match after reopening the 
                                                     property set";
        else
           wprintf( L"Success\n" );

   }
   catch( const WCHAR *pwszError )
   {
       wprintf( L"Error:  %s (hr=%08x)\n", pwszError, hr );
   }

   PropVariantClear( &propvarRead );
			if( pPropStg ) pPropStg->Release();
   if( pPropSetStg ) pPropSetStg->Release();

}

But I don't know how to test it; I don't have a C++ compiler anymore, or the ole32.dll it needs.
I would like to think that I know what I'm doing, but there's just to much stuff I've yet to learn...

dicanus
  • Members
  • 24 posts
  • Last active: Jul 19 2010 09:50 PM
  • Joined: 04 Sep 2007
It's been almost a year, and I was just wondering if any new leaps have been made on this function.

raven-gm
  • Members
  • 44 posts
  • Last active: Nov 20 2011 09:40 AM
  • Joined: 25 Mar 2007
nope! But I switched to reading the IDTB file by hand anyways...
My advice is to switch languages. I had to. Autohotkey is dieing/dead, as sad as it seems, and it might help to have something a little more powerful (such as python) under your belt.

Of course, I still know ahk better, and I really miss it... but it has its limitations.
I would like to think that I know what I'm doing, but there's just to much stuff I've yet to learn...