Win32 API 日本語リファレンス
ホーム › Storage.DistributedFileSystem › NetDfsRemove

NetDfsRemove

関数
DFS名前空間からリンクまたはターゲットを削除する。
DLLNETAPI32.dll呼出規約winapi対応OSWindows Vista 以降

シグネチャ

// NETAPI32.dll
#include <windows.h>

DWORD NetDfsRemove(
    LPWSTR DfsEntryPath,
    LPWSTR ServerName,   // optional
    LPWSTR ShareName   // optional
);

パラメーター

名前型方向説明
DfsEntryPathLPWSTRin

DFS リンクの汎用名前付け規則 (UNC) パスを指定する文字列へのポインターです。

この文字列は 2 つの形式のいずれかを取ります。1 つ目の形式は次のとおりです。

\\ShareName\DfsName\link_path

ここで ShareName は、スタンドアロン DFS 名前空間をホストするルート ターゲット サーバーの名前、 DfsName は DFS 名前空間の名前、 link_path は DFS リンクです。

2 つ目の形式は次のとおりです。

\\DomainName\DomDfsname\link_path

ここで DomainName は、ドメインベースの DFS 名前空間をホストするドメインの名前、 DomDfsname は DFS 名前空間の名前、 link_path は DFS リンクです。

このパラメーターは必須です。

ServerNameLPWSTRinoptionalリンク ターゲットのサーバー名を指定する文字列へのポインターです。詳細については、 後述の「解説」セクションを参照してください。リンクとすべてのリンク ターゲットを削除する場合は、 このパラメーターに NULL を設定します。
ShareNameLPWSTRinoptionalリンク ターゲットの共有名を指定する文字列へのポインターです。リンクとすべてのリンク ターゲットを削除する場合は、 このパラメーターに NULL を設定します。

戻り値の型: DWORD

公式ドキュメント

DFS 名前空間内の分散ファイル システム (DFS) リンク、または DFS リンクの特定のリンク ターゲットを削除します。特定のリンク ターゲットを削除する場合、そのリンクの最後のリンク ターゲットが削除されると、リンク自体も削除されます。

戻り値

関数が成功した場合、戻り値は NERR_Success です。

関数が失敗した場合、戻り値はシステム エラー コードです。エラー コードの一覧については、 System Error Codes を参照してください。

解説(Remarks)

呼び出し元は、DFS サーバーに対する Administrator 特権を持っている必要があります。管理者特権を必要とする関数の 呼び出しの詳細については、 Running with Special Privileges を参照してください。

リンクからターゲットを削除するために NetDfsRemove を呼び出す場合は、リンクを作成したときに指定したものと 同じターゲット サーバー名を ServerName パラメーターに指定する必要があります。たとえば、ターゲットを リンクに追加したときにターゲット サーバーの DNS 名を指定した場合は、リンクを削除するときにも同じ DNS 名を 指定する必要があります。NetBIOS 名を指定することはできません。

例

次のコード サンプルは、NetDfsRemove 関数の呼び出しによって DFS リンクからターゲットを削除する方法を 示しています。

#include <windows.h>
#include <lm.h>
#include <lmdfs.h>
#include <stdio.h>
#pragma comment(lib, "Netapi32.lib")

