|
rahuljin wrote: this is the frist time i am doing the advance level programming.
It's not really an advanced topic as much as it is a specialized topic. See here for an idea.
"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 for the link. i have tried to write some code but it is not working. can u find the mistake i am making ? i want to find the status of the service "W3SVC", and when it is running, the program should print "Found" ----
<br />
<br />
#ifndef UNICODE<br />
#define UNICODE<br />
#endif<br />
<br />
#include <stdio.h><br />
#include <assert.h><br />
#include <windows.h><br />
#include <lm.h><br />
#include <tchar.h><br />
#include <wchar.h><br />
<br />
int wmain(int argc, wchar_t * argv[])<br />
{<br />
LPSERVER_INFO_101 pBuf = NULL;<br />
LPSERVER_INFO_101 pTmpBuf;<br />
DWORD dwLevel = 101;<br />
DWORD dwPrefMaxLen = MAX_PREFERRED_LENGTH;<br />
DWORD dwEntriesRead = 0;<br />
DWORD dwTotalEntries = 0;<br />
DWORD dwTotalCount = 0;<br />
DWORD dwServerType = SV_TYPE_SERVER;
DWORD dwResumeHandle = 0;<br />
NET_API_STATUS nStatus;<br />
LPTSTR pszServerName = NULL;<br />
LPTSTR pszDomainName = NULL;<br />
DWORD i;<br />
<br />
if (argc > 2) <br />
{<br />
fwprintf(stderr, L"Usage: %s [DomainName]\n", argv[0]);<br />
exit(1);<br />
}<br />
if (argc == 2)<br />
pszDomainName = argv[1];<br />
nStatus = NetServerEnum((LPCWSTR) pszServerName,<br />
dwLevel,<br />
(LPBYTE *) & pBuf,<br />
dwPrefMaxLen,<br />
&dwEntriesRead,<br />
&dwTotalEntries,<br />
dwServerType, <br />
(LPCWSTR) pszDomainName, <br />
&dwResumeHandle);<br />
if ((nStatus == NERR_Success) || (nStatus == ERROR_MORE_DATA)) {<br />
if ((pTmpBuf = pBuf) != NULL) {<br />
for (i = 0; i < dwEntriesRead; i++) {<br />
assert(pTmpBuf != NULL);<br />
<br />
if (pTmpBuf == NULL) {<br />
fprintf(stderr, "An access violation has occurred\n");<br />
break;<br />
}<br />
<br />
printf("\tPlatform: %d\n", pTmpBuf->sv101_platform_id);<br />
wprintf(L"\tName: %s\n", pTmpBuf->sv101_name);<br />
printf("\tVersion: %d.%d\n",<br />
pTmpBuf->sv101_version_major,<br />
pTmpBuf->sv101_version_minor);<br />
printf("\tType: %d", pTmpBuf->sv101_type);<br />
if (pTmpBuf->sv101_type & SV_TYPE_DOMAIN_CTRL)<br />
wprintf(L" (PDC)");<br />
else if (pTmpBuf->sv101_type & SV_TYPE_DOMAIN_BAKCTRL)<br />
wprintf(L" (BDC)");<br />
<br />
printf("\n");<br />
SC_HANDLE hSCM = OpenSCManager((LPCTSTR) pTmpBuf->sv101_name, NULL, SC_MANAGER_CONNECT);<br />
<br />
if (hSCM != NULL)<br />
{<br />
SC_HANDLE hService = OpenService(hSCM, _T("W3SVC"), SERVICE_QUERY_STATUS);<br />
if (hService != NULL)<br />
{<br />
SERVICE_STATUS ss;<br />
if ((QueryServiceStatus(hService, &ss) == SERVICE_RUNNING)||(QueryServiceStatus(hService, &ss) == SERVICE_START_PENDING))<br />
printf("Found");<br />
<br />
CloseServiceHandle(hService);<br />
}<br />
CloseServiceHandle(hSCM);<br />
}<br />
<br />
wprintf(L"\tComment: %s\n\n", pTmpBuf->sv101_comment);<br />
<br />
pTmpBuf++;<br />
dwTotalCount++;<br />
}<br />
<br />
if (nStatus == ERROR_MORE_DATA) {<br />
fprintf(stderr, "\nMore entries available!!!\n");<br />
fprintf(stderr, "Total entries: %d", dwTotalEntries);<br />
}<br />
<br />
printf("\nEntries enumerated: %d\n", dwTotalCount);<br />
<br />
} else {<br />
printf("No servers were found\n");<br />
printf("The buffer (bufptr) returned was NULL\n");<br />
printf(" entriesread: %d\n", dwEntriesRead);<br />
printf(" totalentries: %d\n", dwEntriesRead);<br />
}<br />
<br />
} else<br />
fprintf(stderr, "NetServerEnum failed with error: %d\n", nStatus);<br />
if (pBuf != NULL)<br />
NetApiBufferFree(pBuf);<br />
<br />
return 0;<br />
}<br />
<br />
<br />
|
|
|
|
|
rahuljin wrote: if ((QueryServiceStatus(hService, &ss) == SERVICE_RUNNING)||(QueryServiceStatus(hService, &ss) == SERVICE_START_PENDING))
printf("Found");
Should be:
if (QueryServiceStatus(hService, &ss) != FALSE)
{
if (ss.dwCurrentState == SERVICE_RUNNING || ss.dwCurrentState == SERVICE_START_PENDING)
printf("Found");
}
"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, it is working now. i will bother u soon if i stuck in something.
one more thing i want to ask. currently i have only one computer so no network. will this program work on a network of computers too ? i cant check myself.
suppose i run it on a client, will it give the info of server or all the computers in the network (clients + servers) ?
also, if i have the ip address of the server then how to use it in this program ?
thanks again
rahul
update :
when i make a try to make a array of processes like this -------
wchar_t selPro[] = { _T("W3SVC"), _T("Iisadmin")};
SC_HANDLE hService = OpenService(hSCM, selPro[j], SERVICE_QUERY_STATUS);
where j is for "for" lool (0,1). when i compile this code, compiling completes without any error and when i try to run it, it crashes. if i pass without array, it works fine.
please guide me
modified on Saturday, June 13, 2009 5:05 PM
|
|
|
|
|
rahuljin wrote: will this program work on a network of computers too ?
That's what NetServerEnum() is for.
rahuljin wrote: suppose i run it on a client, will it give the info of server or all the computers in the network (clients + servers) ?
First, did you try it? Second, did you check MSDN to see how OpenSCManager() handles its first argument?
rahuljin wrote: also, if i have the ip address of the server then how to use it in this program ?
Convert the IP address to the host name using gethostbyaddr() .
rahuljin wrote: ...it crashes.
Meaning what? A "crash" is fairly meaningless.
"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
|
|
|
|
|
here is error from windows. it says "new01" has stopped working
Problem signature:
Problem Event Name: APPCRASH
Application Name: new01.exe
Application Version: 0.0.0.0
Application Timestamp: 4a349ab0
Fault Module Name: RPCRT4.dll
Fault Module Version: 6.1.7100.0
Fault Module Timestamp: 49eea681
Exception Code: c0000005
Exception Offset: 0002f3b0
OS Version: 6.1.7100.2.0.0.256.1
Locale ID: 16393
Additional Information 1: 0a9e
Additional Information 2: 0a9e372d3b4ad19135b953a78882e789
Additional Information 3: 0a9e
Additional Information 4: 0a9e372d3b4ad19135b953a78882e789
Read our privacy statement online:
http:
If the online privacy statement is not available, please read our privacy statement offline:
C:\Windows\system32\en-US\erofflps.txt
here is the complete code of the program ----
#ifndef UNICODE
#define UNICODE
#endif
#include <stdio.h>
#include <assert.h>
#include <windows.h>
#include <lm.h>
#include <tchar.h>
#include <wchar.h>
void printServer(LPSERVER_INFO_101 ppTmpBuf, DWORD ddwEntriesRead)
{
SC_HANDLE hSCM;
SERVICE_STATUS ss;
DWORD i;
short int j, x;
x = 2;
wchar_t* prName[] = {
_T("W3SVC"),
_T("Themes")
};
for (i = 0; i < ddwEntriesRead; i++)
{
for(j=0; j<x ; j++)
{
hSCM = OpenSCManager((LPCTSTR) ppTmpBuf->sv101_name,
NULL, SC_MANAGER_CONNECT);
if (hSCM != NULL)
{
SC_HANDLE hService = OpenService(hSCM, prName[j], SERVICE_QUERY_STATUS);
if (hService != NULL)
{
if (QueryServiceStatus(hService, &ss) != FALSE)
{
if ((ss.dwCurrentState == SERVICE_RUNNING)||(ss.dwCurrentState == SERVICE_START_PENDING))
wprintf(_T("%-20s %-15s This service is running.\n"),ppTmpBuf->sv101_name, prName[j]);
else
wprintf(_T("%-20s %-15s This service is stopped or not found.\n"),ppTmpBuf->sv101_name, prName[j]);
}
CloseServiceHandle(hService);
}
}
CloseServiceHandle(hSCM);
}
ppTmpBuf++;
}
NetApiBufferFree(ppTmpBuf);
}
void debugeFunct(NET_API_STATUS nState, LPSERVER_INFO_101 pTmpBuf,
DWORD dwEntriesRead, DWORD dwTotalEntries)
{
NET_API_STATUS nas ;
NET_DISPLAY_MACHINE * pndm;
DWORD dwNdmCount;
switch(nState)
{
case NERR_Success:
case ERROR_MORE_DATA:
{
if(pTmpBuf == NULL)
{
fprintf(stderr, "An access voilation has occurred.\n");
}
else
{
nas = NetQueryDisplayInformation (pTmpBuf->sv101_name,
2,
0,
1,
sizeof(NET_DISPLAY_MACHINE),
&dwNdmCount,
(PVOID*)&pndm);
switch (nas)
{
case NERR_Success:
case ERROR_MORE_DATA:
printServer(pTmpBuf, dwEntriesRead);
break;
default:
{
printf("NQDI gave error %u\n", nas);
break;
}
}
}
}
break;
default:
printf("No pc were found. The buffer returned was NULL\n");
break;
}
NetApiBufferFree(pTmpBuf);
}
void findServ(DWORD dwPrefMaxLen, DWORD dwServerType)
{
LPSERVER_INFO_101 pBuf = NULL;
DWORD dwLevel = 101;
DWORD dwEntriesRead = 0;
DWORD dwTotalEntries = 0;
DWORD dwTotalCount = 0;
DWORD dwResumeHandle = 0;
NET_API_STATUS nStatus;
LPTSTR pszServerName = NULL;
LPTSTR pszDomainName = NULL;
nStatus = NetServerEnum(
(LPCWSTR) pszServerName,
dwLevel,
(LPBYTE *) & pBuf,
dwPrefMaxLen,
&dwEntriesRead,
&dwTotalEntries,
dwServerType,
(LPCWSTR) pszDomainName,
&dwResumeHandle
);
debugeFunct(nStatus, pBuf, dwEntriesRead, dwTotalEntries);
NetApiBufferFree(pBuf);
}
int _tmain(int argc, wchar_t * argv[])
{
DWORD dPrefMaxLen = MAX_PREFERRED_LENGTH;
DWORD dServerType = SV_TYPE_SERVER;
printf("Machine Service Status\n");
while(1)
{
findServ(dPrefMaxLen, dServerType);
Sleep(3000);
}
return 0;
} Here is the event viewer file of the application
modified on Sunday, June 14, 2009 10:33 AM
|
|
|
|
|
So where's the problem?
"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
|
|
|
|
|
when i remove the following statements from the program, program run without any error.
NetApiBufferFree(ppTmpBuf);
NetApiBufferFree(pTmpBuf);
what may be the problem with this ?
|
|
|
|
|
rahuljin wrote: what may be the problem with this ?
It appears you are freeing the same memory three times.
"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
|
|
|
|
|
yes, that may be the reason for the program crash.
is there a way to access from a client if it have minimum access ? i mean that the client can access only a few folder in the other pc.
also when i try this program on xp OS system, it gives the error ---
NetQueryDisplayInformation gave error ERROR_ACCESS_DENIED.
Due to this error, it does not display the status of service even of the system it is running on. it is a client pc.
though i can ping the ip of other computers in the network.
is there any remedy for this ?
modified on Tuesday, June 16, 2009 3:50 AM
|
|
|
|
|
from the Win32 console functions built CreateDialog,use
only dos.h, conio.h, stdio.h.I using VC6
by tuan1111.Vietnam
|
|
|
|
|
|
Are you some kind of troll ? Do you really think that somebody will be able to answer any of your questions ?
|
|
|
|
|
The random word generator you have used for this and your previous posts is working perfectly.
If you have developed it yourself you should really post an article about it!
|
|
|
|
|
Hello,
I have an ActiveX control that provides such method:
void GetCurrentImage(long theFormat, VARIANT * theBuffer, long * theBufferSize);
I want to get a byte image buffer from this function. That is, I am trying to do this:
long image_size;
VARIANT FrameBuf[1024*1024];
char ByteBuf[1024*1024];
pCtrl->GetCurrentImage(0, FrameBuf, &image_size);
I did some googling. But partly because VARIANT is a common word that confused Google, I can hardly find any useful solution to this. Can anyone give me some advice? Thank you very much.
Jason
|
|
|
|
|
Creating an array of Variant is wrong.
Try this
VARIANT FrameBuf;
BYTE ByteBuf[1024 * 1024];
FrameBuf.vt = VT_BYREF|VT_UI1;
FrameBuf.pbVal = ByteBuf;
pCtrl->GetCurrentImage(0, FrameBuf, ℑ_size);
«_Superman_»
I love work. It gives me something to do between weekends.
|
|
|
|
|
_Superman_,
Thank you for your kindly reply. I guess you were meaning this, right?
pCtrl->GetCurrentImage(0, &FrameBuf, &size);
since GetCurrentImage() takes a VARIANT* argument.
But after I executed your example code(with GetCurrentImage line replaced with the above one) and checked the ByteBuf, I found its content is unchanged. Did I still miss anything here?
Thanks,
Jason
|
|
|
|
|
Please check the return value of GetCurrentImage to see if it has succeeded.
«_Superman_»
I love work. It gives me something to do between weekends.
|
|
|
|
|
Unfortuenately, the function is an asyncrous function and returns immediatly, so return value is not useful. I have waited quite some time in the main thread and the check result is the same: the image size is returned correctly, but the buffer is unchanged...
|
|
|
|
|
Hey guys,
I couldn't find the way to display '&' on CMFCToolBarButton. I have a string of "Boy&Girl" and I want to display that string on a CMFCToolBarButton. If I set its text to exactly "Boy&Girl", the text will be displayed as "BoyGirl" due to a window control shortcut.
So.. I replace the original, "Boy&Girl" to "Boy&&Girl" so that I can display '&' character. However, I ended up with Boy Girl".
Now I replace the orignal text with "Boy/&Girl", it displays my text as "Boy Girl".
Do you guys know how to fix this?
Thanks!
Un
|
|
|
|
|
Un Suthee wrote: "Boy&Girl"
Try "Boy&&Girl".
It is a crappy thing, but it's life -^ Carlo Pallini
|
|
|
|
|
I tried that but it does not work.
The problem is I am using CMFCToolBarButton::OnDraw() method.
I looked at the source code of that function and turns out that it does not set a flag "DT_NOPREFIX" in which tells DrawText not to interpret ampersand as a directive to underscore the following character.
So the work around I did is to convert a string "Boy&Girl" to "Boy&&&&Girl" !! What happens is CMFCToolBarButton::OnDraw() will convert this string to "Boy&&Girl" and then CDC::DrawText will now convert "&&" to "&". It works but I guess there must be a much better solution than the one I have.
Thanks!
Un
|
|
|
|
|
Un Suthee wrote: Now I replace the orignal text with "Boy/&Girl"
You should try "Boy\&Girl". Backslash instead of forward slash.
But I guess your workaround is pretty good.
«_Superman_»
I love work. It gives me something to do between weekends.
|
|
|
|
|
You should try "Boy\\&&Girl". Backslash instead of forward slash.
I think so it's ok.
|
|
|
|
|
I just tried "Boy\\&&Girl" and I got "Boy\Girl".
Un
|
|
|
|
|