Chào mừng đến với Diễn đàn lập trình - Cộng đồng lập trình.
Kết quả 1 đến 6 của 6
  1. #1

  2. #2
    Ngày tham gia
    Sep 2015
    Bài viết
    0
    có đọc ở đây
    http://www.codeproject.com/KB/vbscri...select=1350790
    http://www.codeproject.com/KB/system...formation.aspx
    http://social.msdn.microsoft.com/for...-a1f970c1f2d2/

  3. #3
    Ngày tham gia
    Sep 2015
    Bài viết
    0
    có cái này hay hưn [IMG]images/smilies/smile.png[/IMG] http://www.codeprovn.com/forums/view...hp?f=80&t=1187


    Nhìn vào các bài post loạn quá !

  4. #4
    Ngày tham gia
    Sep 2015
    Bài viết
    0
    Mã nguồn PHP:
    #define _WIN32_DCOM#define UNICODE#include <iostream>using namespace std;#include <comdef.h>#include <Wbemidl.h># pragma comment(lib, "wbemuuid.lib")# pragma comment(lib, "credui.lib")# pragma comment(lib, "comsuppw.lib")#include <wincred.h>#include <strsafe.h>int __cdecl main(int argc, char **argv){ HRESULT hres; // Step 1: -------------------------------------------------- // Initialize COM. ------------------------------------------ hres = CoInitializeEx(0, COINIT_MULTITHREADED); if (FAILED(hres)) { cout << "Failed to initialize COM library. Error code = 0x" << hex << hres << endl; return 1; // Program has failed. } // Step 2: -------------------------------------------------- // Set general COM security levels -------------------------- hres = CoInitializeSecurity( NULL, -1, // COM authentication NULL, // Authentication services NULL, // Reserved RPC_C_AUTHN_LEVEL_DEFAULT, // Default authentication RPC_C_IMP_LEVEL_IDENTIFY, // Default Impersonation NULL, // Authentication info EOAC_NONE, // Additional capabilities NULL // Reserved ); if (FAILED(hres)) { cout << "Failed to initialize security. Error code = 0x" << hex << hres << endl; CoUninitialize(); return 1; // Program has failed. } // Step 3: --------------------------------------------------- // Obtain the initial locator to WMI ------------------------- IWbemLocator *pLoc = NULL; hres = CoCreateInstance( CLSID_WbemLocator, 0, CLSCTX_INPROC_SERVER, IID_IWbemLocator, (LPVOID *) &pLoc); if (FAILED(hres)) { cout << "Failed to create IWbemLocator object." << " Err code = 0x" << hex << hres << endl; CoUninitialize(); return 1; // Program has failed. } // Step 4: ----------------------------------------------------- // Connect to WMI through the IWbemLocator::ConnectServer method IWbemServices *pSvc = NULL; // Get the user name and password for the remote computer CREDUI_INFO cui; bool useToken = false; wchar_t pszName[CREDUI_MAX_USERNAME_LENGTH+1] = {0}; wchar_t pszPwd[CREDUI_MAX_PASSWORD_LENGTH+1] = {0}; wchar_t pszDomain[CREDUI_MAX_USERNAME_LENGTH+1]; wchar_t pszUserName[CREDUI_MAX_USERNAME_LENGTH+1]; BOOL fSave; DWORD dwErr; memset(&cui,0,sizeof(CREDUI_INFO)); cui.cbSize = sizeof(CREDUI_INFO); cui.hwndParent = NULL; // Ensure that MessageText and CaptionText identify // what credentials to use and which application requires them. cui.pszMessageText = TEXT("Press cancel to use process token"); cui.pszCaptionText = TEXT("Enter Account Information"); cui.hbmBanner = NULL; fSave = FALSE; dwErr = CredUIPromptForCredentials( &cui, // CREDUI_INFO structure TEXT(""), // Target for credentials NULL, // Reserved 0, // Reason pszName, // User name CREDUI_MAX_USERNAME_LENGTH+1, // Max number for user name pszPwd, // Password CREDUI_MAX_PASSWORD_LENGTH+1, // Max number for password &fSave, // State of save check box CREDUI_FLAGS_GENERIC_CREDENTIALS | // flags CREDUI_FLAGS_ALWAYS_SHOW_UI | CREDUI_FLAGS_DO_NOT_PERSIST); if(dwErr == ERROR_CANCELLED) { useToken = true; } else if (dwErr) { cout << "Did not get credentials " << dwErr << endl; pLoc->Release(); CoUninitialize(); return 1; } // Connect to the remote root\cimv2 namespace // and obtain pointer pSvc to make IWbemServices calls. //--------------------------------------------------------- // change the computerName and domain // strings below to the full computer name and domain // of the remote computer hres = pLoc->ConnectServer( _bstr_t(L"\\\\COMPUTERNAME\ oot\\cimv2"), _bstr_t(useToken?NULL:pszName), // User name _bstr_t(useToken?NULL:pszPwd), // User password NULL, // Locale NULL, // Security flags NULL, // Authority 0, // Context object &pSvc // IWbemServices proxy ); if (FAILED(hres)) { cout << "Could not connect. Error code = 0x" << hex << hres << endl; pLoc->Release(); CoUninitialize(); return 1; // Program has failed. } cout << "Connected to ROOT\\CIMV2 WMI namespace" << endl; // step 5: -------------------------------------------------- // Create COAUTHIDENTITY that can be used for setting security on proxy COAUTHIDENTITY *userAcct = NULL ; COAUTHIDENTITY authIdent; if( !useToken ) { memset(&authIdent, 0, sizeof(COAUTHIDENTITY)); authIdent.PasswordLength = wcslen (pszPwd); authIdent.Password = (USHORT*)pszPwd; LPWSTR slash = wcschr (pszName, L'\\'); if( slash == NULL ) { cout << "Could not create Auth identity. No domain specified
    " ; pSvc->Release(); pLoc->Release(); CoUninitialize(); return 1; // Program has failed. } StringCchCopy(pszUserName, CREDUI_MAX_USERNAME_LENGTH+1, slash+1); authIdent.User = (USHORT*)pszUserName; authIdent.UserLength = wcslen(pszUserName); StringCchCopyN(pszDomain, CREDUI_MAX_USERNAME_LENGTH+1, pszName, slash - pszName); authIdent.Domain = (USHORT*)pszDomain; authIdent.DomainLength = slash - pszName; authIdent.Flags = SEC_WINNT_AUTH_IDENTITY_UNICODE; userAcct = &authIdent; } // Step 6: -------------------------------------------------- // Set security levels on a WMI connection ------------------ hres = CoSetProxyBlanket( pSvc, // Indicates the proxy to set RPC_C_AUTHN_GSS_NEGOTIATE, // RPC_C_AUTHN_xxx RPC_C_AUTHZ_DEFAULT, // RPC_C_AUTHZ_xxx COLE_DEFAULT_PRINCIPAL, // Server principal name RPC_C_AUTHN_LEVEL_PKT_PRIVACY, // RPC_C_AUTHN_LEVEL_xxx RPC_C_IMP_LEVEL_IMPERSONATE, // RPC_C_IMP_LEVEL_xxx userAcct, // client identity EOAC_NONE // proxy capabilities ); if (FAILED(hres)) { cout << "Could not set proxy blanket. Error code = 0x" << hex << hres << endl; pSvc->Release(); pLoc->Release(); CoUninitialize(); return 1; // Program has failed. } // Step 7: -------------------------------------------------- // Use the IWbemServices pointer to make requests of WMI ---- // For example, get the name of the operating system IEnumWbemClassObject* pEnumerator = NULL; hres = pSvc->ExecQuery( bstr_t("WQL"), bstr_t("Select * from Win32_OperatingSystem"), WBEM_FLAG_FORWARD_ONLY | WBEM_FLAG_RETURN_IMMEDIATELY, NULL, &pEnumerator); if (FAILED(hres)) { cout << "Query for operating system name failed." << " Error code = 0x" << hex << hres << endl; pSvc->Release(); pLoc->Release(); CoUninitialize(); return 1; // Program has failed. } // Step 8: ------------------------------------------------- // Secure the enumerator proxy hres = CoSetProxyBlanket( pEnumerator, // Indicates the proxy to set RPC_C_AUTHN_GSS_NEGOTIATE, // RPC_C_AUTHN_xxx RPC_C_AUTHZ_DEFAULT, // RPC_C_AUTHZ_xxx COLE_DEFAULT_PRINCIPAL, // Server principal name RPC_C_AUTHN_LEVEL_PKT_PRIVACY, // RPC_C_AUTHN_LEVEL_xxx RPC_C_IMP_LEVEL_IMPERSONATE, // RPC_C_IMP_LEVEL_xxx userAcct, // client identity EOAC_NONE // proxy capabilities ); if (FAILED(hres)) { cout << "Could not set proxy blanket on enumerator. Error code = 0x" << hex << hres << endl; pEnumerator->Release(); pSvc->Release(); pLoc->Release(); CoUninitialize(); return 1; // Program has failed. } // When you have finished using the credentials, // erase them from memory. SecureZeroMemory(pszName, sizeof(pszName)); SecureZeroMemory(pszPwd, sizeof(pszPwd)); SecureZeroMemory(pszUserName, sizeof(pszUserName)); SecureZeroMemory(pszDomain, sizeof(pszDomain)); // Step 9: ------------------------------------------------- // Get the data from the query in step 7 ------------------- IWbemClassObject *pclsObj = NULL; ULONG uReturn = 0; while (pEnumerator) { HRESULT hr = pEnumerator->Next(WBEM_INFINITE, 1, &pclsObj, &uReturn); if(0 == uReturn) { break; } VARIANT vtProp; // Get the value of the Name property hr = pclsObj->Get(L"Name", 0, &vtProp, 0, 0); wcout << " OS Name : " << vtProp.bstrVal << endl; // Get the value of the FreePhysicalMemory property hr = pclsObj->Get(L"FreePhysicalMemory", 0, &vtProp, 0, 0); wcout << " Free physical memory (in kilobytes): " << vtProp.uintVal << endl; VariantClear(&vtProp); pclsObj->Release(); pclsObj = NULL; } // Cleanup // ======== pSvc->Release(); pLoc->Release(); pEnumerator->Release(); if( pclsObj ) { pclsObj->Release(); } CoUninitialize(); return 0; // Program successfully completed.}  
    http://msdn.microsoft.com/en-us/libr...8VS.85%29.aspx

  5. #5
    Ngày tham gia
    Sep 2015
    Bài viết
    0
    Kiểu dữ liệu IEnumWbemClassObject có chứa ID của Mainboard không nhỉ


    Mã:
    .586
    .model FLAT,stdcall
    .code
    
    
    IP_ADDRESS_STRING struct
    	String db 16 dup (?)
    IP_ADDRESS_STRING ends
    
    
    IP_ADDR_STRING struct
    	Next		dd ?
    	IpAddress 	db 16 dup (?)
    	IpMask	  	db 16 dup (?)
    	Context		dd ?	
    IP_ADDR_STRING ends
    
    
    
    IP_ADAPTER_INFO struct
    	Next			dd ?
    	ComboIndex 		dd ?
    	AdapterName		db 260 dup (?)
    	Description		db 132 dup (?)
    	AddressLength		dd ?
    	Address			db 8 dup (?)
    	Index			dd ?
    	tType			dd ?
    	DhcpEnabled		dd ?
    	CurrentIpAddress 	dd ?
    	IpAddressList		IP_ADDR_STRING <>
    	GatewayList		IP_ADDR_STRING <>
    	DhcpServer		IP_ADDR_STRING <>
    	HaveWins		dd ?
    	PrimaryWinsServer	IP_ADDR_STRING <>
    	SecondaryWinsServer	IP_ADDR_STRING <>
    	LeaseObtained		dd ?
    	LeaseExpires		dd ?
    IP_ADAPTER_INFO ends
    
    PUBLIC GetMacAddress
    
    LoadLibrary textequ <LoadLibraryA>
    
    LoadLibrary proto :DWORD
    GetProcAddress proto :DWORD,:DWORD
    FreeLibrary proto :DWORD
    
    GetMacAddress proc uses eax ebx ecx edx pOut
    	local pDLL
    	local AdInfo[8]:IP_ADAPTER_INFO,dwBufLen
    	local str1[8]:DWORD
    
    	
    	
    	
    	mov dwBufLen,IP_ADAPTER_INFO*8
    	
    	.data
    		ishapi_ db "iphlpapi.dll",0
    		getada_ db "GetAdaptersInfo",0
    	.code
    	invoke LoadLibrary,addr ishapi_
    	mov pDLL,eax
    	test eax,eax
    	jz _bad
    	mov pDLL,eax
    
    	; make str1 = "GetAdaptersInfo"
    	invoke GetProcAddress,eax,addr getada_
    	test eax,eax
    	jz _bad
    	
    	lea ecx,AdInfo
    	lea edx,dwBufLen
    	push edx
    	push ecx
    	call eax
    	test eax,eax
    	jnz _bad
    	
    	
    	;----------[ do stuff with the AdInfo.Address ]-------------\
    	; it's the MAC address of the first NIC
    	;-----------------------------------------------------------/
    	
    	.if pDLL
    		invoke FreeLibrary,pDLL
    	.endif
    	
    	mov eax,1
    	ret
    	
    _bad:
    	; handle missing-NIC somehow
    	
    	ret
    GetMacAddress endp
    
    
    end

  6. #6
    em điều tra ra là nó sử dụng cấu trúc Win32_BaseBoard.SerialNumber để lấy thông tin


    Mã:
    Public Function MBSerialNumber() As String
    
    'RETRIEVES SERIAL NUMBER OF MOTHERBOARD
    'IF THERE IS MORE THAN ONE MOTHERBOARD, THE SERIAL
    'NUMBERS WILL BE DELIMITED BY COMMAS
    
    'YOU MUST HAVE WMI INSTALLED AND A REFERENCE TO
    'Microsoft WMI Scripting Library IS REQUIRED
    
    Dim objs As Object
    
    Dim obj As Object
    Dim WMI As Object
    Dim sAns As String
    
    
    Set WMI = GetObject("WinMgmts:")
    Set objs = WMI.InstancesOf("Win32_BaseBoard")
    For Each obj In objs
      sAns = sAns & obj.SerialNumber
     If sAns < objs.Count Then sAns = sAns & ","
    Next
    MBSerialNumber = sAns
    End Function
    http://msdn.microsoft.com/en-us/libr...8VS.85%29.aspx
    Mã:
    class Win32_BaseBoard : CIM_Card
    {
      string   Caption;
      string   ConfigOptions[];
      string   CreationClassName;
      real32   Depth;
      string   Description;
      real32   Height;
      boolean  HostingBoard;
      boolean  HotSwappable;
      datetime InstallDate;
      string   Manufacturer;
      string   Model;
      string   Name;
      string   OtherIdentifyingInfo;
      string   PartNumber;
      boolean  PoweredOn;
      string   Product;
      boolean  Removable;
      boolean  Replaceable;
      string   RequirementsDescription;
      boolean  RequiresDaughterBoard;
      string   SerialNumber;
      string   SKU;
      string   SlotLayout;
      boolean  SpecialRequirements;
      string   Status;
      string   Tag;
      string   Version;
      real32   Weight;
      real32   Width;
    };
    http://social.msdn.microsoft.com/For...f-f85c911c42d4

 

 

Quyền viết bài

  • Bạn Không thể gửi Chủ đề mới
  • Bạn Không thể Gửi trả lời
  • Bạn Không thể Gửi file đính kèm
  • Bạn Không thể Sửa bài viết của mình
  •