Programming Forums
User Name Password Register
 

RSS Feed
FORUM INDEX | TODAY'S POSTS | UNANSWERED THREADS | ADVANCED SEARCH

Reply
 
Thread Tools Display Modes
Old Jul 25th, 2007, 5:38 PM   #1
snipertomcat
Programmer
 
snipertomcat's Avatar
 
Join Date: Nov 2005
Location: Spring Valley, CA
Posts: 52
Rep Power: 3 snipertomcat is on a distinguished road
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)
snipertomcat is offline   Reply With Quote
Old Jul 25th, 2007, 5:48 PM   #2
Random-Spirit
Unverified User
 
Join Date: Jul 2007
Location: England
Posts: 22
Rep Power: 0 Random-Spirit is an unknown quantity at this point
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.
Random-Spirit is offline   Reply With Quote
Old Jul 26th, 2007, 12:14 AM   #3
Prm753
Professional Programmer
 
Prm753's Avatar
 
Join Date: Oct 2005
Location: United States
Posts: 447
Rep Power: 4 Prm753 is on a distinguished road
Send a message via AIM to Prm753 Send a message via MSN to Prm753
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
Prm753 is offline   Reply With Quote
Old Jul 26th, 2007, 9:40 AM   #4
snipertomcat
Programmer
 
snipertomcat's Avatar
 
Join Date: Nov 2005
Location: Spring Valley, CA
Posts: 52
Rep Power: 3 snipertomcat is on a distinguished road
@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)
snipertomcat is offline   Reply With Quote
Old Jul 26th, 2007, 10:45 AM   #5
Infinite Recursion
Programming Guru
 
Infinite Recursion's Avatar
 
Join Date: Jul 2004
Location: United States
Posts: 3,467
Rep Power: 8 Infinite Recursion is on a distinguished road
Send a message via MSN to Infinite Recursion Send a message via Yahoo to Infinite Recursion
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."
Infinite Recursion is offline   Reply With Quote
Old Jul 26th, 2007, 2:21 PM   #6
snipertomcat
Programmer
 
snipertomcat's Avatar
 
Join Date: Nov 2005
Location: Spring Valley, CA
Posts: 52
Rep Power: 3 snipertomcat is on a distinguished road
Got it! Thanks Guys.
__________________
if (u=an_asshole) then GOTO (hell)
snipertomcat is offline   Reply With Quote
Reply

Bookmarks

« Previous Thread in Forum | Next Thread in Forum »

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

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




DaniWeb IT Discussion Community
All times are GMT -5. The time now is 11:04 AM.

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