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. MFC System Information

MFC System Information

Scheduled Pinned Locked Moved C / C++ / MFC
c++sysadminsecuritytutorialannouncement
14 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.
  • C charu123

    Thanks for the info. I am having a little probs figuring out how to use SystemParametersInfo. I also need help with: DEFAULT PRINTER: ServerName: PrinterName: ShareName: PortName: DriverName: Description: Location: Processor: Processor param: DataType: Status: Current jobs: 0 Current printing speed: Print to the following port: thanks U get wht u Give

    P Offline
    P Offline
    P Rex
    wrote on last edited by
    #4

    Try this, you should get Devicename, port and the drivername of your default printer CPrintDialog dlg(FALSE); if (!dlg.GetDefaults()) AfxMessageBox(_T("You have no default printer!")); else { CString strDescription; strDescription.Format(_T("Your default printer is %s on %s using %s."), (LPCTSTR) dlg.GetDeviceName(), (LPCTSTR) dlg.GetPortName(), (LPCTSTR) dlg.GetDriverName()); AfxMessageBox(strDescription); } P-Man

    C 1 Reply Last reply
    0
    • C charu123

      hi, Could someone Please tell me how to retrieve the following information to print in the dialog box. Ethernet: NIC Address: IP Address: Modems installed: Browser Information: Version: Start page: Viewing Security: NetClient: Network Protocols: III. DIRECTORIES Temp Directory: IV. DISK INFORMATION Drive C: Fixed Disk Volume Name: Volume Serial: Total Space: Free Space: V. DISPLAY Display Adapter: Display Resolution: Display Colors: thanks U get wht u Give

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

      charu123 wrote: NIC Address: IP Address: To get the MAC address, use GetAdaptersInfo(). To get the IP address, use gethostname() followed by gethostbyname(). charu123 wrote: Browser Information: Since more than one browser can be present, this question cannot be answered directly. One approach would be to call FindExecutable() with the name of some .html file. Then query that executable using GetFileVersionInfo() and VerQueryValue().


      "Opinions are neither right nor wrong. I cannot change your opinion. I can, however, change what influences your opinion." - David Crow

      C 3 Replies Last reply
      0
      • C charu123

        Thanks for the info. I am having a little probs figuring out how to use SystemParametersInfo. I also need help with: DEFAULT PRINTER: ServerName: PrinterName: ShareName: PortName: DriverName: Description: Location: Processor: Processor param: DataType: Status: Current jobs: 0 Current printing speed: Print to the following port: thanks U get wht u Give

        T Offline
        T Offline
        ThatsAlok
        wrote on last edited by
        #6

        About Printer You already got the answer and about rest you can depend upon this api [GetSystemInfo]


        [Vote One Here, Complete my Survey....] Alok Gupta
        visit me at http://www.thisisalok.tk          "I Think Believe this Will Help"

        1 Reply Last reply
        0
        • D David Crow

          charu123 wrote: NIC Address: IP Address: To get the MAC address, use GetAdaptersInfo(). To get the IP address, use gethostname() followed by gethostbyname(). charu123 wrote: Browser Information: Since more than one browser can be present, this question cannot be answered directly. One approach would be to call FindExecutable() with the name of some .html file. Then query that executable using GetFileVersionInfo() and VerQueryValue().


          "Opinions are neither right nor wrong. I cannot change your opinion. I can, however, change what influences your opinion." - David Crow

          C Offline
          C Offline
          charu123
          wrote on last edited by
          #7

          Hi I am having some problem... please see this code and tell me whr I am going wrong. LPTSTR lptstrFilename; char buffer[BUF]="C:\\Program Files\\Internet Explorer\\iexplore.exe"; lptstrFilename = (char *) malloc( sizeof(BUF) ); strcpy(lptstrFilename,buffer); DWORD dwHandle=NULL; DWORD lpdwHandle= -1; DWORD dwLen=0; void *lpData; dwLen= GetFileVersionInfoSize(lptstrFilename,&lpdwHandle); lpData = malloc(dwLen); DWORD dwError = GetLastError(); BOOL bRet = GetFileVersionInfo(lptstrFilename,NULL,dwLen,&lpData); PUINT lplpBuffer; PUINT puLen; VerQueryValue(lpData, TEXT("\\VarFileInfo\\Translation"), &lpBuffer, &dwBytes); I am getting an error when i reach the VerQueryValue. Can u please point out the mistake. U get wht u Give

          D 1 Reply Last reply
          0
          • D David Crow

            charu123 wrote: NIC Address: IP Address: To get the MAC address, use GetAdaptersInfo(). To get the IP address, use gethostname() followed by gethostbyname(). charu123 wrote: Browser Information: Since more than one browser can be present, this question cannot be answered directly. One approach would be to call FindExecutable() with the name of some .html file. Then query that executable using GetFileVersionInfo() and VerQueryValue().


            "Opinions are neither right nor wrong. I cannot change your opinion. I can, however, change what influences your opinion." - David Crow

            C Offline
            C Offline
            charu123
            wrote on last edited by
            #8

            I am not able to implement GetAdaptersInfo becoz it is not recognizing some header files. Is there any other way i can implement it. Probably read from some file etc. Can u tell me how to get CPU speed. Thanks U get wht u Give

            D C 2 Replies Last reply
            0
            • C charu123

              Hi I am having some problem... please see this code and tell me whr I am going wrong. LPTSTR lptstrFilename; char buffer[BUF]="C:\\Program Files\\Internet Explorer\\iexplore.exe"; lptstrFilename = (char *) malloc( sizeof(BUF) ); strcpy(lptstrFilename,buffer); DWORD dwHandle=NULL; DWORD lpdwHandle= -1; DWORD dwLen=0; void *lpData; dwLen= GetFileVersionInfoSize(lptstrFilename,&lpdwHandle); lpData = malloc(dwLen); DWORD dwError = GetLastError(); BOOL bRet = GetFileVersionInfo(lptstrFilename,NULL,dwLen,&lpData); PUINT lplpBuffer; PUINT puLen; VerQueryValue(lpData, TEXT("\\VarFileInfo\\Translation"), &lpBuffer, &dwBytes); I am getting an error when i reach the VerQueryValue. Can u please point out the mistake. U get wht u Give

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

              charu123 wrote: char buffer[BUF]="C:\\Program Files\\Internet Explorer\\iexplore.exe"; This will not work if IE has been moved/installed to a different location. Better to use FindExecutable(). Why copy buffer to lptstrFilename? That makes no sense. :confused: charu123 wrote: Can u please point out the mistake. Not unless you disclose what error you are receiving. Have you searched for examples? http://msdn.microsoft.com/library/default.asp?url=/library/en-us/winui/winui/windowsuserinterface/resources/versioninformation/versioninformationreference/versioninformationfunctions/verqueryvalue.asp[^] http://www.mindcracker.com/mindcracker/c_cafe/winapi/version.asp[^] http://gnuwin32.sourceforge.net/version.c.txt[^] http://www.google.com/search?num=20&hl=en&lr=&safe=off&c2coff=1&q=verqueryvalue+GetFileVersionInfo&btnG=Search[^] http://www.codeproject.com/file/fileversioninfo.asp[^]


              "Opinions are neither right nor wrong. I cannot change your opinion. I can, however, change what infl

              1 Reply Last reply
              0
              • C charu123

                I am not able to implement GetAdaptersInfo becoz it is not recognizing some header files. Is there any other way i can implement it. Probably read from some file etc. Can u tell me how to get CPU speed. Thanks U get wht u Give

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

                charu123 wrote: I am not able to implement GetAdaptersInfo becoz it is not recognizing some header files. This makes no sense. Functions do not have the ability or capacity to recognize anything compiler-related. Perhaps you meant that the compiler is unable to locate a particular header file. charu123 wrote: Can u tell me how to get CPU speed. There are several ways of doing this, some better than others. Here is a Delphi example (it's a trivial exercise to convert to C). You can also look in the registry at HKEY_LOCAL_MACHINE\HARDWARE\DESCRIPTION\System\CentralProcessor\0. I'ved used the following before:

                unsigned __int64 start, stop;
                unsigned __int64 nCtr, nFreq, nCtrStop;
                QueryPerformanceFrequency((LARGE_INTEGER *) &nFreq);

                _asm _emit 0x0F
                _asm _emit 0x31
                _asm mov DWORD PTR start, eax
                _asm mov DWORD PTR [start + 4], edx

                QueryPerformanceCounter((LARGE_INTEGER *) &nCtrStop);

                nCtrStop += nFreq;

                do
                {
                QueryPerformanceCounter((LARGE_INTEGER *) &nCtr);
                } while (nCtr < nCtrStop);

                _asm _emit 0x0F
                _asm _emit 0x31
                _asm mov DWORD PTR stop, eax
                _asm mov DWORD PTR [stop + 4], edx

                // stop-start is speed in Hz
                // divided by 1,000,000 is speed in MHz


                "Opinions are neither right nor wrong. I cannot change your opinion. I can, however, change what influences your opinion." - David Crow

                1 Reply Last reply
                0
                • P P Rex

                  Try this, you should get Devicename, port and the drivername of your default printer CPrintDialog dlg(FALSE); if (!dlg.GetDefaults()) AfxMessageBox(_T("You have no default printer!")); else { CString strDescription; strDescription.Format(_T("Your default printer is %s on %s using %s."), (LPCTSTR) dlg.GetDeviceName(), (LPCTSTR) dlg.GetPortName(), (LPCTSTR) dlg.GetDriverName()); AfxMessageBox(strDescription); } P-Man

                  C Offline
                  C Offline
                  charu123
                  wrote on last edited by
                  #11

                  I am getting an error sayin The data area passed to a system call is too small. theSIZE i have declared is 5000. please tell m ewhr i am going wrong in this code snippet. char DevName[100]; sprintf(DevName,"%s",(LPCTSTR)dlg.GetDeviceName()); HANDLE phPrinter=NULL; DWORD dwBytesNeeded; PRINTER_INFO_2 *pst; BYTE pPrinter; DWORD sizeReq=SIZE; OpenPrinter(DevName,&phPrinter,NULL); GetPrinter(phPrinter, 2, &pPrinter, sizeReq, &dwBytesNeeded); pst=(PRINTER_INFO_2 *)malloc(dwBytesNeeded); char j[SIZE]; sprintf(j,"%l",pst->AveragePPM); U get wht u Give

                  1 Reply Last reply
                  0
                  • C charu123

                    I am not able to implement GetAdaptersInfo becoz it is not recognizing some header files. Is there any other way i can implement it. Probably read from some file etc. Can u tell me how to get CPU speed. Thanks U get wht u Give

                    C Offline
                    C Offline
                    charu123
                    wrote on last edited by
                    #12

                    I am getting an error sayin The data area passed to a system call is too small. theSIZE i have declared is 5000. please tell m ewhr i am going wrong in this code snippet. char DevName[100]; sprintf(DevName,"%s",(LPCTSTR)dlg.GetDeviceName()); HANDLE phPrinter=NULL; DWORD dwBytesNeeded; PRINTER_INFO_2 *pst; BYTE pPrinter; DWORD sizeReq=SIZE; OpenPrinter(DevName,&phPrinter,NULL); GetPrinter(phPrinter, 2, &pPrinter, sizeReq, &dwBytesNeeded); pst=(PRINTER_INFO_2 *)malloc(dwBytesNeeded); char j[SIZE]; sprintf(j,"%l",pst->AveragePPM); U get wht u Give

                    1 Reply Last reply
                    0
                    • D David Crow

                      charu123 wrote: NIC Address: IP Address: To get the MAC address, use GetAdaptersInfo(). To get the IP address, use gethostname() followed by gethostbyname(). charu123 wrote: Browser Information: Since more than one browser can be present, this question cannot be answered directly. One approach would be to call FindExecutable() with the name of some .html file. Then query that executable using GetFileVersionInfo() and VerQueryValue().


                      "Opinions are neither right nor wrong. I cannot change your opinion. I can, however, change what influences your opinion." - David Crow

                      C Offline
                      C Offline
                      charu123
                      wrote on last edited by
                      #13

                      hi david, I ma getting the following error " the instruction at a memory location reference memory at . the memory could not be written." Could u point out where I am going wrong. char b[1000],a[1000],file[1000]="trial.html"; char path[1000]="C:\\Documents and Settings\\bhoomika.WIPHP_DOMAIN\\Desktop"; //CString a; LPTSTR data; data=(char*)malloc(1000); VS_FIXEDFILEINFO *pFileInfo; UINT BufLen; FindExecutable(file,path,data); DWORD dwHandle, dwLen; dwLen = GetFileVersionInfoSize (data, &dwHandle); LPTSTR lpData; lpData=(char*)malloc(sizeof(BUF)); if (!GetFileVersionInfo (data, dwHandle, dwLen, lpData)) { free (lpData); lpData = NULL; AfxMessageBox ("VersionInfo: not found\n"); } if (!VerQueryValue(lpData,"\\",(LPVOID*) &pFileInfo,(PUINT) &BufLen)) { printf ("VersionInfo: not found\n"); } else { sprintf (a,"MajorVersion: %d", HIWORD(pFileInfo->dwProductVersionMS)); m_ctrlBrowser.SetWindowText(a); sprintf (b,"MinorVersion: %d\n",LOWORD(pFileInfo->wProductVersionMS)); } free(data); return TRUE; Thanks For all the help. U get wht u Give

                      D 1 Reply Last reply
                      0
                      • C charu123

                        hi david, I ma getting the following error " the instruction at a memory location reference memory at . the memory could not be written." Could u point out where I am going wrong. char b[1000],a[1000],file[1000]="trial.html"; char path[1000]="C:\\Documents and Settings\\bhoomika.WIPHP_DOMAIN\\Desktop"; //CString a; LPTSTR data; data=(char*)malloc(1000); VS_FIXEDFILEINFO *pFileInfo; UINT BufLen; FindExecutable(file,path,data); DWORD dwHandle, dwLen; dwLen = GetFileVersionInfoSize (data, &dwHandle); LPTSTR lpData; lpData=(char*)malloc(sizeof(BUF)); if (!GetFileVersionInfo (data, dwHandle, dwLen, lpData)) { free (lpData); lpData = NULL; AfxMessageBox ("VersionInfo: not found\n"); } if (!VerQueryValue(lpData,"\\",(LPVOID*) &pFileInfo,(PUINT) &BufLen)) { printf ("VersionInfo: not found\n"); } else { sprintf (a,"MajorVersion: %d", HIWORD(pFileInfo->dwProductVersionMS)); m_ctrlBrowser.SetWindowText(a); sprintf (b,"MinorVersion: %d\n",LOWORD(pFileInfo->wProductVersionMS)); } free(data); return TRUE; Thanks For all the help. U get wht u Give

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

                        charu123 wrote: lpData=(char*)malloc(sizeof(BUF)); I think this should be lpData=(char*)malloc(dwLen). charu123 wrote: sprintf (b,"MinorVersion: %d\n",LOWORD(pFileInfo->wProductVersionMS)); The compiler should have complained about this one as wProductVersionMS is not a valid member name. Other than that, and the lack of error checking, what you have should work. You do, however, seem to be confused as to when to use MFC and when not to. Unless there is no MFC equivalent for some Win32 function, it really makes no sense to mix the two. Here is a modified version of your code:

                        VS_FIXEDFILEINFO *pFileInfo;
                        LPCTSTR pszFile = "trial.html",
                        pszPath = "C:\\Documents and Settings\\bhoomika.WIPHP_DOMAIN\\Desktop";
                        CString strExecutable,
                        strResult;
                        DWORD dwHandle,
                        dwVerSize;
                        LPBYTE pBuffer;
                        UINT uBufLen;

                        FindExecutable(pszFile, pszPath, strExecutable.GetBuffer(_MAX_PATH));
                        strExecutable.ReleaseBuffer();

                        dwVerSize = GetFileVersionInfoSize(strExecutable, &dwHandle);
                        if (dwVerSize > 0)
                        {
                        pBuffer = new BYTE[dwVerSize];
                        if (NULL != pBuffer)
                        {
                        if (GetFileVersionInfo(strExecutable, dwHandle, dwVerSize, pBuffer) != FALSE)
                        {
                        if (VerQueryValue(pBuffer, "\\", (LPVOID *) &pFileInfo, &uBufLen) != FALSE)
                        {
                        strResult.Format("MajorVersion: %u\nMinorVersion: %u",
                        HIWORD(pFileInfo->dwProductVersionMS),
                        LOWORD(pFileInfo->dwProductVersionMS));
                        }
                        else
                        strResult.Format("VerQueryValue() failed. Error = %lu", GetLastError());
                        }
                        else
                        strResult.Format("GetFileVersionInfo() failed. Error = %lu", GetLastError());

                            delete \[\] pBuffer;
                        }
                        

                        }
                        else
                        strResult.Format("GetFileVersionInfoSize() failed. Error = %lu", GetLastError());

                        AfxMessageBox(strResult);


                        "Opinions are neither right nor wrong. I cannot change your opinion. I can, however, change what influences your opinion." - David Crow

                        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