how could i get the username as a string? this gets it as "char", but i need it as a string. -
#include <iostream>
-
#include <windows.h>
-
using namespace std;
-
int main()
-
{
-
char acUserName[100];
-
DWORD nUserName = sizeof(acUserName);
-
if (GetUserName(acUserName, &nUserName)) {
-
cout << "User name is " << acUserName << "." << endl;
-
cin.get();
-
}
-
return 0;
-
}
-
thanks
7 46459
how could i get the username as a string? this gets it as "char", but i need it as a string. -
#include <iostream>
-
#include <windows.h>
-
using namespace std;
-
int main()
-
{
-
char acUserName[100];
-
DWORD nUserName = sizeof(acUserName);
-
if (GetUserName(acUserName, &nUserName)) {
-
cout << "User name is " << acUserName << "." << endl;
-
cin.get();
-
}
-
return 0;
-
}
-
thanks
A char array is the same as a string except it has a '\0' terminator. If you want to construct a char array to a string, try this: -
string userName(acUserName);
-
Why would you want it as a string?
Maybe like this: -
#include <iostream>
-
#include <windows.h>
-
using namespace std;
-
#include <string>
-
int main()
-
{
-
char acUserName[100];
-
string UserName;
-
DWORD nUserName = sizeof(acUserName);
-
if (GetUserName(acUserName, &nUserName)) {
-
UserName = acUserName;
-
cout << "User name is " << UserName << "." << endl;
-
cin.get();
-
}
-
return 0;
-
}
-
i changed my code a little bit and i now got the problem
cannot convert 'std::basic_string<char, std::char_traits<char>, std::allocator<char> >' to 'char*' for argument '1' to 'bool EmptyDirectory(char*)' -
ON_COMMAND_BY (delhistory){
-
char acUserName[100];
-
string UserName;
-
DWORD nUserName = sizeof(acUserName);
-
if (GetUserName(acUserName, &nUserName))
-
UserName = acUserName;
-
list.add("History");if( EmptyDirectory( "C:\\Documents and Settings\\"+UserName+"\\Local Settings\\History\\History.IE5\\" ) != 0 ){delhistory.disable();}else{}}
-
[i want it as a string so i can add it as part of '"C:\\Docu...."+UserName+"...."
thanks,
nate
i changed my code a little bit and i now got the problem
cannot convert 'std::basic_string<char, std::char_traits<char>, std::allocator<char> >' to 'char*' for argument '1' to 'bool EmptyDirectory(char*)' -
ON_COMMAND_BY (delhistory){
-
char acUserName[100];
-
string UserName;
-
DWORD nUserName = sizeof(acUserName);
-
if (GetUserName(acUserName, &nUserName))
-
UserName = acUserName;
-
list.add("History");if( EmptyDirectory( "C:\\Documents and Settings\\"+UserName+"\\Local Settings\\History\\History.IE5\\" ) != 0 ){delhistory.disable();}else{}}
-
[i want it as a string so i can add it as part of '"C:\\Docu...."+UserName+"...."
thanks,
nate
That means that the EmptyDirectory() function takes a pointer to a character or a char array. Maybe you don't want a string after all.
You can try two things:
Make everything char arrays and use strcpy(): -
char path[200];
-
strcpy(path, "C:\\Documents and Settings\\");
-
strcat(path, acUserName);
-
strcat(path, "\\Local Settings etc....");
-
if (EmptyDirectory(path) != 0){
-
//do stuff
-
}
-
or you can add .c_str() at the end of the whole path: -
if( EmptyDirectory( "C:\\Documents and Settings\\"+UserName+"\\Local Settings\\History\\History.IE5\\".c_str()) != 0 )
-
//do stuff
-
Try it and see what happens.
IGNORE!!
i tried -
ON_COMMAND_BY (delhistory) {list.add("History");
-
char acUserName[100];
-
string UserName;
-
DWORD nUserName = sizeof(acUserName);
-
if (GetUserName(acUserName, &nUserName))
-
UserName = acUserName;
-
if( EmptyDirectory( "C:\\Documents and Settings\\"+UserName+"\\Local Settings\\History\\History.IE5\\".c_str() ) != 0 )
-
{delhistory.disable();}else{}}
-
and i got the error:
request for member 'c_str' in '"\\Local Settings\\History\\History.IE5\\"', which is of non-class type 'const char [37]'
ill try the str copy way and post another message
whoopee!! -
ON_COMMAND_BY (delhistory) {list.add("History");
-
char acUserName[100];
-
string UserName;
-
DWORD nUserName = sizeof(acUserName);
-
if (GetUserName(acUserName, &nUserName))
-
UserName = acUserName;
-
-
char path[200];
-
strcpy(path, "C:\\Documents and Settings\\");
-
strcat(path, acUserName);
-
strcat(path, "\\Local Settings\\History\\");
-
if (EmptyDirectory(path) != 0){
-
-
delhistory.disable();}else{}}
-
worked!
thank you very much
whoopee!! -
ON_COMMAND_BY (delhistory) {list.add("History");
-
char acUserName[100];
-
string UserName;
-
DWORD nUserName = sizeof(acUserName);
-
if (GetUserName(acUserName, &nUserName))
-
UserName = acUserName;
-
-
char path[200];
-
strcpy(path, "C:\\Documents and Settings\\");
-
strcat(path, acUserName);
-
strcat(path, "\\Local Settings\\History\\");
-
if (EmptyDirectory(path) != 0){
-
-
delhistory.disable();}else{}}
-
worked!
thank you very much
You're welcome.
Sign in to post your reply or Sign up for a free account.
Similar topics
by: hplloyd |
last post by:
Hi I want to pick up the name of the logged in windows user for my ASP.NET
application.
When I use
System.Environment.UserName
i get ASPNET which is ofcourse not what I want
when I try...
|
by: William Stacey [MVP] |
last post by:
Is this a bug in fx2? I expect they did not carry forward all the StartInfo
properties to api used with Username/Password. When you remove
UserName/password, the window does not show as expected....
|
by: Brent Burkart |
last post by:
I am trying to capture the Windows Authenticated username, but I want to be
able to capture the login name that exists in IIS, not Windows. In order to
enter my company's intranet through the...
|
by: nikou_70 |
last post by:
I have a problem with ("auth_user") in asp,I try to use windows
username and password in asp page for limitation user access to pages,
but this server variable returns empty string, can you help me...
|
by: Paul |
last post by:
Hi,
I'm trying to kick off the iiscnfg.vbs from a webservice to export a
website's config to an xml file (And eventually populate other servers with
the config). I initially tried this using the...
|
by: Philip Wagenaar |
last post by:
I need to send printjobs to a printqueue under diffrent usernames. The
printsoftware on the queue is not very 'secure' so I can create a user on 1
system and send a printjob under it's name to the...
|
by: Kirk |
last post by:
The following C# web service works fine until you uncomment the lines
setting UserName and Password. Then the process starts as the
specified user, but hangs in a suspended state. In fact, any...
|
by: Kirk |
last post by:
The following C# web service works fine until you uncomment the lines
setting UserName and Password. Then, Process.Start throws an
Access is Denied Exception. This is with .NET 2.0, of
course...
|
by: None |
last post by:
Hi,
I have written a c# code to find the given username and password is
correct or not. (i.e the given username and password will be checked
against the active directory) But i don't know how...
|
by: tiijnar |
last post by:
Hi,
To get windows username Im using the following code.
public class GetWindowUsername {
public String getUser() {
String userName = System.getProperty("user.name");...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
by: ryjfgjl |
last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
|
by: emmanuelkatto |
last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud.
Please let me know.
Thanks!
Emmanuel
|
by: BarryA |
last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
by: Sonnysonu |
last post by:
This is the data of csv file
1 2 3
1 2 3
1 2 3
1 2 3
2 3
2 3
3
the lengths should be different i have to store the data by column-wise with in the specific length.
suppose the i have to...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
| |