![]() |
|
![]() |
|
|
Thread Tools | Display Modes |
|
|
#1 |
|
Programmer
Join Date: Nov 2005
Location: Spring Valley, CA
Posts: 52
Rep Power: 3
![]() |
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++?
__________________
if (u=an_asshole) then GOTO (hell) |
|
|
|
|
|
#2 |
|
Unverified User
Join Date: Jul 2007
Location: England
Posts: 22
Rep Power: 0
![]() |
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. |
|
|
|
|
|
#3 |
|
Professional Programmer
|
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.
__________________
The world's first athletic computer geek! The home of PrProgramsStudios How not to post a question: <-- Please don't reply |
|
|
|
|
|
#4 |
|
Programmer
Join Date: Nov 2005
Location: Spring Valley, CA
Posts: 52
Rep Power: 3
![]() |
@Random-Spirit -- Here is another interesting idea...thank you for the help, but if you dont feel like responding, dont. I appreciate the help.
__________________
if (u=an_asshole) then GOTO (hell) |
|
|
|
|
|
#5 |
|
Programming Guru
![]() ![]() ![]() |
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".
__________________
http://jasonpowers.net "There are a thousand hacking at the branches of evil to one who is striking at the root." |
|
|
|
|
|
#6 |
|
Programmer
Join Date: Nov 2005
Location: Spring Valley, CA
Posts: 52
Rep Power: 3
![]() |
Got it! Thanks Guys.
__________________
if (u=an_asshole) then GOTO (hell) |
|
|
|
![]() |
| Bookmarks |
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | |
| Display Modes | |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Trying to find a computer science job.. | csrocker101 | Coder's Corner Lounge | 12 | Jul 24th, 2007 8:15 AM |
| Build Computer for Low Price | PhilBon | Coder's Corner Lounge | 4 | Jun 11th, 2007 11:27 AM |
| test | lostcauz | Coder's Corner Lounge | 9 | Jul 18th, 2006 3:20 PM |
| what is computer programming? | pal | Coder's Corner Lounge | 14 | Dec 9th, 2005 10:22 AM |
| Computer - Freezing | coldDeath | Coder's Corner Lounge | 37 | Nov 23rd, 2005 9:35 AM |