Net1.1没有专门封装好的WIN32管理类(2.0就方便多了),分享一下目录共享及权限的方法(网上找了许多都是文不对题的)



权限定义:
[Flags]
   public enum AccessPrivileges : uint{
   FILE_READ_DATA = 0x00000001,
   FILE_WRITE_DATA = 0x00000002,
   FILE_APPEND_DATA = 0x00000004,
   FILE_READ_EA = 0x00000008,
   FILE_WRITE_EA = 0x00000010,
   FILE_EXECUTE = 0x00000020,
   FILE_DELETE_CHILD = 0x00000040,
   FILE_READ_ATTRIBUTES = 0x00000080,
   FILE_WRITE_ATTRIBUTES  = 0x00000100,

   DELETE = 0x00010000,
   READ_CONTROL = 0x00020000,
   WRITE_DAC = 0x00040000,
   WRITE_OWNER = 0x00080000,
   SYNCHRONIZE = 0x00100000,

   ACCESS_SYSTEM_SECURITY = 0x01000000,
   MAXIMUM_ALLOWED = 0x02000000,
   
   GENERIC_ALL = 0x10000000,
   GENERIC_EXECUTE= 0x20000000,
   GENERIC_WRITE = 0x40000000,
   GENERIC_READ = 0x80000000
  }


  [Flags]
   enum AceFlags : uint{
   NonInheritAce = 0,
   ObjectInheritAce = 1,
   ContainerInheritAce = 2,
   NoPropagateInheritAce = 4,
   InheritOnlyAce = 8,
   InheritedAce = 16
  }

  [Flags]
   enum AceType : uint{
   AccessAllowed = 0,
   AccessDenied = 1,
   Audit = 2
  }


流程:

//设置Everyone用户,可以选择其他用户或新建用户
   ManagementClass trustee = new ManagementClass("Win32_Trustee");
   trustee.Properties["Name"].Value = "Everyone";
   trustee.Properties["Domain"].Value = null;
   trustee.Properties["SID"].Value = new byte[]{1,1,0,0,0,0,0,1,0,0,0,0};

//设置只读/运行权限
   ManagementClass ace = new ManagementClass("Win32_ACE");
   ace.Properties["AccessMask"].Value = AccessPrivileges.GENERIC_READ
    | AccessPrivileges.FILE_READ_DATA | AccessPrivileges.FILE_READ_ATTRIBUTES | AccessPrivileges.FILE_READ_EA
    | AccessPrivileges.READ_CONTROL | AccessPrivileges.FILE_EXECUTE;
   ace.Properties["AceFlags"].Value = 3;//AceFlags.ObjectInheritAce | AceFlags.ContainerInheritAce ;
   ace.Properties["AceType"].Value = 0;//AceType.AccessAllowed;
   ace.Properties["Trustee"].Value = trustee;

//修改ACL设置
   ManagementObject secDescriptor = new ManagementClass("Win32_SecurityDescriptor");
   secDescriptor["ControlFlags"] = 4;
   secDescriptor["DACL"] = new ManagementObject[] { ace };


   //设置添加共享
   ManagementClass mc = new ManagementClass("win32_share");
   ManagementBaseObject inParams = mc.GetMethodParameters("Create");
   inParams["Path"] = "f:\\dannyr";
   inParams["Name"] = "share of dannyr";
   inParams["Type"] = 0x0;
   inParams["MaximumAllowed"] = null;      //=null 则用户数连接无限制
   inParams["Description"] = null;
   inParams["Password"] = null;
   inParams["Access"] = secDescriptor;  //=null 则使Everyone拥有完全控制权限

   ManagementBaseObject outParams = mc.InvokeMethod("Create", inParams, null);
   uint returnValue = (uint)outParams.Properties["ReturnValue"].Value;
   string ErrorMessage = null;
   switch (returnValue)
   {
    case 0: //Success
     break;
    case 2: //Access denied
     ErrorMessage = "无权访问";
     break;
    case 8: //Unknown failure
     ErrorMessage = "未知错误";
     break;
    case 9: //Invalid name
     ErrorMessage = "非法的共享名";
     break;
    case 10: //Invalid level
     ErrorMessage = "非法的层次";
     break;
    case 21: //Invalid parameter
     ErrorMessage = "非法的参数";
     break;
    case 22: //Duplicate share
     ErrorMessage = "重复共享";
     break;
    case 23: //Redirected path
     ErrorMessage = "重定向路径";
     break;
    case 24: //Unknown device or directory
     ErrorMessage = "未知的目录";
     break;
    case 25: //Net name not found
     ErrorMessage = "网络名不存在";
     break;
    default:
     break;
   }