void wmain(int argc, wchar_t *argv[])
{
   DWORD res;
   //
   // すべてのパラメーターが必須です。
   //
   if (argc < 4)
      wprintf(L"Syntax: %s DfsEntryPath ServerName ShareName
", argv[0]);
   else
   {
      //
      // NetDfsRemove 関数を呼び出して
      //  DFS リンクを削除します。
      //
      res = NetDfsRemove(argv[1], argv[2], argv[3]);
      //
      // 呼び出し結果を表示します。
      //
      if(res == 0)
         printf("Removed DFS link
");
      else
         printf("Error: %u
", res);
   }
   return;
}
出典・ライセンス: 上記「公式ドキュメント」の内容は Microsoft の Win32 API ドキュメント(MicrosoftDocs/sdk-api)を日本語に翻訳・改変したものです。© Microsoft Corporation. CC BY 4.0 で提供。
Microsoft 公式リファレンス: 英語 (en-us) · 日本語 (ja-jp) · 原文ソース (GitHub)

各言語での呼び出し定義

// NETAPI32.dll
#include <windows.h>

DWORD NetDfsRemove(
    LPWSTR DfsEntryPath,
    LPWSTR ServerName,   // optional
    LPWSTR ShareName   // optional
);
[DllImport("NETAPI32.dll", ExactSpelling = true)]
static extern uint NetDfsRemove(
    [MarshalAs(UnmanagedType.LPWStr)] string DfsEntryPath,   // LPWSTR
    [MarshalAs(UnmanagedType.LPWStr)] string ServerName,   // LPWSTR optional
    [MarshalAs(UnmanagedType.LPWStr)] string ShareName   // LPWSTR optional
);
<DllImport("NETAPI32.dll", ExactSpelling:=True)>
Public Shared Function NetDfsRemove(
    <MarshalAs(UnmanagedType.LPWStr)> DfsEntryPath As String,   ' LPWSTR
    <MarshalAs(UnmanagedType.LPWStr)> ServerName As String,   ' LPWSTR optional
    <MarshalAs(UnmanagedType.LPWStr)> ShareName As String   ' LPWSTR optional
) As UInteger
End Function
' DfsEntryPath : LPWSTR
' ServerName : LPWSTR optional
' ShareName : LPWSTR optional
Declare PtrSafe Function NetDfsRemove Lib "netapi32" ( _
    ByVal DfsEntryPath As LongPtr, _
    ByVal ServerName As LongPtr, _
    ByVal ShareName As LongPtr) As Long
' VBA7前提(PtrSafe)。32bit Office では LongPtr→Long。Integer=16bit / Long=32bit / LongLong=64bit。
import ctypes
from ctypes import wintypes

NetDfsRemove = ctypes.windll.netapi32.NetDfsRemove
NetDfsRemove.restype = wintypes.DWORD
NetDfsRemove.argtypes = [
    wintypes.LPCWSTR,  # DfsEntryPath : LPWSTR
    wintypes.LPCWSTR,  # ServerName : LPWSTR optional
    wintypes.LPCWSTR,  # ShareName : LPWSTR optional
]
require 'fiddle'
require 'fiddle/import'

lib = Fiddle.dlopen('NETAPI32.dll')
NetDfsRemove = Fiddle::Function.new(
  lib['NetDfsRemove'],
  [
    Fiddle::TYPE_VOIDP,  # DfsEntryPath : LPWSTR
    Fiddle::TYPE_VOIDP,  # ServerName : LPWSTR optional
    Fiddle::TYPE_VOIDP,  # ShareName : LPWSTR optional
  ],
  -Fiddle::TYPE_INT)
#[link(name = "netapi32")]
extern "system" {
    fn NetDfsRemove(
        DfsEntryPath: *mut u16,  // LPWSTR
        ServerName: *mut u16,  // LPWSTR optional
        ShareName: *mut u16  // LPWSTR optional
    ) -> u32;
}
// crates: windows-sys provides ready-made bindings for this API.
$sig = @"
[DllImport("NETAPI32.dll")]
public static extern uint NetDfsRemove([MarshalAs(UnmanagedType.LPWStr)] string DfsEntryPath, [MarshalAs(UnmanagedType.LPWStr)] string ServerName, [MarshalAs(UnmanagedType.LPWStr)] string ShareName);
"@
$api = Add-Type -MemberDefinition $sig -Name 'NETAPI32_NetDfsRemove' -Namespace Win32 -PassThru
# $api::NetDfsRemove(DfsEntryPath, ServerName, ShareName)
#uselib "NETAPI32.dll"
#func global NetDfsRemove "NetDfsRemove" sptr, sptr, sptr
; NetDfsRemove DfsEntryPath, ServerName, ShareName   ; 戻り値は stat
; DfsEntryPath : LPWSTR -> "sptr"
; ServerName : LPWSTR optional -> "sptr"
; ShareName : LPWSTR optional -> "sptr"
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。
#uselib "NETAPI32.dll"
#cfunc global NetDfsRemove "NetDfsRemove" wstr, wstr, wstr
; res = NetDfsRemove(DfsEntryPath, ServerName, ShareName)
; DfsEntryPath : LPWSTR -> "wstr"
; ServerName : LPWSTR optional -> "wstr"
; ShareName : LPWSTR optional -> "wstr"
; DWORD NetDfsRemove(LPWSTR DfsEntryPath, LPWSTR ServerName, LPWSTR ShareName)
#uselib "NETAPI32.dll"
#cfunc global NetDfsRemove "NetDfsRemove" wstr, wstr, wstr
; res = NetDfsRemove(DfsEntryPath, ServerName, ShareName)
; DfsEntryPath : LPWSTR -> "wstr"
; ServerName : LPWSTR optional -> "wstr"
; ShareName : LPWSTR optional -> "wstr"
import (
	"golang.org/x/sys/windows"
	"unsafe"
)

var (
	netapi32 = windows.NewLazySystemDLL("NETAPI32.dll")
	procNetDfsRemove = netapi32.NewProc("NetDfsRemove")
)

// DfsEntryPath (LPWSTR), ServerName (LPWSTR optional), ShareName (LPWSTR optional)
r1, _, err := procNetDfsRemove.Call(
	uintptr(unsafe.Pointer(windows.StringToUTF16Ptr(DfsEntryPath))),
	uintptr(unsafe.Pointer(windows.StringToUTF16Ptr(ServerName))),
	uintptr(unsafe.Pointer(windows.StringToUTF16Ptr(ShareName))),
)
_ = err  // syscall.Errno (valid when the call sets last-error)
_ = r1   // DWORD
function NetDfsRemove(
  DfsEntryPath: PWideChar;   // LPWSTR
  ServerName: PWideChar;   // LPWSTR optional
  ShareName: PWideChar   // LPWSTR optional
): DWORD; stdcall;
  external 'NETAPI32.dll' name 'NetDfsRemove';
result := DllCall("NETAPI32\NetDfsRemove"
    , "WStr", DfsEntryPath   ; LPWSTR
    , "WStr", ServerName   ; LPWSTR optional
    , "WStr", ShareName   ; LPWSTR optional
    , "UInt")   ; return: DWORD
●NetDfsRemove(DfsEntryPath, ServerName, ShareName) = DLL("NETAPI32.dll", "dword NetDfsRemove(char*, char*, char*)")
# 呼び出し: NetDfsRemove(DfsEntryPath, ServerName, ShareName)
# DfsEntryPath : LPWSTR -> "char*"
# ServerName : LPWSTR optional -> "char*"
# ShareName : LPWSTR optional -> "char*"
# なでしこ1は32bit・ANSI(Shift_JIS)。文字列=char*(ANSI)、ポインタ/ハンドル=void*(4byte)。
const std = @import("std");

extern "netapi32" fn NetDfsRemove(
    DfsEntryPath: [*c]const u16, // LPWSTR
    ServerName: [*c]const u16, // LPWSTR optional
    ShareName: [*c]const u16 // LPWSTR optional
) callconv(std.os.windows.WINAPI) u32;
proc NetDfsRemove(
    DfsEntryPath: WideCString,  # LPWSTR
    ServerName: WideCString,  # LPWSTR optional
    ShareName: WideCString  # LPWSTR optional
): uint32 {.importc: "NetDfsRemove", stdcall, dynlib: "NETAPI32.dll".}
pragma(lib, "netapi32");
extern(Windows)
uint NetDfsRemove(
    const(wchar)* DfsEntryPath,   // LPWSTR
    const(wchar)* ServerName,   // LPWSTR optional
    const(wchar)* ShareName   // LPWSTR optional
);
ccall((:NetDfsRemove, "NETAPI32.dll"), stdcall, UInt32,
      (Cwstring, Cwstring, Cwstring),
      DfsEntryPath, ServerName, ShareName)
# DfsEntryPath : LPWSTR -> Cwstring
# ServerName : LPWSTR optional -> Cwstring
# ShareName : LPWSTR optional -> Cwstring
# stdcall は 32bit のみ意味を持つ(x64 では無視)。
local ffi = require("ffi")
ffi.cdef[[
uint32_t NetDfsRemove(
    const uint16_t* DfsEntryPath,
    const uint16_t* ServerName,
    const uint16_t* ShareName);
]]
local netapi32 = ffi.load("netapi32")
-- netapi32.NetDfsRemove(DfsEntryPath, ServerName, ShareName)
-- DfsEntryPath : LPWSTR
-- ServerName : LPWSTR optional
-- ShareName : LPWSTR optional
-- 構造体/GUIDへのポインタは cdef が通るよう void* で表記(実型は各引数コメント参照)。値渡し構造体・enum は対応する typedef を cdef に追加すること。
const koffi = require('koffi');
const lib = koffi.load('NETAPI32.dll');
const NetDfsRemove = lib.func('__stdcall', 'NetDfsRemove', 'uint32_t', ['str16', 'str16', 'str16']);
// NetDfsRemove(DfsEntryPath, ServerName, ShareName)
// DfsEntryPath : LPWSTR -> 'str16'
// ServerName : LPWSTR optional -> 'str16'
// ShareName : LPWSTR optional -> 'str16'
// 出力ポインタは koffi.out(...) で包む。構造体は koffi.struct で定義。
const lib = Deno.dlopen("NETAPI32.dll", {
  NetDfsRemove: { parameters: ["buffer", "buffer", "buffer"], result: "u32" },
});
// lib.symbols.NetDfsRemove(DfsEntryPath, ServerName, ShareName)
// DfsEntryPath : LPWSTR -> "buffer"
// ServerName : LPWSTR optional -> "buffer"
// ShareName : LPWSTR optional -> "buffer"
// 文字列引数は "buffer"(NUL 終端のバイト列を Uint8Array で渡す)。
// 値渡し構造体は { struct: [ ...field types... ] } を使用。
<?php
$ffi = FFI::cdef(<<<C
uint32_t NetDfsRemove(
    const uint16_t* DfsEntryPath,
    const uint16_t* ServerName,
    const uint16_t* ShareName);
C, "NETAPI32.dll");
// $ffi->NetDfsRemove(DfsEntryPath, ServerName, ShareName);
// DfsEntryPath : LPWSTR
// ServerName : LPWSTR optional
// ShareName : LPWSTR optional
// 構造体/GUIDへのポインタは cdef が通るよう void* で表記(実型は各引数コメント参照)。値渡し構造体・enum は対応する typedef を cdef に追加すること。
// WINAPI(stdcall): x64 では呼出規約が統一されるため問題なし。x86 では __stdcall 対応のラッパが必要な場合あり。
import com.sun.jna.*;
import com.sun.jna.ptr.*;
import com.sun.jna.win32.StdCallLibrary;
import com.sun.jna.win32.W32APIOptions;

public interface Netapi32 extends StdCallLibrary {
    Netapi32 INSTANCE = Native.load("netapi32", Netapi32.class);
    int NetDfsRemove(
        WString DfsEntryPath,   // LPWSTR
        WString ServerName,   // LPWSTR optional
        WString ShareName   // LPWSTR optional
    );
}
@[Link("netapi32")]
lib LibNETAPI32
  fun NetDfsRemove = NetDfsRemove(
    DfsEntryPath : UInt16*,   # LPWSTR
    ServerName : UInt16*,   # LPWSTR optional
    ShareName : UInt16*   # LPWSTR optional
  ) : UInt32
end
# 構造体/GUID/enum は lib 内に対応する型定義が必要。
# 呼出規約: x64 は規約統一のため OK。x86(32bit)は WINAPI=stdcall だが Crystal の fun に stdcall 付与構文がなく非対応。
import 'dart:ffi';
import 'package:ffi/ffi.dart';

typedef NetDfsRemoveNative = Uint32 Function(Pointer<Utf16>, Pointer<Utf16>, Pointer<Utf16>);
typedef NetDfsRemoveDart = int Function(Pointer<Utf16>, Pointer<Utf16>, Pointer<Utf16>);
final NetDfsRemove = DynamicLibrary.open('NETAPI32.dll')
    .lookupFunction<NetDfsRemoveNative, NetDfsRemoveDart>('NetDfsRemove');
// DfsEntryPath : LPWSTR -> Pointer<Utf16>
// ServerName : LPWSTR optional -> Pointer<Utf16>
// ShareName : LPWSTR optional -> Pointer<Utf16>
// 文字列は package:ffi の "...".toNativeUtf16()/toNativeUtf8() で変換。
{$mode objfpc}{$H+}
function NetDfsRemove(
  DfsEntryPath: PWideChar;   // LPWSTR
  ServerName: PWideChar;   // LPWSTR optional
  ShareName: PWideChar   // LPWSTR optional
): DWORD; stdcall;
  external 'NETAPI32.dll' name 'NetDfsRemove';
import Foreign
import Foreign.C.Types
import Foreign.C.String

foreign import stdcall safe "NetDfsRemove"
  c_NetDfsRemove :: CWString -> CWString -> CWString -> IO Word32
-- DfsEntryPath : LPWSTR -> CWString
-- ServerName : LPWSTR optional -> CWString
-- ShareName : LPWSTR optional -> CWString
-- 要 GHC(Windows)。stdcall は x64 では ccall として扱われる。ブロックする API は safe 呼び出し推奨。
open Ctypes
open Foreign

let netdfsremove =
  foreign "NetDfsRemove"
    ((ptr uint16_t) @-> (ptr uint16_t) @-> (ptr uint16_t) @-> returning uint32_t)
(* DfsEntryPath : LPWSTR -> (ptr uint16_t) *)
(* ServerName : LPWSTR optional -> (ptr uint16_t) *)
(* ShareName : LPWSTR optional -> (ptr uint16_t) *)
(* foreign は cdecl 前提。x64 Windows では WINAPI と一致。構造体は ctypes structure を定義のこと。 *)
(cffi:define-foreign-library netapi32 (t "NETAPI32.dll"))
(cffi:use-foreign-library netapi32)

(cffi:defcfun ("NetDfsRemove" net-dfs-remove :convention :stdcall) :uint32
  (dfs-entry-path (:string :encoding :utf-16le))   ; LPWSTR
  (server-name (:string :encoding :utf-16le))   ; LPWSTR optional
  (share-name (:string :encoding :utf-16le)))   ; LPWSTR optional
; isize/usize(INT_PTR/SIZE_T)は x64 前提で :int64/:uint64。x86 では :int32/:uint32。
use Win32::API;
my $NetDfsRemove = Win32::API::More->new('NETAPI32',
    'DWORD NetDfsRemove(LPCWSTR DfsEntryPath, LPCWSTR ServerName, LPCWSTR ShareName)');
# my $ret = $NetDfsRemove->Call($DfsEntryPath, $ServerName, $ShareName);
# DfsEntryPath : LPWSTR -> LPCWSTR
# ServerName : LPWSTR optional -> LPCWSTR
# ShareName : LPWSTR optional -> LPCWSTR
# 値渡し構造体は pack() した文字列、または Win32::API::Struct を使用。

関連項目

公式の関連項目