|
|
|
Hi,
Am developing a VC++ application where i need to get the username.
I have tried using GetUserName() and also USERNAME. But when i run the application on Vista as "Run as administrator", this is returning the admin's username and not the username with which the system is logged in.
Any suggestions on how to get the username with which the system is logged in when the application is "Run as administrator"?
Thanks
|
|
|
|
|
You could try GetEnvironmentStrings .
Then look for USERNAME variable.
|
|
|
|
|
Thanks for the reply. I have already tried that. It is returning the administrators username when i run the app as "Run as administrator". But i want the system logged on user name.
|
|
|
|
|
The reason why I gave you the answer is this -
I run a normal command prompt and run the set command which lists the environment variables.
Here it lists USERNAME=xxx .
I then run the command prompt as administrator and then do the same thing.
The USERNAME variable lists the same user.
|
|
|
|
|
Did you see here[^]
You need to google first, if you have "It's urgent please" mentioned in your question.
_AnShUmAn_
|
|
|
|
|
Have you looked at LsaEnumerateLogonSessions() ?
"One man's wage rise is another man's price increase." - Harold Wilson
"Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons
"Man who follows car will be exhausted." - Confucius
|
|
|
|
|
hey, i want to add custom bitmap on toolbar buttons in WIN32 c++..tell me how i can do this??
|
|
|
|
|
Take a look at TB_ADDBITMAP .
|
|
|
|
|
u know any book of WIN32....or any website?
|
|
|
|
|
The documentation has a small code snippet on how this can be done - http://msdn.microsoft.com/en-us/library/bb787289(VS.85).aspx
|
|
|
|
|
|
Is there any efficient way to share OpenGL resources in multithreaded programming?
|
|
|
|
|
Could you please elaborate ? What do you mean by resources exactly ? And how do you want to share them ?
|
|
|
|
|
Hello,everybody !
I want to set a 25 hours timer in the dialog based project.There will be plenty of database operation in the menber function.
I used this way:
1、SetTimer
when I used it ,the window interface always death after 10 minutes ago.
2、Multi-Threading
but it faild to ,when the function execute several times,it no longer to run anymore.
DWORD CTestDlg::ThreadProc(LPARAM lParam)
{
typedef BOOL (_stdcall *MYSWITCH)();
MYSWITCH MySwitchToThread;
HINSTANCE hInst = LoadLibrary("Kernel32.dll");
if (hInst != NULL)
MySwitchToThread = (MYSWITCH)GetProcAddress(hInst, "SwitchToThread");
if(!MySwitchToThread)
return -1;
CTestDlg *pDlg = (CTestDlg *)lParam;
TRACE( "Work thread pDlg --- %d\n ",pDlg);
UINT oldTickCount,newTickCount;
oldTickCount = GetTickCount();
while(TRUE)
{
while(TRUE)
{
newTickCount = GetTickCount();
if(newTickCount - oldTickCount >= 10000)
{
oldTickCount = newTickCount;
break;
}
else
MySwitchToThread();
}
CFile file("MyThread.txt",CFile::modeReadWrite|CFile::modeNoTruncate);
CTime time;
CString str="";
time = CTime::GetCurrentTime();
str.Format("%d-%02d-%02d %02d:%02d:%02d Thread Running...\r\n",
time.GetYear(),time.GetMonth(),time.GetDay(),
time.GetHour(),time.GetMinute(),time.GetSecond());
file.SeekToEnd();
file.Write(str,str.GetLength());
file.Flush();
file.Close();
Sleep(100);
pDlg->Fun1();
Sleep(100);
pDlg->Fun2();
return 0;
}
return 0;
}
then run the thread:
BOOL CTestDlg::OnInitDialog()
{
CDialog::OnInitDialog();
......
CreateThread(NULL,0,(LPTHREAD_START_ROUTINE)ThreadProc,this,0,NULL);
}
There a better way ?
modified on Sunday, April 11, 2010 11:30 PM
|
|
|
|
|
You can use SetTimer like this -
SetTimer(hWnd 0, 25 * 60 * 60 * 1000);
|
|
|
|
|
|
Koma Wang wrote: I want to set a 25 hours timer...
Have you tried setting a 60000ms timer and when the timer has "fired" 1500 times, you know that it has been 25 hours?
Another option would be to create a scheduled task within Windows and let it handle when to run the program.
"One man's wage rise is another man's price increase." - Harold Wilson
"Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons
"Man who follows car will be exhausted." - Confucius
|
|
|
|
|
thanks !
I used Windows Task Scheduler instead.
|
|
|
|
|
Hi,
I often hear or read about Parent/Child relationship with regards to Process
but is there any relationship with regards to threads
For instance if Thread A AFXbeginThread B and Thread B AFXBeginThread C
if thread A goes away do Thread B and C still live as long as the process is alive
thankx
|
|
|
|
|
ForNow wrote: if thread A goes away do Thread B and C still live as long as the process is alive
yes
|
|
|
|
|
If you are using Nested Threads like NT as main thread & T1 & T2 are as two sub thread under NT, then the answer will be YES.
But, other than called it as parent-child relation, I would rather like to call it as ordered relation, like threads will execute,in an order they are placed in the program.
As threads are mainly uses systems resources, so one can not delete a thread until that gets completed.
NOTE: though using various time slashing algorithm one can switch between threads if he/she wants.
--Rupam
System Analysts
|
|
|
|
|
There is no parent-child relationship that I'm aware of, but there's one caveat: if the main thread dies (the thread that calls WinMain ) dies so does the entire process.
Steve
|
|
|
|
|
Is a CWinAPP so special or does the process need at least one thread alive
|
|
|
|