posted @ 2008-06-20 17:03 dannyr|一个都不能少! 阅读(1457) | 评论 (1)编辑
Access数据库对于文本和备注类型的数据类型定义(DATA_TYPE)都是为130,无法直接区分,找了N多网页,包括MSDN都没有描述有关COLUMN_FLAGS的说明,还是自己分析一下:

    COLUMN_FLAGS为64位(8字节)的十六进制的值,组合了数据类型和必填字段等信息

其中最后2个字节有效,最后一个字节一直为0x0A,有变化的是最后第二个字节,即:
    对于文本类型的为0x00;备注类型为0x80;
    对于非必填字段为0x40;必填字段为0x60

组合后:
   文本必填:  0x6A
   文本非必填:0x4A
   备注必填:  0xEA
   备注非必填:0xCA
   
最后可以得到COLUMN_FLAGS右移7位后可以区分文本类型和备注类型


DataTable dt = m_OLEDBCon.GetOleDbSchemaTable(
    OleDbSchemaGuid.Columns,
    new object[] {null, null, "表名称", null});

DataRow[] drs = dt.Select("COLUMN_NAME='字段名称'");
if(drs.Length > 0 && Convert.ToInt32(drs[0]["DATA_TYPE"]) == 130) {
    //文本类型
    if ( (Convert.ToInt64(drs[0]["COLUMN_FLAGS"]) >> 7) == 1){
        //=1为备注字段       
    }else{
        //=0为文本字段
    }
}
posted @ 2008-05-22 10:10 dannyr|一个都不能少! 阅读(1755) | 评论 (4)编辑

灰色
posted @ 2008-05-19 09:34 dannyr|一个都不能少! 阅读(113) | 评论 (0)编辑
下面的代码是可以执行,大家都来说说为什么这个程序不会自动退出?
也就是说mian函数执行完毕后,为什么.net不会释放ThreadEx对象?

using System;
using System.Threading;

public class ThreadEx : IDisposable{    
    
private Thread thread;
    
private volatile bool bExit;
    
public ThreadEx(){
        Console.WriteLine(
"ThreadEx output");
        bExit 
= false;
        thread 
= new Thread(OnThread);
        thread.Start();
    }


    
~ThreadEx(){
        Console.WriteLine(
"~ThreadEx output");
        bExit 
= true;
    }


    
private void OnThread(){
        
while(true){
            
if(bExit){
                
break;
            }

            Console.WriteLine(
"Thread output");
            Thread.Sleep(
1000);
        }

        Console.WriteLine(
"Thread exit");
    }


    
private void Close(){
        bExit 
= true;
    }


    
public void Dispose() {
        
// TODO:  添加 ThreadEx.Dispose 实现
        Console.WriteLine("~Dispose output");
        bExit 
= true;
    }


    
static void Main(){
        ThreadEx threadEx 
= new ThreadEx();
    }

}
posted @ 2007-09-28 16:42 dannyr|一个都不能少! 阅读(2247) | 评论 (16)编辑
As is known,in many advanced programming languages(esp. object oriented ones) like c/c++,c#,Java,etc., the function is only one of the programming syntax constructs,unlike that in some pure interpreted programming lanuage such as Javascript,SmallTalk and so on,which are also object oriented,the function itself is a first-class object,however,for example:
 
function Foo() { // note: Foo is an object
    this.sampleMemVar = 123;
    
this.sampleMemFun = function() {}; // create a new function object
    function() {}; // anonymouse function object
    var f = function(){}; // equal to function f() {} declaration,also create new function object
};

 
As a result,foo can behaves in the same way as regular object do,that is to say,foo can have properties,member functions,and can be extended,see below:
 

Foo.prototype.sampleVar 
= 0;
Foo.prototype.sampleFun 
= function(arglist) {}; // prototype is one of the properties of object Foo
Foo.sampleStaticVar = "sample static variable"// static variable
Foo.sampleStaticFun = function() // extend Foo with a static function
var foo = new Foo(); // applying new operator on a function object causing an instance of an Object is created with the members declared in the constructor,i.e.,Foo.
foo.toString(); // inherited from Object
typeof(foo); // you can call typeof operator on foo,where Object is returned
typeof(Foo); // call tpyeof operator on Foo,where Function is returned
printf(Foo.sampleStaticVar);
foo.sampleMemVar 
= 100// access instance variable
Foo.sampleStaticFun(); // call static method
foo.sampleMemFun(); // call instance method

 
No need to enumerate the examples any more. You can see that the function has no much differences from general objects,except that it does inherites from Function on the other hand.
 
