⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 srcsharing.cpp

📁 这是一个远程控制程序
💻 CPP
字号:
//---------------------------------------------------------------------------
#include <vcl.h>
#pragma hdrstop

#include "srcSharing.h"

//---------------------------------------------------------------------------
#pragma package(smart_init)
//=============share info======
__fastcall ShareResource::ShareResource()
{
        FAccessType     = SHI50F_RDONLY;
        FComment        = "";
        FReadOnlyPassword  = "";
        FReadWritePassword = "";
        FResourcePath   = "";
        FResourceType   = STYPE_DISKTREE;
        FServerName     = "";
        FShareName      = "";
        OnError         = NULL;

        DLLHandle = (HANDLE)LoadLibrary("SVRAPI.DLL"); //Win9x

        if( DLLHandle )
        {
                NetShareAdd     = (int (__stdcall*)(char *,short,void *,unsigned short))GetProcAddress(DLLHandle, "NetShareAdd");
                NetShareDel     = (int (__stdcall*)(char *,char *,WORD))GetProcAddress(DLLHandle, "NetShareDel");
                NetShareGetInfo = (int (__stdcall*)(char *,char *,short,void *,WORD,WORD &))GetProcAddress(DLLHandle, "NetShareGetInfo");
                NetShareSetInfo = (int (__stdcall*)(char *,char *,short,void *,WORD,short int))GetProcAddress(DLLHandle, "NetShareSetInfo");
        }
}
__fastcall ShareResource::~ShareResource()
{
        if( DLLHandle )
        {
                FreeLibrary(DLLHandle);
                DLLHandle = NULL;
        }
}
bool __fastcall ShareResource::IsShared(void)
{
        Share_Info50 siShare;
        int Err;
        Word AmountUsed;
        if( DLLHandle )
        {
                Err = NetShareGetInfo(FServerName.UpperCase().c_str(),FShareName.UpperCase().c_str(),50,&siShare,512,AmountUsed);
        }
        else if( OnError)
        {
                OnError(NERR_DLLNotLoaded,GetNetErrorString(NERR_DLLNotLoaded));
        }
        return (Err == 0? true : false);
}
int __fastcall ShareResource::LoadShareInfo(AnsiString _ServerName, AnsiString _ShareName)
{
        Share_Info50 siShare;
        int Err;
        Word AmountUsed;
        if( DLLHandle )
        {
                Err = NetShareGetInfo((_ServerName.UpperCase()).c_str(),(_ShareName.UpperCase()).c_str(),50,&siShare,512,AmountUsed);
                if( !Err )
                {
                        FServerName     = ServerName;
                        FShareName      = siShare.shi50_netname;
                        FResourceType   = siShare.shi50_type;

                        if ((siShare.shi50_flags & SHI50F_DEPENDSON1) == SHI50F_DEPENDSON1)
                        {
                                FAccessType = SHI50F_DEPENDSON1;
                        }
                        else if ((siShare.shi50_flags & SHI50F_RDONLY) == SHI50F_RDONLY)
                        {
                                FAccessType = SHI50F_RDONLY;
                        }
                        else if ((siShare.shi50_flags & SHI50F_FULL) == SHI50F_FULL)
                        {
                                FAccessType = SHI50F_FULL;
                        }

                        FComment                = siShare.shi50_remark;
                        FResourcePath           = siShare.shi50_path;
                        FReadOnlyPassword       = siShare.shi50_ro_password;
                        FReadWritePassword      = siShare.shi50_rw_password;
                }
                else if( OnError )
                {
                        OnError(Err,GetNetErrorString(Err));
                }
        }
        else if( OnError )
        {
                OnError(NERR_DLLNotLoaded,GetNetErrorString(NERR_DLLNotLoaded));
        }
        return Err;
}
int __fastcall ShareResource::Share(void)
{
        Word Flags;
        Share_Info50 siShare;
        int Err;

        Flags = 0;

        Flags = Flags | FAccessType;

//        FShareName = FShareName.UpperCase();
        FResourcePath = FResourcePath.UpperCase();

        strncpy(siShare.shi50_netname,FShareName.c_str(),13);

        siShare.shi50_flags  = Flags;
        siShare.shi50_type   = FResourceType;

        siShare.shi50_remark = FComment.c_str();
        siShare.shi50_path   = FResourcePath.c_str();

        strncpy(siShare.shi50_rw_password,FReadWritePassword.c_str(),9);
        strncpy(siShare.shi50_ro_password,FReadOnlyPassword.c_str(),9);
        if( DLLHandle )
        {
                Err = NetShareAdd(FServerName.UpperCase().c_str(),50,&siShare,sizeof(siShare));
        }
        else
        {
                Err = NERR_DLLNotLoaded;
        }

        if( Err && OnError)
        {
                OnError(Err,GetNetErrorString(Err));
        }
        return Err;
 }
