convert vbscript to c++
-
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
-
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
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?
-
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?
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
-
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
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."
-
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."
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
-
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
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
-
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
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
-
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
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
-
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
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
-
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
// 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