AllExperts > C# 
Search      
C#
Volunteer
Answers to thousands of questions
 Home · More C# Questions · Answer Library  · Encyclopedia ·
More C# Answers
Question Library

Ask a question about C#
Volunteer
Experts of the Month
Expert Login

Awards

About Us
Tell friends
Link to Us
Disclaimer

 
 
 
 
About Srini Nagarajan
Expertise
can answer any kind of questions in ASP.NET, C#, VB.NET, ASP, SharePoint 2007, Coldfusion, Powerbuilder 7.00 / 8.00, JAVA servlets, MS SQL 2000 / MSSQL7, Sybase

Experience
Contact me if you need any custom development on ASP.NET, ASP, Coldfusion, Powerbuilder
 
   

You are here:  Experts > Computing/Technology > Microsoft .NET > C# > Full address of a user's Desktop

C# - Full address of a user's Desktop


Expert: Srini Nagarajan - 6/26/2005

Question
Hello sir,

I want to know how I can have the FULL adress of a user's "Desktop";
for example , for a user named "John", it can be like this:
 C:\Documents and Settings\John\Desktop

How can I acquire the above string for the user who is logged in the windows.

thank you very much.

Answer
Hi

Here is the code


<%
  '''''''''''''''''''''''''''''''''''''''''''''''''
  ' ADSI User Authentication Script
  ' Peter A. Bromberg  01/26/2001
  '''''''''''''''''''''''''''''''''''''''''''''''''
   ' Test here for a form post ...
  if request("GETUSER") = "" Then
   ' write out the test form
     With Response
     .write "<FORM ACTION=USER.ASP METHOD=POST>"
     .Write "<INPUT TYPE=TEXT NAME=oDomain>ENTER DOMAIN<BR>"
     .write "<INPUT TYPE=TEXT NAME=oUSer>ENTER USER NAME TO CHECK<BR>"
     .write "<INPUT TYPE=PASSWORD NAME=oPassword>ENTER USER PASSWORD<BR>"
     .Write "<INPUT TYPE =SUBMIT NAME=GETUSER VALUE=CHECK>"
     .write "</FORM>"
     end with
  
  else
  ' Form was autopostback, grab the form variables ...
       oDomain= Request("oDomain")
       oUser = Request("oUser")
       oPassword = Request("oPassword")
' begin "Kludge" VBScript error trapping  (see Javascript version for
try / catch handling)
on error resume next
' Set reference to the ADSI interface to NT User Manager ...
Set objUser = GetObject("WinNT://" & oDomain & "/" & oUser )

  if err.number <> 0 then
     Response.write "Login Error---"
     Response.end
  end if
  If len(objUser.FullName) < 1 then
        response.write "User Not Found!!!!"
        response.end
  else

on error resume next
' We verify the user password by using the ChangePassword method to change
' the password back to itself.
' Since this requires that first parameter password be correct, it's an easy'  way to circumvent the fact
' that NT won't give actual access to the user's password to make a comparison. ' Be aware that on some systems,
' Admin policy settings may force the password
' to have to be changed after X number of uses
' of this method...

 objUser.ChangePassword  oPassword, oPassword
  if err.number <> 0 then

     Response.write" BAD PASSWORD!"
     Response.end
  else  

' Now write out the ADSI User object properties that are supported by Windows 2000 ...

With Response
   .write "USER AUHTENTICATED!<BR>"
  .write "Properties for user " & objUser.FullName & ": <BR>"
  .Write "AccountExpirationDate: " & objUser.AccountExpirationDate & "<BR>"
  .Write "BadLoginCount: " & objUser.BadLoginCount & "<BR>"
  .write "Description: " & objUser.Description & "<BR>"
  .write "HomeDirectory: " & objUser.HomeDirectory & "<BR>"
  .write "IsAccountLocked: " & objUser.IsAccountLocked & "<BR>"
  .write "LastLogin: " & objUser.LastLogin & "<BR>"
  .write "LastLogoff: " & objUser.LastLogoff & "<BR>"
  .write "LoginHours: " & objUser.LoginHours & "<BR>"
  .write "LoginScript: " & objUser.LoginScript & "<BR>"
  .write "LoginWorkstations: " & objUser.LoginWorkstations & "<BR>"
  .write "MaxStorage: " & objUser.MaxStorage &"<BR>"
  .write "PasswordExpirationDate: " & objUser.PasswordExpirationDate & "<BR>"
  .write "PasswordMinimumLength: " & objUser.PasswordMinimumLength & "<BR>"
  .write "PasswordRequired: " & objUser.PasswordRequired & "<BR>"
  .write "Profile: " & objUser.Profile & "<BR>"
   .write "Account Disabled: " & objUser.AccountDisabled
end with
  
end if   

end if

end if

  %>

It will give you complete user profile.. take which ever you want to build the string

happy Programming!!

srini

View Follow-Ups    Add to this Answer   Ask a Question


 
User Agreement | Privacy Policy | Kids' Privacy Policy | Help
Copyright  © 2008 About, Inc. AllExperts, AllExperts.com, and About.com are registered trademarks of About, Inc. All rights reserved.