|
You need sample code for using a function that takes no arguments and returns a simple type. Are you really a senior developer?
"Love people and use things, not love things and use people." - Unknown
"To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne
|
|
|
|
|
pooja_friends wrote: Such as i want to get Which user(administrator or user),user type etc
You can use CheckTokenMembership . Here is the link to this in MSDN -> http://msdn.microsoft.com/en-us/library/aa376389(VS.85).aspx[^]
Source for IsUserAdmin is shown here, you can customize it for your needs.
Nibu thomas
Microsoft MVP for VC++
Code must be written to be read, not by the compiler, but by another human being.
Programming Blog: http://nibuthomas.wordpress.com
|
|
|
|
|
'IsUserAnAdmin' : undeclared identifier
I have got this error
|
|
|
|
|
pooja_friends wrote: 'IsUserAnAdmin' : undeclared identifier
MSDN says that you'll need to link to shell32.lib and #include <shlobj.h> to use this function.
Nobody can give you wiser advice than yourself. - Cicero
.·´¯`·->Rajesh<-·´¯`·.
Codeproject.com: Visual C++ MVP
|
|
|
|
|
how can i link shell32.lib
|
|
|
|
|
pooja_friends wrote: how can i link shell32.lib
#pragma comment(lib, "Shell32.lib")
Nobody can give you wiser advice than yourself. - Cicero
.·´¯`·->Rajesh<-·´¯`·.
Codeproject.com: Visual C++ MVP
|
|
|
|
|
My code
#include "stdafx.h"
#include "useradmin.h"
#include "useradminDlg.h"
#include <shlobj.h>
#pragma comment(lib, "Shell32.lib")
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CAboutDlg dialog used for App About
void CUseradminDlg::OnOK()
{
// TODO: Add extra validation here
if(IsUserAnAdmin())
AfxMessageBox(_T("User is an administrator"));
else
AfxMessageBox(_T("User is not an administrator"));
CDialog::OnOK();
}
I got Following error :
**********************
77) : error C2065: 'IsUserAnAdmin' : undeclared identifier
Generating Code...
Error executing cl.exe.
what is problem
|
|
|
|
|
pooja_friends wrote: 77) : error C2065: 'IsUserAnAdmin' : undeclared identifier
Probably your SDK is too old. See question no. 2.2 in this FAQ article[^]
Nobody can give you wiser advice than yourself. - Cicero
.·´¯`·->Rajesh<-·´¯`·.
Codeproject.com: Visual C++ MVP
|
|
|
|
|
TCHAR infoBuf[INFO_BUFFER_SIZE];
DWORD bufCharCount = INFO_BUFFER_SIZE;
CString s;
// Get and display the name of the computer.
bufCharCount = INFO_BUFFER_SIZE;
if( !GetComputerName( infoBuf, &bufCharCount ) )
::MessageBox(0,"GetComputerName","Cannot computer name",0);
s.Format("%s", infoBuf );
::MessageBox(0,s,"Computer Name",0);
// Get and display the user name.
bufCharCount = INFO_BUFFER_SIZE;
if( !GetUserName( infoBuf, &bufCharCount ) )
::MessageBox(0,"GetUserName","Can not read user name",0);
s.Format("%s", infoBuf );
::MessageBox(0,s,"User Name",0);
This code display system name and user name correctly
I want user account type (administrator or limited)
|
|
|
|
|
pooja_friends wrote: I want user account type (administrator or limited)
I have already answered this query.
Nobody can give you wiser advice than yourself. - Cicero
.·´¯`·->Rajesh<-·´¯`·.
Codeproject.com: Visual C++ MVP
|
|
|
|
|
Hi friend,
I am using this code in my system to identify What is computer name & currently who is using it.
<code>/////////////////////////////////////////////////////////////////////
DWORD i;
TCHAR infoBuf[INFO_BUFFER_SIZE];
DWORD bufCharCount = INFO_BUFFER_SIZE;
// Get and display the name of the computer.
bufCharCount = INFO_BUFFER_SIZE;
if( !GetComputerName( infoBuf, &bufCharCount ) )
::MessageBox(0,"GetComputerName","Cannot computer name",0);
s.Format("%s", infoBuf );
::MessageBox(0,s,"Computer Name",0);
// Get and display the user name.
bufCharCount = INFO_BUFFER_SIZE;
if( !GetUserName( infoBuf, &bufCharCount ) )
::MessageBox(0,"GetUserName","Can not read user name",0);
s.Format("%s", infoBuf );
::MessageBox(0,s,"User Name",0);
/////////////////////////////////////////////////////////////////////
</code>
Have Good Luck...
Jagdish Bhimbha
S/W Developer
|
|
|
|
|
BOOL IsUserAdmin(VOID)
/*++
Routine Description: This routine returns TRUE if the caller's
process is a member of the Administrators local group. Caller is NOT
expected to be impersonating anyone and is expected to be able to
open its own process and process token.
Arguments: None.
Return Value:
TRUE - Caller has Administrators local group.
FALSE - Caller does not have Administrators local group. --
*/
{
BOOL b;
SID_IDENTIFIER_AUTHORITY NtAuthority = SECURITY_NT_AUTHORITY;
PSID AdministratorsGroup;
b = AllocateAndInitializeSid(
&NtAuthority,
2,
SECURITY_BUILTIN_DOMAIN_RID,
DOMAIN_ALIAS_RID_ADMINS,
0, 0, 0, 0, 0, 0,
&AdministratorsGroup);
if(b)
{
if (!CheckTokenMembership( NULL, AdministratorsGroup, &b))
{
b = FALSE;
}
FreeSid(AdministratorsGroup);
}
return(b);
}
I have add this function to find User account type but i got following error
CheckTokenMembership' : undeclared identifier
|
|
|
|
|
Hello...
The function CheckTokenMembership() requires following things :
Header : Declared in Winbase.h; include Windows.h.
Library : Use Advapi32.lib.
DLL : Requires Advapi32.dll
Check by including this header file.
Next solution is you can you something like :
Bool IsUserAdmin(VOID)
{
DWORD i;
TCHAR infoBuf[INFO_BUFFER_SIZE];
DWORD bufCharCount = INFO_BUFFER_SIZE;
char admin[]="Admin"
Have Best Luck this time...
Jagdish Bhimbha
S/W Developer
|
|
|
|
|
Hi all,
"Attempt to Update or Delete failed." and "Recordset is read-only"
These two error is occur when i update the record.
how can i resolve them.
Thanks in advance.
IN A DAY, WHEN YOU DON'T COME ACROSS ANY PROBLEMS - YOU CAN BE SURE THAT YOU ARE TRAVELLING IN A WRONG PATH
|
|
|
|
|
What "Connection String" did you use from?
(e.g.
"SELECT * FROM [MyTable]" )
|
|
|
|
|
i m not using SQL Queries.
i m using CRecordset derived class, and directly assign the value of database variable to my dialog variable.
IN A DAY, WHEN YOU DON'T COME ACROSS ANY PROBLEMS - YOU CAN BE SURE THAT YOU ARE TRAVELLING IN A WRONG PATH
|
|
|
|
|
ThatsMe. wrote: how can i resolve them.
By opening the recordset as updateable.
"Love people and use things, not love things and use people." - Unknown
"To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne
|
|
|
|
|
Hi All,
I have a doubt in serial communication.
I am using non-overlapped io serial communication inside a thread in my application. So while coomunicating with the instrument, the thread gets blocked without blocking the application.
Now what is the difference between the above scenario and overlapped io communication?
Thanks for your reply .
|
|
|
|
|
In overlapped IO, the system will signal an event when the operation complete (read or write for example). But you still have to wait for that before processing your data (sure, you can't process your data if it is not available yet...). So, in general you still have to use a thread to wait on the event.
The big difference is that using this technique, you'll be able to wait for multiple events. With a blocking call, you can't do anything but wait until the function returns.
|
|
|
|
|
Hi Cedric,
Thanks for your reply.
If i place the blocking call in a thread, then the application will bot be blocked.
In this scenario what is the difference between the two types of communication?
|
|
|
|
|
No, your application won't be blocked but you can't wait for other events in the same thread.
Another point I made: by using overlapped IO, you will in general wait for the event to be signaled (so the read operation to finish for example). To do that, you will block the thread which is calling WaitForSingleObject. So, in general, even when I use overlapped IO I handle that in a separate thread. The difference, as I said before, is that you can wait for multiple events to happen instead of just one. For example you could be reading two serial ports in the same thread.
|
|
|
|
|
Communications events can occur at any time in the course of using a communications port. The two steps involved in receiving notification of communications events are as follows:
* SetCommMask sets the desired events that cause a notification.
* WaitCommEvent issues a status check. The status check can be an overlapped or nonoverlapped operation, just as the read and write operations can be.
There are two interesting side effects of SetCommMask and WaitCommEvent. First, if the communications port is open for nonoverlapped operation, WaitCommEvent will be blocked until an event occurs. If another thread calls SetCommMask to set a new event mask, that thread will be blocked on the call to SetCommMask. The reason is that the original call to WaitCommEvent in the first thread is still executing. The call to SetCommMask blocks the thread until the WaitCommEvent function returns in the first thread. This side effect is universal for ports open for nonoverlapped I/O. If a thread is blocked on any communications function and another thread calls a communications function, the second thread is blocked until the communications function returns in the first thread. The second interesting note about these functions is their use on a port open for overlapped operation. If SetCommMask sets a new event mask, any pending WaitCommEvent will complete successfully, and the event mask produced by the operation is NULL.
For more details you can refer link given below:
http://msdn.microsoft.com/en-us/library/ms810467.aspx[^]
buntyrolln
|
|
|
|
|
Continuation of above reply ....
you can use overlapped-IO operation for communication with serial com port.
Read code snippet for overlapped-IO is given below:
DWORD dwRead;
BOOL fWaitingOnRead = FALSE;
OVERLAPPED osReader = {0};
osReader.hEvent = CreateEvent(NULL, TRUE, FALSE, NULL);
if (osReader.hEvent == NULL)
if (!fWaitingOnRead) {
if (!ReadFile(hComm, lpBuf, READ_BUF_SIZE, &dwRead, &osReader)) {
if (GetLastError() != ERROR_IO_PENDING)
else
fWaitingOnRead = TRUE;
}
else {
HandleASuccessfulRead(lpBuf, dwRead);
}
}
buntyrolln
|
|
|
|
|
Hi all,
I m working on VC++ 2005, MFC-SDI type application, I m using ODBC for connection of Access Database.
CRecordset use as Derived class of Database.
Here i want to get the index of Currently save Record.
Please tell me how can i do this.
I m waiting for your valuable suggestions.
Thanks in advance.
IN A DAY, WHEN YOU DON'T COME ACROSS ANY PROBLEMS - YOU CAN BE SURE THAT YOU ARE TRAVELLING IN A WRONG PATH
|
|
|
|
|
ThatsMe. wrote: CRecordset use as Derived class of Database.
CRecordset is derived from CObject not Database . If you have something different, perhaps that is the cause of your problem.
"Love people and use things, not love things and use people." - Unknown
"To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne
|
|
|
|