WNetGetUser

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I would liike to know which C# function is the replacement for the following
function, and how do I use Platform SDK functions which r not updated in .Net
Framework.

CHAR nUser[100];
DWORD mError = 80,test ;
test = WNetGetUser(NULL, nUser, &mError);

if(test == NO_ERROR){
// Show Current Log On User
AfxMessageBox(nUser,MB_OK);
}
 
AbdSol said:
I would liike to know which C# function is the replacement for the following
function, and how do I use Platform SDK functions which r not updated in .Net
Framework.

CHAR nUser[100];
DWORD mError = 80,test ;
test = WNetGetUser(NULL, nUser, &mError);

if(test == NO_ERROR){
// Show Current Log On User
AfxMessageBox(nUser,MB_OK);
}

How about this:

System.Security.Principal.WindowsIdentity wid
= System.Security.Principal.WindowsIdentity.GetCurrent();

string user = wid.Name;

System.Windows.Forms.MesssageBox.Show( user );
 
It works but not as I want. the output is includes the computer name
"computername\user"

Mohammad said:
I would liike to know which C# function is the replacement for the following
function, and how do I use Platform SDK functions which r not updated in .Net
Framework.

CHAR nUser[100];
DWORD mError = 80,test ;
test = WNetGetUser(NULL, nUser, &mError);

if(test == NO_ERROR){
// Show Current Log On User
AfxMessageBox(nUser,MB_OK);
}

How about this:

System.Security.Principal.WindowsIdentity wid
= System.Security.Principal.WindowsIdentity.GetCurrent();

string user = wid.Name;

System.Windows.Forms.MesssageBox.Show( user );
 
AbdSol said:
It works but not as I want. the output is includes the computer name
"computername\user"

Then how about:

System.Security.Principal.WindowsIdentity wid
= System.Security.Principal.WindowsIdentity.GetCurrent();

string[] domainAndUser = wid.Name.Split( '\\' );
user = domainAndUser[1];

System.Windows.Forms.MesssageBox.Show( user );

I mean... RT(*BEEB*)M for goodness sake.
 
Back
Top