Einzelnen Beitrag anzeigen

Benutzerbild von sk.Silvia
sk.Silvia

Registriert seit: 8. Feb 2006
Ort: Slovenia
90 Beiträge
 
Delphi 7 Personal
 
#4

Re: Restart des Netzweradapters

  Alt 18. Aug 2008, 14:12
buhaaaa wie soll ich dass in Delphi umsetzen?

Delphi-Quellcode:
void ResetAdapter(char * AdapterName) {
  struct _GUID guid = {0xBA126AD1,0x2166,0x11D1,0}
;
  memcpy(guid.Data4, "\xB1\xD0\x00\x80\x5F\xC1\x27\x0E", 8);
  unsigned short * buf = new unsigned short[strlen(AdapterName)+1];
  
  void (__stdcall *NcFreeNetConProperties) (NETCON_PROPERTIES *);
  HMODULE NetShell_Dll = LoadLibrary("Netshell.dll");
  if (!NetShell_Dll) {
    printf("Couldn't load Netshell.dll\n");
    return;
    }

  NcFreeNetConProperties = (void (__stdcall *)(struct tagNETCON_PROPERTIES *))GetProcAddress(NetShell_Dll, "NcFreeNetconProperties");
  if (!NcFreeNetConProperties) {
    printf("Couldn't load required DLL function\n");
    return;
    }


  for (unsigned int i = 0; i <= strlen(AdapterName); i++) {
    buf[i] = AdapterName[i];
    }

  CoInitialize(0);
    INetConnectionManager * pNCM = NULL;
    HRESULT hr = ::CoCreateInstance(guid,
                                     NULL,
                                     CLSCTX_ALL,
                                     __uuidof(INetConnectionManager),
                                     (void**)&pNCM);
    if (!pNCM)
        printf("Failed to instantiate required object\n");
    else {
        IEnumNetConnection * pENC;
        pNCM->EnumConnections(NCME_DEFAULT, &pENC);
        if (!pENC) {
          printf("Could not enumerate Network Connections\n");
          }

        else {
          INetConnection * pNC;
          ULONG fetched;
          NETCON_PROPERTIES * pNCP;
          do {
            pENC->Next(1, &pNC, &fetched);
            if (fetched && pNC) {
              pNC->GetProperties(&pNCP);
              if (pNCP) {
                if (wcscmp(pNCP->pszwName, buf) == 0) {
                  pNC->Disconnect();
                  pNC->Connect();
                  }

                NcFreeNetConProperties(pNCP);
                }
              }
            } while (fetched);
            pENC->Release();
          }
        pNCM->Release();
    }

    FreeLibrary(NetShell_Dll);
    CoUninitialize ();
  }
wie kann man dass in eine unit stecken?
  Mit Zitat antworten Zitat