Then how about the situation in c/c++,or others?
For example, we have a function,which can perform some action on two operands,and the specified action can only be determined at runtime.Then how to solve this problem?
 
Of course,you can use (memebr) function pointer like:
 
typedef int (*OpFunc)(int left,int right);


 
but you should first know the argument types and return type.
how about template?
 
template<class _Arg1,class _Arg2,class _Result>
_Result(
*OpFunc)(_Arg1 arg1,_Arg2 arg2); // this does not compile

 
You could never use template directly on typedef or object declarations.
Then maybe you want to encapsulate the concept in this way:
 
template<class _Arg1,class _Arg2,class _Result>
class Performer
{
public:
 typedef _Result (
*OpFunc)(_Arg1,_Arg2);
 Performer(OpFunc _opfunc) : m_opfunc(_opfunc)
 {
  _ASSERT(NULL 
!= _opfunc);
 }
 _Result Perform(_Arg1 arg1,_Arg2 arg2)
 {
  
return m_opfunc(arg1,arg2);
 }
private:
 OpFunc m_opfunc;
};

 
Yes,this works. However,function pointer itself is not an object oriented construct,as a result,lack of flexibility and extensibility.
 
Then,if you're familar with c#,you may want to use delegate.
And unlike template in c++,you can apply generic on delegate directly.
 

delegate _Result OpFunc<_Arg1,_Arg2,_Result>(_Arg1 arg1,_Arg2 arg2);
class Performer<_Arg1, _Arg2, _Result>
{
    
private OpFunc<_Arg1, _Arg2, _Result> opfun = null;
    
public Performer(OpFunc<_Arg1, _Arg2, _Result> _opfun)
    {
        
if (null == _opfun) throw new ArgumentException();
        
this.opfun = _opfun;
    }
    
public _Result Perform(_Arg1 arg1, _Arg2 arg2)
    {
        
return opfun(arg1, arg2);
    }
}

 
you can even implement you delegate in c++,only by making a wrapper to any function pointer.
No matter what you do with delegate,you are actually using function pointers,then again,lack of flexibility and extensibility.
 
So, why not use polymorphism?
If we can store the runtime action performer in an object,e.g.,action_performer,and we call the method on this object,where different object has different implementation for that action.
 

template
<class _Arg1,class _Arg2,class _Result>
class PerformerBase
{
public:
 
virtual _Result Perform(_Arg1 arg1,_Arg2 arg2) = 0;
};
template
<class _Arg1,class _Arg2,class _Result>
class AddPerformer : public PerformerBase<_Arg1,_Arg2,_Result>
{
public:
 _Result Perform(_Arg1 arg1,_Arg2 arg2)
 {
  
return arg1 + arg2;
 }
};
template
<class _Arg1,class _Arg2,class _Result>
class MinusPerformer : public PerformerBase<_Arg1,_Arg2,_Result>
{
public:
 _Result Perform(_Arg1 arg1,_Arg2 arg2)
 {
  
return arg1 - arg2;
 }
};

 
Yes,this also works and we can gain much flexibility and extensibility from this solution.
Then if we we can use function object as we do in Javascript,we can gain much more.
Forget operator overloading?( return to your c++ textbook for a look:-))
we can obtain a function object by encapsulate the function and overload it call operator,i.e.().
For example,
 
class Functor
{
public:
    
int operator()(int a,int b) { return a + b; }
};
Functor myFuncObj;
int x = myFuncObj(1,2);

 
Quite easy,right?
 
OK,then let's return to our problem,which is now trivial,given below:
 
