Newsgroup: it.comp.appl.access
Titolo: Come trovare la directory di sistema ?

Devo copiare un file nella cartella di windows, ma come faccio a risalire al
suo percorso corretto ?
es. in win2000 di solito è C:\winnt mentre in win98 potrebbe essere
C:\windows
grazie
Andrea

Andrea ha scritto nel messaggio ...

Credo che la soluzione sia questa:
Declare Function GetWindowsDirectory Lib "kernel32" Alias
"GetWindowsDirectoryA" (ByVal lpBuffer As String, ByVal nSize As Long) As
Long
Cordiali saluti.


Scusa ma non mi è chiaro , che parametri gli devo passare ? (  lpBuffer ? -
nSize  ? )


 ha scritto nel messaggio
news:YTT69.67063$n04.1...@twister2.libero.it...

Eccoti un modulo che spesso utilizzo
ciao omnitow
Option Explicit
'ritorna path cartella temp
Public Declare Function GetTempPath Lib "kernel32.dll" Alias "GetTempPathA"
_
(ByVal nBufferLength As Long, ByVal lpBuffer As String) As Long
'Ritorna path cartelle speciali
Public Declare Function SHGetFolderPath Lib "shfolder.dll" Alias _
"SHGetFolderPathA" (ByVal hwndOwner As Long, ByVal nFolder As Long, _
ByVal hToken As Long, ByVal dwReserved As Long, _
ByVal lpszPath As String) As Long
'        La Funzione SHGetFolderPath ritorna il path delle cartelle speciali
del sistema.
'        Questa funzione è valida solo per le cartelle speciali che
fisicamente sono delle directory
'        del disco.
'        hwndOwner 'handle della finestra da cui si richiama la funzione.
'        nFolder 'Il CSIDL della cartella speciale di cui si vuole conoscere
il percorso.
'        hToken 'Un simbolo che identifica l'utente. Normalmente 0, ma può
essere diverso a seconda degli scopi.
'        dwReserved 'Uno dei seguenti Flags, specifica come deve essere
ritornato il path:
'        La funzione ritorna uno dei seguenti flags
Public Const S_OK = &H0        'Funzione completata con successo
Public Const S_FALSE = &H1 'il CSIDL della cartella speciale è valido, ma la
cartella è una cartella virtuale.
Public Const E_INVALIDARG = &H80070057 'Il CSIDL non è valido.
Public Enum SHdwReservedType
    SHGFP_TYPE_CURRENT = &H0 'Ritorna il path corrente della carttella
    SHGFP_TYPE_DEFAULT = &H1 'Ritorna il path di default della cartella
End Enum
'        lpszPath
'        Riceve il caratterie di terminazione della stringa che contiene il
path della cartella speciale.
'        La stringa può contenere al massimo 260 caratteri
Public Enum SHcsidlsType
    CSIDL_ADMINTOOLS = &H30 'Windows 2000: The Administration Tools folder.
    CSIDL_ALTSTARTUP = &H1D 'The non-localized Startup folder.
    CSIDL_APPDATA = &H1A  'The Application Data folder (used to store common
program data)
    CSIDL_BITBUCKET = &HA 'The Recycle Bin on the desktop.
    CSIDL_COMMON_ADMINTOOLS = &H2F 'Windows 2000: The Administration Tools
folder common to all users.
    CSIDL_COMMON_APPDATA = &H23 'Windows 2000: The Application Data folder
(used to store common program data) common to all users.
    CSIDL_COMMON_ALTSTARTUP = &H1D 'Windos NT, 2000: The non-localized
Startup folder common to all users.
    CSIDL_COMMON_DESKTOPDIRECTORY = &H19 'Windows NT, 2000: The Desktop
directory (used to store file objects on the Windows desktop) common to all
users.
    CSIDL_COMMON_DOCUMENTS = &H2E 'Windows NT, 2000: The Documents folder
common to all users.
    CSIDL_COMMON_FAVORITES = &H1F 'Windows NT, 2000: The Favorites folder
common to all users.
    CSIDL_COMMON_PROGRAMS = &H17 'Windows NT, 2000: The Programs folder
under the Start Menu common to all users.
    CSIDL_COMMON_STARTMENU = &H16 'Windows NT, 2000: The Start Menu folder
common to all users.
    CSIDL_COMMON_STARTUP = &H18 'Windows NT, 2000: The Startup folder under
Start Menu\Programs common to all users.
    CSIDL_COMMON_TEMPLATES = &H2D 'Windows NT, 2000: The Templates folder
common to all users
    CSIDL_CONTROLS = &H3 'The Control Panel.
    CSIDL_COOKIES = &H21 'The folder used for Internet Explorer's cookie
