|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 |
//----------------------------------------------------------
// Funzioni da inserire in: "Local External Functions"
//----------------------------------------------------------
// === Legge il path del sistema operativo Windows ===
// Il valore di ritorno è la lunghezza della stringa in 'WindowsDirectory'
// il Path della cartella dove sta il sist op. windows NON termina con backslash \
Function Long GetWindowsDirectory (ref String WindowsDirectory, Long nSize) &
Library "kernel32" Alias For "GetWindowsDirectoryA;Ansi"
// === Legge il path di sistema di Windows ===
// Il valore di ritorno è la lunghezza della stringa in 'SystemDirectory'
// il Path della cartella di sistema di windows NON termina con backslash \
Function Long GetSystemDirectory (ref String SystemDirectory, Long nSize) &
Library "kernel32" Alias For "GetSystemDirectoryA;Ansi"
// === Legge il Nome del Computer ===
// Se la chiamata ha successo il valore di ritorno è DIVERSO da Zero (per esempo 1)
// e la variabile 'BufferLenght' contiene la lunghezza effett. del 'ComputerName'
// Se la funzione fallisce il valore di ritorno è 0
FUNCTION long GetComputerName (ref string ComputerName, ref ulong BufferLength) &
Library "kernel32" Alias For "GetComputerNameA;Ansi"
// === Legge il nome utente che ha fatto accesso a Windows ===
// Se la chiamata ha successo il valore di ritorno è DIVERSO da Zero (per esempo 1)
// e la variabile 'BufferLenght' contiene la lunghezza effett. dello 'UserName'
// Se la funzione fallisce il valore di ritorno è 0
FUNCTION long GetUserName (ref string UserName, ref ulong BufferLength) &
Library "advapi32.dll" Alias For "GetUserNameA;Ansi"
//----------------------------------------------------------
//----------------------------------------------------------
// Lo script che richiama le suddette funzioni può essere a sua volta dentro
// una 'global user function' facendo restituire a questa il valore desiderato.
// Qui preferisco supporre alcuni campi di testo in una Window riempiti dai valori
// restituiti dalle funzioni.
// Il valore che viene emesso tra ( ) è la lunghezza del nome emesso.
//----------------------------------------------------------
long ll_return
string ls_ComputerName, ls_UserName
ulong BufferLength = 255 // potrebbe necessitare più lungo... a seconda dei casi
ls_ComputerName = Space(BufferLength)
ls_UserName = Space(BufferLength)
ll_return = GetComputerName (ls_ComputerName, BufferLength)
if ll_return = 0 then
st_computername.text = "Errore nella funzione GetComputerName"
else
st_computername.text = ls_ComputerName + " (" + string( BufferLength ) + ")"
end if
ll_return = GetUserName (ls_UserName, BufferLength)
if ll_return = 0 then
st_username.text = "Errore nella funzione GetUserName"
else
st_username.text = ls_UserName + " (" + string( BufferLength ) + ")"
end if
String ls_WinPath, ls_SystemPath
ls_WinPath = Space (255)
ll_return = GetWindowsDirectory (ls_WinPath, 255)
st_WinPath.text = ls_WinPath + " (" + string(ll_return) + ")"
ls_SystemPath = Space (255)
ll_return = GetSystemDirectory (ls_SystemPath, 255)
st_SystemPath.text = ls_SystemPath + " (" + string(ll_return) + ")"
//----------------------------------------------------------
|