template<class _Arg1,class _Arg2,class _Result>
class FunctorBase
{
public:
 
virtual _Result operator()(_Arg1 arg1,_Arg2 arg2) = 0;
};
template
<class _Arg1,class _Arg2,class _Result>
class AddFunctor : public FunctorBase<_Arg1,_Arg2,_Result>
{
public:
 _Result 
operator()(_Arg1 arg1,_Arg2 arg2)
 {
  
return arg1 + arg2;
 }
};
template
<class _Arg1,class _Arg2,class _Result>
class MinusFunctor : public FunctorBase<_Arg1,_Arg2,_Result>
{
public:
 _Result 
operator()(_Arg1 arg1,_Arg2 arg2)
 {
  
return arg1 - arg2;
 }
};
template
<class _Arg1,class _Arg2,class _Result>
class Performer
{
public:
 Performer(FunctorBase
<_Arg1,_Arg2,_Result> & functor)
  : m_functor(functor)
 {
 }
 _Result Perform(_Arg1 arg1,_Arg2 arg2)
 {
  
return m_functor(arg1,arg2);
 }
private:
 FunctorBase
<_Arg1,_Arg2,_Result> & m_functor;
};

 
In conclusion, you can implement your own specific function object(functor) even in c++,c#,etc.,then you can use function as general objects in your program with high flexibility,resuability and extensibility. Actually, if you look into the STL,you will find that many functions receive a functor as a parameter,e.g.,find_if in <algorithm> receives a predictor as a searching criteria. see declaration below:
 
template<class InputIterator, class Predicate>
   InputIterator find_if(
      InputIterator _First,
      InputIterator _Last,
      Predicate _Pred
   );

 
then you can call like this:
int arr[] = {1,2,3,4,5};
int * found = find_if(arr,arr + _countof(arr),greater<int>(2)); // find element that is greater thatn 2.
 

functors are declared in <functional> in STL.

posted @ 2007-09-15 08:03 dannyr|一个都不能少! 阅读(197) | 评论 (0)编辑
//GridView属性设置:
GridView.OptionsView.GroupDrawMode = GroupDrawMode.Office2003;
GridView.OptionsView.ShowVertLines 
= true;

//GridColumn分组列属性设置:
GridColumn.GroupIndex = 0;
GridColumn.GroupInterval 
= ColumnGroupInterval.DateRange;

//GridControl数据绑定后,设置GridView
gvReserve.SetRowExpanded(-1true);
gvReserve.SetRowExpanded(
-2true);

a.JPG
posted @ 2007-08-06 13:27 dannyr|一个都不能少! 阅读(792) | 评论 (5)编辑
   frm.MdiParent = this;
   
//frm.WindowState = FormWindowState.Maximized;
   frm.Dock = DockStyle.Fill;   //设置为ChildForm和MainForm一起拉伸
   frm.FormBorderStyle = FormBorderStyle.None;
   
this.Client_Event += new Message_Event(frm.OnClientEvent);
   frm.m_Operator 
= m_Operator;
   
return frm;
posted @ 2007-07-27 15:06 dannyr|一个都不能少! 阅读(459) | 评论 (0)编辑
DevExpress.XtraEditors.ComboBoxEdit
下拉框是否允许输入
Properties.TextEditStyle = DevExpress.XtraEditors.Controls.TextEditStyles.DisableTextEditor
posted @ 2007-07-24 11:43 dannyr|一个都不能少! 阅读(192) | 评论 (0)编辑
var firefox = document.getElementById && !document.all;


IE浏览器和FireFox浏览器都有getElementById方法,而FireFox没有document.all方法,因此当上面firefox变量为false说明为IE浏览器。
posted @ 2007-07-06 11:22 dannyr|一个都不能少! 阅读(457) | 评论 (0)编辑
posted @ 2007-01-17 16:10 dannyr|一个都不能少! 阅读(560) | 评论 (1)编辑

下载:

http://www.adobe.com/cfusion/entitlement/index.cfm?e=labs_spry

 