int __fastcall ShareResource::Unshare(void)
{
        int Err;
        if( DLLHandle )
        {
                Err = NetShareDel(FServerName.UpperCase().c_str(),FShareName.UpperCase().c_str(),0);
        }
        else
        {
                Err = NERR_DLLNotLoaded;
        }
        if( Err && OnError)
        {
                OnError(Err,GetNetErrorString(Err));
        }
        return Err;
}
int __fastcall ShareResource::Update(void)
{
        int Err;
        if( IsShared())
        {
                if( (Err = Unshare()) == 0 );
                {
                        Err = Share();
                }
        }
        else
        {
                Err = NERR_NetNameNotFound;
        }
        if(Err && OnError)
        {
                OnError(Err,GetNetErrorString(Err));
        }
        return Err;
}

void __fastcall ShareResource::SetAccessType(TAccessType value)
{
        //TODO: Add your source code here
        if (value == ATReadOnly)
        {
                FAccessType = SHI50F_RDONLY;
        }
        else if (value == ATFull)
        {
                FAccessType = SHI50F_FULL;
        }
        else    FAccessType = SHI50F_DEPENDSON1;
}

Word __fastcall ShareResource::GetAccessType()
{
        //TODO: Add your source code here
        if (FAccessType == SHI50F_RDONLY)
        {
                FAccessType = ATReadOnly;
        }
        else if( FAccessType == SHI50F_FULL)
        {
                FAccessType = ATFull;
        }
        else
        {
                FAccessType = ATDepends;
        }
        return FAccessType;
}

void __fastcall ShareResource::SetComment(AnsiString value)
{
        //TODO: Add your source code here
        if( FComment != value)
        {
                FComment = value;
        }
}

AnsiString __fastcall ShareResource::GetComment()
{
        //TODO: Add your source code here
        return FComment;
}

void __fastcall ShareResource::SetReadOnlyPassword(AnsiString value)
{
        //TODO: Add your source code here
        if( FReadOnlyPassword != value)
        {
                FReadOnlyPassword = value;
        }
}

AnsiString __fastcall ShareResource::GetReadOnlyPassword()
{
        //TODO: Add your source code here
        return FReadOnlyPassword;
}

void __fastcall ShareResource::SetReadWritePassword(AnsiString value)
{
        if(FReadWritePassword != value) {
                FReadWritePassword = value;
        }
}

AnsiString __fastcall ShareResource::GetReadWritePassword()
{
        return FReadWritePassword;
}

void __fastcall ShareResource::SetResourcePath(AnsiString value)
{
        if(FResourcePath != value) {
                FResourcePath = value;
        }
}

AnsiString __fastcall ShareResource::GetResourcePath()
{
        return FResourcePath;
}

void __fastcall ShareResource::SetResourceType(TResrcType value)
{
        if (value == RTPrinter)
        {
                FResourceType = STYPE_PRINTQ;
        }
        else    FResourceType = STYPE_DISKTREE;
}

TResrcType __fastcall ShareResource::GetResourceType()
{
        if (FResourceType == STYPE_PRINTQ)
        {
                return RTPrinter;
        }
        else    return RTFolder;
}

void __fastcall ShareResource::SetServerName(AnsiString value)
{
        if(FServerName != value) {
                FServerName = value;
        }
}

AnsiString __fastcall ShareResource::GetServerName()
{
        return FServerName;
}

void __fastcall ShareResource::SetShareName(AnsiString value)
{
        if(FShareName != value) {
                FShareName = value;
        }
}

AnsiString __fastcall ShareResource::GetShareName()
{
        return FShareName;
}


⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -