Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. convert vbscript to c++

convert vbscript to c++

Scheduled Pinned Locked Moved C / C++ / MFC
c++data-structuresquestion
10 Posts 4 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • M Offline
    M Offline
    Mogaambo
    wrote on last edited by
    #1

    how can i convert below code from vbscript to c++ strComputer = "." Set colGroups = GetObject("WinNT://" & strComputer & "") colGroups.Filter = Array("group") For Each objGroup In colGroups 'Wscript.Echo objGroup.Name if objGroup.Name ="Administrators" then For Each objUser in objGroup.Members Wscript.Echo vbTab & objUser.Name Next end if Next

    “You will never be a leader unless you first learn to follow and be led.” –Tiorio "Coming together is a beginning, staying together is progress, and working together is success." Henry Ford

    L 1 Reply Last reply
    0
    • M Mogaambo

      how can i convert below code from vbscript to c++ strComputer = "." Set colGroups = GetObject("WinNT://" & strComputer & "") colGroups.Filter = Array("group") For Each objGroup In colGroups 'Wscript.Echo objGroup.Name if objGroup.Name ="Administrators" then For Each objUser in objGroup.Members Wscript.Echo vbTab & objUser.Name Next end if Next

      “You will never be a leader unless you first learn to follow and be led.” –Tiorio "Coming together is a beginning, staying together is progress, and working together is success." Henry Ford

      L Offline
      L Offline
      led mike
      wrote on last edited by
      #2

      Mogaambo wrote:

      how can i convert

      What do you mean? Are you looking for a tool that will do it or what? Most of the people here know how to write C++ code and that is why they might be able to do the work. What can you do and what do you want from the people in this forum?

      M 1 Reply Last reply
      0
      • L led mike

        Mogaambo wrote:

        how can i convert

        What do you mean? Are you looking for a tool that will do it or what? Most of the people here know how to write C++ code and that is why they might be able to do the work. What can you do and what do you want from the people in this forum?

        M Offline
        M Offline
        Mogaambo
        wrote on last edited by
        #3

        How can i enumerate users // adminGroup.cpp : Defines the entry point for the console application. // #pragma comment(lib,"Netapi32.lib") #include #include < LMCONS.H> #include #include #define MAX_PREFERRED_LENGTH ((DWORD) -1) #include "stdafx.h" int _tmain(int argc, _TCHAR* argv[]) { NET_API_STATUS ret = 0 ; LPCWSTR servername = NULL; LPCWSTR groupname = L"Administrators"; LPBYTE buffer = NULL; DWORD entriesRead; DWORD totalEntries; DWORD resumeHandle =0; typedef struct _LOCALGROUP_MEMBERS_INFO_1 { PSID lgrmi1_sid; SID_NAME_USE lgrmi1_sidusage; LPWSTR lgrmi1_name; }LOCALGROUP_MEMBERS_INFO_1, *PLOCALGROUP_MEMBERS_INFO_1, *LPLOCALGROUP_MEMBERS_INFO_1; //function call ret=NetLocalGroupGetMembers (NULL, groupname, 1, &buffer, MAX_PREFERRED_LENGTH, &entriesRead, &totalEntries, &resumeHandle); for(int i = 0;i< entriesRead ;i++) { //here i wan to enumerate but how } int n=0; return 0; }

        “You will never be a leader unless you first learn to follow and be led.” –Tiorio "Coming together is a beginning, staying together is progress, and working together is success." Henry Ford

        L 1 Reply Last reply
        0
        • M Mogaambo

          How can i enumerate users // adminGroup.cpp : Defines the entry point for the console application. // #pragma comment(lib,"Netapi32.lib") #include #include < LMCONS.H> #include #include #define MAX_PREFERRED_LENGTH ((DWORD) -1) #include "stdafx.h" int _tmain(int argc, _TCHAR* argv[]) { NET_API_STATUS ret = 0 ; LPCWSTR servername = NULL; LPCWSTR groupname = L"Administrators"; LPBYTE buffer = NULL; DWORD entriesRead; DWORD totalEntries; DWORD resumeHandle =0; typedef struct _LOCALGROUP_MEMBERS_INFO_1 { PSID lgrmi1_sid; SID_NAME_USE lgrmi1_sidusage; LPWSTR lgrmi1_name; }LOCALGROUP_MEMBERS_INFO_1, *PLOCALGROUP_MEMBERS_INFO_1, *LPLOCALGROUP_MEMBERS_INFO_1; //function call ret=NetLocalGroupGetMembers (NULL, groupname, 1, &buffer, MAX_PREFERRED_LENGTH, &entriesRead, &totalEntries, &resumeHandle); for(int i = 0;i< entriesRead ;i++) { //here i wan to enumerate but how } int n=0; return 0; }

          “You will never be a leader unless you first learn to follow and be led.” –Tiorio "Coming together is a beginning, staying together is progress, and working together is success." Henry Ford

          L Offline
          L Offline
          led mike
          wrote on last edited by
          #4

          I've never used that API but based on the documentation my first guess would be that if entriesRead is more than 1 the buffer will contain an array of them so you would iterate through the array, something like:

          PLOCALGROUP_MEMBERS_INFO_1 pData = (PLOCALGROUP_MEMBERS_INFO_1)buffer;

          for(int i = 0;i< entriesRead ;i++, pData++)
          {
          pData->lgrmi1_sid; // etc.
          }

          Of course I would have to verify that by debugging since I've never worked with it. BTW: Don't forget to free the buffer ;) "bufptr [out] Pointer to the address that receives the return information structure. The format of this data depends on the value of the level parameter. This buffer is allocated by the system and must be freed using the NetApiBufferFree function. Note that you must free the buffer even if the function fails with ERROR_MORE_DATA."

          M 1 Reply Last reply
          0
          • L led mike

            I've never used that API but based on the documentation my first guess would be that if entriesRead is more than 1 the buffer will contain an array of them so you would iterate through the array, something like:

            PLOCALGROUP_MEMBERS_INFO_1 pData = (PLOCALGROUP_MEMBERS_INFO_1)buffer;

            for(int i = 0;i< entriesRead ;i++, pData++)
            {
            pData->lgrmi1_sid; // etc.
            }

            Of course I would have to verify that by debugging since I've never worked with it. BTW: Don't forget to free the buffer ;) "bufptr [out] Pointer to the address that receives the return information structure. The format of this data depends on the value of the level parameter. This buffer is allocated by the system and must be freed using the NetApiBufferFree function. Note that you must free the buffer even if the function fails with ERROR_MORE_DATA."

            M Offline
            M Offline
            Mogaambo
            wrote on last edited by
            #5

            Here what i get after a lot of googling or say binging LPLOCALGROUP_MEMBERS_INFO_1 pstMembersInfo = 0; DWORD entriesread = 0; DWORD totalentries = 0; if( 0 != NetLocalGroupGetMembers( NULL, _T("Administrators"), 1, (LPBYTE*) &pstMembersInfo,MAX_PREFERRED_LENGTH, &entriesread, &totalentries, 0 )) { AfxMessageBox( _T("NetLocalGroupGetMembers failed !")); return ; } for( DWORD dwIdx =0; dwIdx < entriesread; dwIdx ++ ) { AfxMessageBox( pstMembersInfo[dwIdx].lgrmi1_name ); } NetApiBufferFree( pstMembersInfo );

            “You will never be a leader unless you first learn to follow and be led.” –Tiorio "Coming together is a beginning, staying together is progress, and working together is success." Henry Ford

            S M 2 Replies Last reply
            0
            • M Mogaambo

              Here what i get after a lot of googling or say binging LPLOCALGROUP_MEMBERS_INFO_1 pstMembersInfo = 0; DWORD entriesread = 0; DWORD totalentries = 0; if( 0 != NetLocalGroupGetMembers( NULL, _T("Administrators"), 1, (LPBYTE*) &pstMembersInfo,MAX_PREFERRED_LENGTH, &entriesread, &totalentries, 0 )) { AfxMessageBox( _T("NetLocalGroupGetMembers failed !")); return ; } for( DWORD dwIdx =0; dwIdx < entriesread; dwIdx ++ ) { AfxMessageBox( pstMembersInfo[dwIdx].lgrmi1_name ); } NetApiBufferFree( pstMembersInfo );

              “You will never be a leader unless you first learn to follow and be led.” –Tiorio "Coming together is a beginning, staying together is progress, and working together is success." Henry Ford

              S Offline
              S Offline
              Stuart Dootson
              wrote on last edited by
              #6

              That's pretty much equivalent to Mike's - it's just the casting's done slightly differently.

              Java, Basic, who cares - it's all a bunch of tree-hugging hippy cr*p

              1 Reply Last reply
              0
              • M Mogaambo

                Here what i get after a lot of googling or say binging LPLOCALGROUP_MEMBERS_INFO_1 pstMembersInfo = 0; DWORD entriesread = 0; DWORD totalentries = 0; if( 0 != NetLocalGroupGetMembers( NULL, _T("Administrators"), 1, (LPBYTE*) &pstMembersInfo,MAX_PREFERRED_LENGTH, &entriesread, &totalentries, 0 )) { AfxMessageBox( _T("NetLocalGroupGetMembers failed !")); return ; } for( DWORD dwIdx =0; dwIdx < entriesread; dwIdx ++ ) { AfxMessageBox( pstMembersInfo[dwIdx].lgrmi1_name ); } NetApiBufferFree( pstMembersInfo );

                “You will never be a leader unless you first learn to follow and be led.” –Tiorio "Coming together is a beginning, staying together is progress, and working together is success." Henry Ford

                M Offline
                M Offline
                Mogaambo
                wrote on last edited by
                #7

                cout<< pData->lgrmi1_name <<std::endl; //how can i get name here as it is printing only address like below printf("%S\n", pData->lgrmi1_name );;

                “You will never be a leader unless you first learn to follow and be led.” –Tiorio "Coming together is a beginning, staying together is progress, and working together is success." Henry Ford

                D 1 Reply Last reply
                0
                • M Mogaambo

                  cout<< pData->lgrmi1_name <<std::endl; //how can i get name here as it is printing only address like below printf("%S\n", pData->lgrmi1_name );;

                  “You will never be a leader unless you first learn to follow and be led.” –Tiorio "Coming together is a beginning, staying together is progress, and working together is success." Henry Ford

                  D Offline
                  D Offline
                  David Crow
                  wrote on last edited by
                  #8

                  Mogaambo wrote:

                  cout<< pData->lgrmi1_name < Have you tried wcout?

                  "Old age is like a bank account. You withdraw later in life what you have deposited along the way." - Unknown

                  "Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons

                  M 1 Reply Last reply
                  0
                  • D David Crow

                    Mogaambo wrote:

                    cout<< pData->lgrmi1_name < Have you tried wcout?

                    "Old age is like a bank account. You withdraw later in life what you have deposited along the way." - Unknown

                    "Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons

                    M Offline
                    M Offline
                    Mogaambo
                    wrote on last edited by
                    #9

                    Thanks to all for helping me a lot, actually i am c# programmer and i dont know all these jargons. Thks alot

                    “You will never be a leader unless you first learn to follow and be led.” –Tiorio "Coming together is a beginning, staying together is progress, and working together is success." Henry Ford

                    M 1 Reply Last reply
                    0
                    • M Mogaambo

                      Thanks to all for helping me a lot, actually i am c# programmer and i dont know all these jargons. Thks alot

                      “You will never be a leader unless you first learn to follow and be led.” –Tiorio "Coming together is a beginning, staying together is progress, and working together is success." Henry Ford

                      M Offline
                      M Offline
                      Mogaambo
                      wrote on last edited by
                      #10

                      // adminGroup.cpp : Defines the entry point for the console application. // #pragma comment(lib,"Netapi32.lib") #include <stdio.h> #include <windows.h> #include < LMCONS.H> #include <Lm.h> #include <Lmaccess.h> #define MAX_PREFERRED_LENGTH ((DWORD) -1) #include "stdafx.h" #include <iostream> #include <string> using namespace std; int _tmain(int argc, _TCHAR* argv[]) { // NET_API_STATUS ret = 0 ; //LPCWSTR servername = NULL; //LPCWSTR groupname = L"Administrators"; LPBYTE buffer = NULL; //DWORD entriesRead; //DWORD totalEntries; //DWORD resumeHandle =0; // //typedef struct _LOCALGROUP_MEMBERS_INFO_1 { // PSID lgrmi1_sid; // SID_NAME_USE lgrmi1_sidusage; // LPWSTR lgrmi1_name; //}LOCALGROUP_MEMBERS_INFO_1, *PLOCALGROUP_MEMBERS_INFO_1, *LPLOCALGROUP_MEMBERS_INFO_1; ////function call //ret=NetLocalGroupGetMembers (NULL, groupname, 1, &buffer, MAX_PREFERRED_LENGTH, &entriesRead, &totalEntries, &resumeHandle); //LPLOCALGROUP_MEMBERS_INFO_1 pstMembersInfo = 0; //for( DWORD dwIdx =0; dwIdx < entriesRead; dwIdx ++ ) //{ // //std::cout<< pstMembersInfo[dwIdx].lgrmi1_name ; //} //int n=0; LPLOCALGROUP_MEMBERS_INFO_1 pstMembersInfo = 0; DWORD entriesread = 0; DWORD totalentries = 0; LPWSTR FromFile2=NULL; if( 0 != NetLocalGroupGetMembers( NULL, _T("Administrators"), 1, (LPBYTE*) &buffer,MAX_PREFERRED_LENGTH, &entriesread, &totalentries, 0 )) { //AfxMessageBox( _T("NetLocalGroupGetMembers failed !")); // return ; } PLOCALGROUP_MEMBERS_INFO_1 pData = (PLOCALGROUP_MEMBERS_INFO_1)buffer; for( DWORD dwIdx =0; dwIdx < entriesread; dwIdx ++ , pData++) { //printf("%S\n", pstMembersInfo[dwIdx].lgrmi1_name );; //lstrcpy(FromFile2,pstMembersInfo[dwIdx].lgrmi1_name); //std::cout<<(std::string) pstMembersInfo[dwIdx].lgrmi1_name <<std::endl; wcout<< pData->lgrmi1_name <<std::endl; //printf("%S\n", pData->lgrmi1_name );; } NetApiBufferFree( buffer ); return 0; }

                      “You will never be a leader unless you first learn to follow and be led.” –Tiorio "Coming together is a beginning, staying together is progress, and working together is success." Henry Ford

                      1 Reply Last reply
                      0
                      Reply
                      • Reply as topic
                      Log in to reply
                      • Oldest to Newest
                      • Newest to Oldest
                      • Most Votes


                      • Login

                      • Don't have an account? Register

                      • Login or register to search.
                      • First post
                        Last post
                      0
                      • Categories
                      • Recent
                      • Tags
                      • Popular
                      • World
                      • Users
                      • Groups