Programming Forums

Programming Forums (http://www.programmingforums.org/forumindex.php)
-   C++ (http://www.programmingforums.org/forum15.html)
-   -   Computer name w/C++ (http://www.programmingforums.org/showthread.php?t=13626)

snipertomcat Jul 25th, 2007 6:38 PM

Computer name w/C++
 
Hey guys,

I have a little program i created using c++. All the program does is runs a dxdiag on the local machine, then outputs the results in a .xml file on the desktop. Then code looks like this:


:

#include <iostream>

using namespace std;

int main()
{
    system("dxdiag /x jxdiagRESULTS.xml");
}



I need to save the file to a folder on a server with the computer name as the file name. Is there any way to find the computer name with c++?

Random-Spirit Jul 25th, 2007 6:48 PM

Hmm here is an interesting idea, why not have a look on Google? Or better yet look at the Win32 api docs!

I will save you the effort (hardly any really).

In windows.h you will find an interestingly named function called GetComputerNameEx(…). I wonder what that could do?

You can look up the parameters yourself using the Win32 documentation on MSDN or your local copy of the docs either in a Platform/Windows SDK or MSDN distribution.

Prm753 Jul 26th, 2007 1:14 AM

You can also use the COMPUTERNAME environment variable to get your name. Call GetEnvironmentVariable(...):

:

DWORD WINAPI GetEnvironmentVariable(
  LPCTSTR lpName,
  LPTSTR lpBuffer,
  DWORD nSize
);


and use the return value in your program.

snipertomcat Jul 26th, 2007 10:40 AM

@Random-Spirit -- Here is another interesting idea...thank you for the help, but if you dont feel like responding, dont. I appreciate the help.

Infinite Recursion Jul 26th, 2007 11:45 AM

http://www.cplusplus.com/reference/c...ib/getenv.html


For Linux:

:

#include <iostream>

using namespace std;

int main (void)
{
        char *x = getenv("HOSTNAME");
        cout << x << endl;
        return 0;
}


For Windows... the environment variable you want is "COMPUTERNAME".

snipertomcat Jul 26th, 2007 3:21 PM

Got it! Thanks Guys.


All times are GMT -5. The time now is 3:08 AM.

Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC