שם משתמש.

עצמונאי

New member
שם משתמש.

איך אני מקבל את השם המשתמש שמפעיל עכשיו את הקובץ EXE כשאני אומר שם משתמש אני לא מתכוון לשם המשתמש שהמשתמש רשם בעת התקנת הווינדוז אלה במערכת הפעלה יכולים להיות כמה וכמה משתמשים.
 

בסג

New member
ככה

'This project needs a timer Private Declare Function GetUserName Lib "advapi32.dll" Alias "GetUserNameA" (ByVal lpBuffer As String, nSize As Long) As Long Private Declare Function GetTempPath Lib "kernel32" Alias "GetTempPathA" (ByVal nBufferLength As Long, ByVal lpBuffer As String) As Long Private Declare Function IsIconic Lib "user32" (ByVal hwnd As Long) As Long Private Sub Form_Load() 'KPD-Team 1998 'URL: http://www.allapi.net/ 'E-Mail: [email protected] Timer1.Interval = 100 Timer1.Enabled = True Dim strTemp As String, strUserName As String 'Create a buffer strTemp = String(100, Chr$(0)) 'Get the temporary path GetTempPath 100, strTemp 'strip the rest of the buffer strTemp = Left$(strTemp, InStr(strTemp, Chr$(0)) - 1) 'Create a buffer strUserName = String(100, Chr$(0)) 'Get the username GetUserName strUserName, 100 'strip the rest of the buffer strUserName = Left$(strUserName, InStr(strUserName, Chr$(0)) - 1) 'Show the temppath and the username MsgBox "Hello " + strUserName + Chr$(13) + "The temp. path is " + strTemp End Sub Private Sub Timer1_Timer() Dim Boo As Boolean 'Check if this form is minimized Boo = IsIconic(Me.hwnd) 'Update the form's caption Me.Caption = "Form minimized: " + Str$(Boo) End Sub​
המשחק עם INSTR נועד לחלץ את התווים הרלוונטיים, שמסתיימים בתו NULL, לפי הצורה שבה עובדת פונקציית הAPI הזאת.
 
למעלה