如何用c#实现添加网上邻居(指定网站、网络位置或FTP站点的位置)

解决方案 »

  1.   

    #ifndef UNICODE
    #define UNICODE
    #endif#include <stdio.h>
    #include <windows.h> 
    #include <lm.h>int wmain(int argc, wchar_t *argv[])
    {
       USER_INFO_1 ui;
       DWORD dwLevel = 1;
       DWORD dwError = 0;
       NET_API_STATUS nStatus;   if (argc != 3)
       {
          fwprintf(stderr, L"Usage: %s \\\\ServerName UserName\n", argv[0]);
          exit(1);
       }
       //
       // Set up the USER_INFO_1 structure.
       //  USER_PRIV_USER: name identifies a user, 
       //    rather than an administrator or a guest.
       //  UF_SCRIPT: required for LAN Manager 2.0 and
       //    Windows NT and later.
       //
       ui.usri1_name = argv[2];
       ui.usri1_password = argv[2];
       ui.usri1_priv = USER_PRIV_USER;
       ui.usri1_home_dir = NULL;
       ui.usri1_comment = NULL;
       ui.usri1_flags = UF_SCRIPT;
       ui.usri1_script_path = NULL;
       //
       // Call the NetUserAdd function, specifying level 1.
       //
       nStatus = NetUserAdd(argv[1],
                            dwLevel,
                            (LPBYTE)&ui,
                            &dwError);
       //
       // If the call succeeds, inform the user.
       //
       if (nStatus == NERR_Success)
          fwprintf(stderr, L"User %s has been successfully added on %s\n",
                   argv[2], argv[1]);
       //
       // Otherwise, print the system error.
       //
       else
          fprintf(stderr, "A system error has occurred: %d\n", nStatus);   return 0;
    }
    给你个c++的 ,C# 可以调用api,原理相同
      

  2.   

    Domain类可以访问,添加就不知道了。。
      

  3.   

     'for windows 2000/xp/2003'Option Explicit
    '変数定義---------------------------------------------------
    dim strNethoodName 'ネットワークプレースの名前を設定
    dim strNethoodPath 'ネットワークプレースの親dirパスを格納(自動で取得)
    dim strNetPlaceDir 'ネットワークプレイス名のフォルダを作るために使用
    dim strNetAddress
    dim FILEIni
    dim F 'desktop.iniの属性変更に仕様
    dim objWshScript
    dim objFilesys
    dim objNethood'ネットワークプレースの名前を設定
    strNethoodName = "microsoft"
    strNetAddress = "http://sccm:1000/sites/document/Administration/20090430D/"'オブジェクトの作成
    set objWshScript = WScript.CreateObject("WScript.Shell")
    set objFilesys = CreateObject("Scripting.FileSystemObject")'ネットワークプレースのパスの取得
    strNethoodPath =objWshScript.SpecialFolders("Nethood")'すでに同じ名前のネットワークプレースが存在したら終了
    strNetPlaceDir = strNethoodPath + "\" + strNethoodNameIf objFilesys.FolderExists (strNetPlaceDir) Then
    msgbox("すでに同じ名前のネットワークプレースが存在しますので、スクリプトを終了します。")
    WScript.quit
    End If 'フォルダ作成
    objFilesys.CreateFolder (strNetPlaceDir)
    'フォルダの属性変更
    ' 1 = ReadOnly, 16 = Folder
    Set F = objFilesys.GetFolder(strNetPlaceDir)
    F.Attributes = 17'target.lnkファイル作成
    set objNethood = objWshScript.CreateShortcut(strNetPlaceDir + "\target.lnk")
    objNethood.TargetPath = strNetAddress
    objNethood.IconLocation = "notepad.exe, 0"
    objNethood.Save
    'target.lnkファイル属性変更
    ' 32 = Archive
    Set F = objFilesys.GetFile(strNetPlaceDir + "\target.lnk")F.Attributes = 32'desktop.iniファイル作成
    Set FILEIni = objFilesys.CreateTextFile(strNetPlaceDir & "\desktop.ini", True)FILEIni.WriteLine("[.ShellClassInfo]") & vbcrlf _
    & ("ComfirmFileOp=0") & vbcrlf _
    & ("CLSID2={0AFACED1-E828-11D1-9187-B532F1E9575D}") & vbcrlf _
    & ("Flags=2")FILEIni.Close
    'desktop.iniファイル属性変更
    ' 2 = Hidden, 4 = System
    Set F = objFilesys.GetFile(strNetPlaceDir & "\desktop.ini")
    F.Attributes = 4