Changes for Spry PreRelease 1.4 - 2006/12/14

  • Data
    • Added function Spry.Utils.serializeObject() for serializing a JS Object into JSON format.
    • Added Spry.XML.nodeToObject() and Spry.XML.documentToObject() utility methods which allow developers to access XML data as JS properties on an object in a manner which is similar to E4X.
    • Added Spry.Utils.updateContent() for dynamically loading an HTML fragment into an element.
    • Added Spry.Utils.setInnerHTML() for setting the innerHTML of an element and executing any scripts within the content string. This method is now used by Spry regions when regenerating their content.
    • Added support for mapping a region state name to another state name. This can be useful for overriding the built-in states, like "ready", "loading", and "error", so that they use markup from a custom state when they fire.
    • Added support for more attributes:
      • spry:even - Conditionally adds the user specified CSS class name to an element based on the current row number used at the time that element was re-generated.
      • spry:odd - Conditionally adds the user specified CSS class name to an element based on the current row number used at the time that element was re-generated.
      • spry:setrow - Attaches a non-destructive onclick handler that sets the current row by row ID.
      • spry:setrownumber - Attaches a non-destructive onclick handler that sets the current row by row number.
      • spry:sort - Attaches a non-destructive onclick handler that sorts a specific data set based on columns specified by the user.
      • spry:readystate - Maps the "ready" state name to the name specified in its value.
      • spry:errorstate - Maps the "error" state name to the name specified in its value.
      • spry:loadingstate - Maps the "loading" state name to the name specified in its value.
    • Added code to report and error when nested regions and detail regions are detected.
    • Added new methods to the DataSet API:
      • getRowCount()
      • getRowByID()
      • getRowByRowNumber()
      • findRowsWithColumnValues()
  • Effects
    • Minor updates of documentation (effects_api and effects_coding, especially of the allowed elements to which the effects can be applied to).
    • Fixed bugs:
      • GrowShrink effect: if border is set, width&height style doesn't get reset to the original value after you toggled the target element
      • GrowShrink effect: text size inside the target element is alternated after the effect has been finished
      • Slide and Blind effect: Scrollbar disappears if overflow:scroll is set and you toggle the element
      • GrowShrink effect: nested image elements doesn't grow if you grow the target element
      • Slide effect: Text inside sliding element doesn't appear once you toggle the effect (IE 7 only)
      • Shake effect: doesn't work perperly in Opera 9.0
      • AppearFade effect: not working for content of a <div> inside a <td> (IE only)
    • new feature:
      • GrowShrink effect: added options 'referHeight' and 'growCenter'
    • IE 7 related fixes also take effect on Windows Vista (not only on XP)
    • new feature:
      • Slide effect: added option 'horizontal' to allow horizontal sliding
    • Slightly updated documentation to reflect new slide option
    • Simplified cluster construction: cluster now is an effect, too, which accepts setup and finish callbacks as option arguments of its constructor
    • Base effects (like Move, Size, etc.) can be called without from argument. Instead of passing element, fromPos, toPos, options as arguments, the effects can be called with element, toPos, options. The fromPos is calculated on the fly based on the current position.
    • AppearFade, Blind, GrowShrink, Slide and Squish effects now can be triggered for initially invisible elements ('display:none' or 'visibility:hidden')
  • Widgets
    • Added Menu Bar widget
    • Added Tabbed Panels widget
    • Added Collapsible Panel widget
    • Added Form Validation Widgets
    • Accordion:
      • Added support for variable height panels.
      • Added some new constructor options:
        • useFixedHeightPanels - This value is true by default. If false allows for variable height panels.
        • fixedPanelHeight - Number of pixels to use as the height of each panel when animating. By default this is the same as the first open panel.
        • duration - Number of milliseconds it takes to open/close a panel. Default is 500 msecs.
      • Fixed bug that prevented panels from animating properly when the accordion started out with a display:none style.
      • Removed addNewPanel(), getNewPanelSnippet(), getNewAccordionSnippet(), and getNewAccordionConstructorSnippet() methods. They don't work cross-browser, and should've never seen the light of day.
  • Docs
    • Added overview for Tabbed Panels widget.
    • Added overview for Collapsible Panel widget.
    • Added overview docs for each Form widget.
  • Demos
    • Gallery
      • Switch from using an interval timer to manually firing off the slide show timer after each image loads. This will allow images loading over slow connections to completely load.
    • Products
      • index.html to use spry:sort and spry:setrow.
      • Use a spry:choose attribute to show/preserve the currently selected product on initial load and after a sort.
    • RSS Reader
      • Modified index.{html,cfm,php} to use spry:setrow.
    • Added Form Validation demo.
  • Samples
    • Added sample for Tabbed Panels widget.
    • Added sample for Collapsible Panel widget.
    • Added samples for 4 Form widgets.
    • Moved data set and region examples to the samples/data_region folder.
    • Changed Effects sample files to use standard samples.css file.
    • Added a samples/utils folder with samples of Spry utility functions.
    • Released a query-to-XML sample page that shows how to convert dynamic data into XML.
    • Added to EvenOddRowSample.html to include spry:even and spry:odd.
    • Added SprySetRowSample.html.
    • Modified the AccordionSample:
      • Added sample for changing the duration of animations.
      • Modified variable height accordion sample to use animation.
      • Added a style for spans used as content panels so that they animate properly.
    • Added SetCurrentRowByValueSample.html to show how to select a row based on some column values.
    • Added StateMappingSample.html to show how to map the built-in region states to your own custom states.
posted @ 2006-12-20 09:48 dannyr|一个都不能少! 阅读(481) | 评论 (0)编辑