list.
    CSIDL_DESKTOP = &H0 'The Windows desktop.
    CSIDL_DESKTOPDIRECTORY = &H10 'The Desktop directory (used to hold file
objects on the Windows desktop).
    CSIDL_DRIVES = &H11 'The My Computer folder.
    CSIDL_FAVORITES = &H6 'The Favorites folder (used primarily to store
Internet Explorer's bookmarks).
    CSIDL_FONTS = &H14 'The Fonts directory (used to hold the fonts
installed in Windows).
    CSIDL_HISTORY = &H22 'The folder used for Internet Explorer's history
list.
    CSIDL_INTERNET = &H1 'The Internet (refering to the Internet Explorer
icon on the desktop).
    CSIDL_INTERNET_CACHE = &H20 'The folder used for Internet Explorer's
cache.
    CSIDL_LOCAL_APPDATA = &H1C 'With Internet Explorer 5.0 or later: Local
Application Data folder.
    CSIDL_MYPICTURES = &H27 'With Internet Explorer 5.0 or later: The My
Pictures folder.
    CSIDL_NETHOOD = &H13 'The Nethood directory (used to hold objects
appearing in Network Neighborhood).
    CSIDL_NETWORK = &H12 'The Network Neighborhood folder.
    CSIDL_PERSONAL = &H5 'The My Documents folder.
    CSIDL_PRINTERS = &H4 'The Printers folder (under My Computer).
    CSIDL_PRINTHOOD = &H1B 'The PrintHood directory (used to store printer
links).
    CSIDL_PROFILE = &H28 'With Internet Explorer 5.0 or later: The user
profile folder.
    CSIDL_PROGRAM_FILES = &H26 'With Internet Explorer 5.0 or later: The
Program Files folder.
    CSIDL_PROGRAM_FILES_COMMON = &H2B 'Windows NT, 2000: The Common folder
under Program Files.
    CSIDL_PROGRAM_FILES_COMMONX86 = &H2C 'Windows 2000: The x86 Common
folder under Program Files for RISC systems.
    CSIDL_PROGRAM_FILESX86 = &H2A 'Windows 2000: The x86 Program Files
directory on RISC systems.
    CSIDL_PROGRAMS = &H2 'The Programs folder in the Start Menu.
    CSIDL_RECENT = &H8 'The Recent folder (used for the Documents list in
the Start Menu).
    CSIDL_SENDTO = &H9 'The Send To folder (used to store Send To menu
items).
    CSIDL_STARTMENU = &HB 'The Start Menu.
    CSIDL_STARTUP = &H7 'The Startup folder under Start Menu\Programs.
    CSIDL_SYSTEM = &H25 'With Internet Explorer 5.0 or later: The Windows
System directory.
    CSIDL_SYSTEMX86 = &H29 'Windows 2000: The x86 system directory on RISC
systems.
    CSIDL_TEMPLATES = &H15 'The Templates folder (used to store document
templates).
    CSIDL_WINDOWS = &H24 'With Internet Explorer 5.0 or later: The Windows
directory.
End Enum
Public Function WinDir(ByVal IDcartella As SHcsidlsType, Optional ByVal
hwndFormAttuale As Long, _
                        Optional ByVal PathComeLoVuoi As SHdwReservedType,
Optional ByVal SimboloUtente As Long _
                        ) As String
Dim Cartella As String
If IsMissing(SimboloUtente) Then SimboloUtente = 0&
If IsMissing(PathComeLoVuoi) Then PathComeLoVuoi = SHGFP_TYPE_CURRENT
Cartella = Space(255)
If Not SHGetFolderPath(hwndFormAttuale, IDcartella, SimboloUtente,
PathComeLoVuoi, Cartella) = S_OK Then
    WinDir = ""
Else
    Cartella = Trim$(Cartella)
    WinDir = Left(Cartella, Len(Cartella) - 1)
End If
End Function
Public Function TempDir() As String
Dim slength As Long 'lunghezza della stringa che riceverà il path
TempDir = Space(255) ' stringa che riceverà il path
slength = GetTempPath(255, TempDir) ' determina la lunghezza del path
scrivendolo sulla stringa
TempDir = Left(TempDir, slength) ' elimina gli spazi
End Function

Grazie :)

 ha scritto nel messaggio
news:UZR69.66826$n04.1...@twister2.libero.it...

Prova con questo script:
'---------
Dim objWshShell As Object
Set objWshShell = CreateObject("Wscript.Shell")
MsgBox objWshShell.ExpandEnvironmentStrings("%WINDIR%")
Set objWshShell = Nothing
'---------
Ciao.
--
Sergio MAZZA