Click here to Skip to main content
Click here to Skip to main content
Add your own
alternative version

The Windows Access Control Model Part 4

, 7 Sep 2005
The final article in the access control series presents a guide to the access control editor and its associated ISecurityInformation interface.
filepermsbox-1_11.zip
Filepermsbox-1.11.exe
filepermsbox111.zip
release
FilePermsBox.dll
FilePermsBox.exe
FilePermsBox.Interop.dll
filepermsboxsrc.zip
Frontend
FilePermsBox.exe.manifest
InnoForm.isf
SetupFpms.iss
NetWrapper
FilePermsBox.Interop.tlb
FPermBoxKey.snk
FilePermsBox.Interop.dll
LockKey.ico
FilePermsBoxDLL
165.avi
FilePermsDll.def
FilePermsDll.manifest
FilePermsDll64.def
/**
*	This code is by OShah. all code will have the following licence.
*	Copyright Shexec32. All code bears the following licence:
**/

/**
*	Copyright Shexec32 2004-2005. All rights reserved.
*
*	THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF
*	ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED
*	TO THE IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A
*	PARTICULAR PURPOSE.
**/


#include "stdafx.h"
#pragma managed


namespace ManagedSecurityBoxWrapper {
using namespace System;
using namespace System::Runtime::InteropServices;
using namespace System::Runtime::ConstrainedExecution;

[Guid("3AFB229D-4A38-4d9a-9C80-90BE97B60BD3")]
[ComVisible(true)]
public enum class SeObjectType
{
	Unknown = 0,
	File,
	Service,
	Printer,
	Registry_Key,
	LmShare,
	KernelObject,
	WindowObject,
	DSObject,
	DSObjectAll,
	ProviderDefinedObject,
	WmiGuidObject,
	RegistryWOW6432Key
};



[ComVisible(true)]
[Guid("06560EEC-6207-48d2-BBA9-3AA4AD3EEE72")]
[InterfaceType(ComInterfaceType::InterfaceIsDual)]
public interface class IManagedSecurityBoxWrapper
{
	virtual void COSecurityBox1([In] bool addWritability) = 0;
	virtual void COSecurityBox2([In] System::Windows::Forms::IWin32Window ^theirhWnd, \
		[In] bool addWritability) = 0;
	virtual void COSecurityBox3([In] System::Windows::Forms::IWin32Window ^theirhWnd, \
		[In] SeObjectType seObj, [In] bool addWritability) = 0;
	property array<System::String ^> ^FileNames
	{
		virtual array<System::String ^> ^get() = 0;
		virtual void set(array<System::String ^> ^value) = 0;
	};
};


[ComVisible(true)]
[Guid("7EECD0C7-0B91-4b70-AF20-F8BD5CAC40B3")]
[ClassInterface(ClassInterfaceType::None)]
[ProgId("FilePermsBox.SecurityBox")]
public ref class ManagedSecurityBoxWrapper : public IManagedSecurityBoxWrapper
{/* This wrapper class enables you to use my class from unmanaged code. */
private:
	array<System::String ^> ^fileNamesIn;

	static void MakeArrayBarbarian(array<System::String ^> ^oldClass,
		std::list< const std::basic_string<TCHAR> > &newClass)
	{
		/* Helper class to convert the managed array to an unmanaged collection */
		for(long i = 0; i < oldClass->LongLength; i++)
		{
			std::basic_string<TCHAR> tmpString;
			ManagedSecurityBoxWrapper::MarshalString(oldClass[i], tmpString);
			newClass.push_back(tmpString);
		}
	};


	static void MarshalString ( System::String ^ s, std::basic_string<TCHAR> &os)
	{
		System::IntPtr chars = 
			(Marshal::StringToHGlobalAuto(s));
		os = reinterpret_cast<const TCHAR *>(chars.ToPointer());
		Marshal::FreeHGlobal(chars);
	}


public:
	ManagedSecurityBoxWrapper()
	{
		fileNamesIn = gcnew array<System::String ^>(1);
	};

	ManagedSecurityBoxWrapper(array<System::String ^> ^fNamesCollection)
	{
		this->fileNamesIn = fNamesCollection;
	};


	virtual ~ManagedSecurityBoxWrapper()
	{
	};

	virtual void COSecurityBox3([In] System::Windows::Forms::IWin32Window ^theirhWnd, \
		[In] SeObjectType seObj, [In] bool addWritability)
	{
		/* Convert the cli array into a std::list */
		HWND ParenthWnd = NULL;
		std::list< const std::basic_string<TCHAR> > newClass;
		MakeArrayBarbarian(this->FileNames, newClass);
		if(theirhWnd != nullptr)
		{
			ParenthWnd = static_cast<HWND>(theirhWnd->Handle.ToPointer());
		}
		SE_OBJECT_TYPE seObjNative = static_cast<SE_OBJECT_TYPE>(static_cast<unsigned int>(seObj));
		int dwErr = ::DoSecurityBox(ParenthWnd, seObjNative, newClass, addWritability);
		if(dwErr != TRUE)
		{
			throw gcnew System::ComponentModel::Win32Exception(::GetLastError(),
				_T("This class returned a failure. The user was informed of the error"));
		}
	};

	virtual void COSecurityBox2([In] System::Windows::Forms::IWin32Window ^theirhWnd, [In] bool addWritability)
	{
		this->COSecurityBox3(theirhWnd, SeObjectType::File, addWritability);
	};

	virtual void COSecurityBox1([In] bool addWritability)
	{
		this->COSecurityBox2(nullptr, addWritability);
	};

	property array<System::String ^> ^FileNames
	{
		virtual array<System::String ^> ^get()
		{
			return this->fileNamesIn;
		};
		virtual void set(array<System::String ^> ^value)
		{
			this->fileNamesIn = value;
		};
	};

};

} /* namespace Managed SecurityBoxWrapper */

#pragma unmanaged

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here

Share

About the Author

oshah
Web Developer
United States United States
Mr. Shah is a reclusive C++/C# developer lurking somewhere in the depths of the city of London. He learnt physics at Kings' College London and obtained a Master in Science there. Having earned an MCAD, he teeters on the brink of transitioning from C++ to C#, unsure of which language to jump to. Fortunately, he also knows how to use .NET interop to merge code between the two languages (which means he won't have to make the choice anytime soon).
 
His interests (apart from programming) are walking, football (the real one!), philosophy, history, retro-gaming, strategy gaming, and any good game in general.
 
He maintains a website / blog / FAQ / junk at shexec32.serveftp.net, where he places the best answers he's written to the questions you've asked. If you can find him, maybe you can hire Mr. Shah to help you with anything C++[/CLI]/C#/.NET related Smile | :) .

| Advertise | Privacy | Terms of Use | Mobile
Web04 | 2.8.141223.1 | Last Updated 7 Sep 2005
Article Copyright 2005 by oshah
Everything else Copyright © CodeProject, 1999-2014
Layout: fixed | fluid