![]() |
Konfigurationsdatei ini
Hallo
Und zwar hab ich folgendes Problem: Ich hab ein Programm geschrieben, das Menüpunkt mit Pfadeinstellung besitzt. Dort kann ich die Quell- und Zielpfade eingeben und per Button wird dies in ein .ini file Geschrieben jetzt möcht ich das ini-File nach den Pfadeinstellungen per OK-Button auf C:\ abspeichern jedoch bekomm ich bei Ausführung einen Zugriffsfehler was mir klar ist.
Delphi-Quellcode:
ini:=TIniFile.Create('C:\rxmlkonfig.ini'); // Hier der Zugriffsfehler
try ini.WriteString('Pfadeinstellungen','Quelle',Quelle+'\'); ini.WriteString('Pfadeinstellungen','Ziel',Ziel+'\'); finally ini.free end; Gibt es eine möglichkeit über Delphi Zugriffsrechte für das Erstellen einer .ini Datei auf C:\ per Befehl etc zu erlangen? |
AW: Konfigurationsdatei ini
Hallo,
dann hast du - wie die wenigsten - keine Schreibrechte auf C:\ und das ist auch gut so. Die Dateien gehören nicht nach C:\ sondern ins Anwendungsdaten-Verzeichnis. Wo sich das unter Vista/Win7 genau befindet, weiß ich nicht, aber unter WinXP war's "Dokumente und Einstellungen\<user>\Anwendungsdaten\Anwendungsnam e\". In der DP gibt's genug Funktionen, um den Pfad zu ermitteln, evtl. hilft schon ![]() Grüße, Matze |
AW: Konfigurationsdatei ini
Das Programmdaten (Root-)Verzeichnis für alle Benutzer ist CSIDL_COMMON_APPDATA ($0023), für den Benutzer allein zugehörig CSIDL_APPDATA ($001A).
Unit, um die Pfade der verfügbaren Windows-Special-Folder zu ermitteln, inklusive deren Konstanten und Beschreibung:
Delphi-Quellcode:
unit specialfolders;
{ Function for retrieving the paths of the Microsoft Windows special folders. Constants of the available special folders below. Systems: Win 2000, Win XP, Vista, Windows 7 } interface uses Windows, SysUtils, ShlObj ; function getWinSpecialFolder(CSIDLFolder : integer) : string; const CSIDL_COMMON_APPDATA = $0023; CSIDL_FLAG_CREATE = $8000; CSIDL_ADMINTOOLS = $0030; CSIDL_ALTSTARTUP = $001D; CSIDL_APPDATA = $001A; CSIDL_BITBUCKET = $000A; CSIDL_CDBURN_AREA = $003B; CSIDL_COMMON_ADMINTOOLS = $002F; CSIDL_COMMON_ALTSTARTUP = $001E; CSIDL_COMMON_DESKTOPDIRECTORY = $0019; CSIDL_COMMON_DOCUMENTS = $002E CSIDL_COMMON_FAVORITES = $001F; CSIDL_COMMON_MUSIC = $0035; CSIDL_COMMON_PICTURES = $0036; CSIDL_COMMON_PROGRAMS = $0017; CSIDL_COMMON_STARTMENU = $0016; CSIDL_COMMON_STARTUP = $0018; CSIDL_COMMON_TEMPLATES = $002D; CSIDL_COMMON_VIDEO = $0037; CSIDL_CONTROLS = $0003; CSIDL_COOKIES = $0021; CSIDL_DESKTOP = $0000; CSIDL_DESKTOPDIRECTORY = $0010 CSIDL_DRIVES = $0011; CSIDL_FAVORITES = $0006; CSIDL_FONTS = $0014; CSIDL_HISTORY = $0022; CSIDL_INTERNET = $0001; CSIDL_INTERNET_CACHE = $0020; CSIDL_LOCAL_APPDATA = $001C CSIDL_MYDOCUMENTS = $000C CSIDL_MYMUSIC = $000D; CSIDL_MYPICTURES = $0027; CSIDL_MYVIDEO = $000E; CSIDL_NETHOOD = $0013; CSIDL_NETWORK = $0012; CSIDL_PERSONAL = $0005; CSIDL_PRINTERS = $0004; CSIDL_PRINTHOOD = $001B; CSIDL_PROFILE = $0028; CSIDL_PROFILES = $003E; CSIDL_PROGRAM_FILES = $0026; CSIDL_PROGRAM_FILES_COMMON = $002B; CSIDL_PROGRAMS = $0002; CSIDL_RECENT = $0008; CSIDL_SENDTO = $0009; CSIDL_STARTMENU = $000B; CSIDL_STARTUP = $0007 CSIDL_SYSTEM = $0025; CSIDL_TEMPLATES = $0015; CSIDL_WINDOWS = $0024; { CSIDL_FLAG_CREATE (0x8000) Version 5.0. Combine this CSIDL with any of the following CSIDLs to force the creation of the associated folder. CSIDL_ADMINTOOLS (0x0030) Version 5.0. The file system directory that is used to store administrative tools for an individual user. The Microsoft Management Console (MMC) will save customized consoles to this directory, and it will roam with the user. CSIDL_ALTSTARTUP (0x001d) The file system directory that corresponds to the user's nonlocalized Startup program group. CSIDL_APPDATA (0x001a) Version 4.71. The file system directory that serves as a common repository for application-specific data. A typical path is C:\Documents and Settings\username\Application Data. This CSIDL is supported by the redistributable Shfolder.dll for systems that do not have the Microsoft Internet Explorer 4.0 integrated Shell installed. CSIDL_BITBUCKET (0x000a) The virtual folder containing the objects in the user's Recycle Bin. CSIDL_CDBURN_AREA (0x003b) Version 6.0. The file system directory acting as a staging area for files waiting to be written to CD. A typical path is C:\Documents and Settings\username\Local Settings\Application Data\Microsoft\CD Burning. CSIDL_COMMON_ADMINTOOLS (0x002f) Version 5.0. The file system directory containing administrative tools for all users of the computer. CSIDL_COMMON_ALTSTARTUP (0x001e) The file system directory that corresponds to the nonlocalized Startup program group for all users. Valid only for Microsoft Windows NT systems. CSIDL_COMMON_APPDATA (0x0023) Version 5.0. The file system directory containing application data for all users. A typical path is C:\Documents and Settings\All Users\Application Data. CSIDL_COMMON_DESKTOPDIRECTORY (0x0019) The file system directory that contains files and folders that appear on the desktop for all users. A typical path is C:\Documents and Settings\All Users\Desktop. Valid only for Windows NT systems. CSIDL_COMMON_DOCUMENTS (0x002e) The file system directory that contains documents that are common to all users. A typical paths is C:\Documents and Settings\All Users\Documents. Valid for Windows NT systems and Microsoft Windows 95 and Windows 98 systems with Shfolder.dll installed. CSIDL_COMMON_FAVORITES (0x001f) The file system directory that serves as a common repository for favorite items common to all users. Valid only for Windows NT systems. CSIDL_COMMON_MUSIC (0x0035) Version 6.0. The file system directory that serves as a repository for music files common to all users. A typical path is C:\Documents and Settings\All Users\Documents\My Music. CSIDL_COMMON_PICTURES (0x0036) Version 6.0. The file system directory that serves as a repository for image files common to all users. A typical path is C:\Documents and Settings\All Users\Documents\My Pictures. CSIDL_COMMON_PROGRAMS (0x0017) The file system directory that contains the directories for the common program groups that appear on the Start menu for all users. A typical path is C:\Documents and Settings\All Users\Start Menu\Programs. Valid only for Windows NT systems. CSIDL_COMMON_STARTMENU (0x0016) The file system directory that contains the programs and folders that appear on the Start menu for all users. A typical path is C:\Documents and Settings\All Users\Start Menu. Valid only for Windows NT systems. CSIDL_COMMON_STARTUP (0x0018) The file system directory that contains the programs that appear in the Startup folder for all users. A typical path is C:\Documents and Settings\All Users\Start Menu\Programs\Startup. Valid only for Windows NT systems. CSIDL_COMMON_TEMPLATES (0x002d) The file system directory that contains the templates that are available to all users. A typical path is C:\Documents and Settings\All Users\Templates. Valid only for Windows NT systems. CSIDL_COMMON_VIDEO (0x0037) Version 6.0. The file system directory that serves as a repository for video files common to all users. A typical path is C:\Documents and Settings\All Users\Documents\My Videos. CSIDL_CONTROLS (0x0003) The virtual folder containing icons for the Control Panel applications. CSIDL_COOKIES (0x0021) The file system directory that serves as a common repository for Internet cookies. A typical path is C:\Documents and Settings\username\Cookies. CSIDL_DESKTOP (0x0000) The virtual folder representing the Windows desktop, the root of the namespace. CSIDL_DESKTOPDIRECTORY (0x0010) The file system directory used to physically store file objects on the desktop (not to be confused with the desktop folder itself). A typical path is C:\Documents and Settings\username\Desktop. CSIDL_DRIVES (0x0011) The virtual folder representing My Computer, containing everything on the local computer: storage devices, printers, and Control Panel. The folder may also contain mapped network drives. CSIDL_FAVORITES (0x0006) The file system directory that serves as a common repository for the user's favorite items. A typical path is C:\Documents and Settings\username\Favorites. CSIDL_FONTS (0x0014) A virtual folder containing fonts. A typical path is C:\Windows\Fonts. CSIDL_HISTORY (0x0022) The file system directory that serves as a common repository for Internet history items. CSIDL_INTERNET (0x0001) A virtual folder representing the Internet. CSIDL_INTERNET_CACHE (0x0020) Version 4.72. The file system directory that serves as a common repository for temporary Internet files. A typical path is C:\Documents and Settings\username\Local Settings\Temporary Internet Files. CSIDL_LOCAL_APPDATA (0x001c) Version 5.0. The file system directory that serves as a data repository for local (nonroaming) applications. A typical path is C:\Documents and Settings\username\Local Settings\Application Data. CSIDL_MYDOCUMENTS (0x000c) Version 6.0. The virtual folder representing the My Documents desktop item. CSIDL_MYMUSIC (0x000d) The file system directory that serves as a common repository for music files. A typical path is C:\Documents and Settings\User\My Documents\My Music. CSIDL_MYPICTURES (0x0027) Version 5.0. The file system directory that serves as a common repository for image files. A typical path is C:\Documents and Settings\username\My Documents\My Pictures. CSIDL_MYVIDEO (0x000e) Version 6.0. The file system directory that serves as a common repository for video files. A typical path is C:\Documents and Settings\username\My Documents\My Videos. CSIDL_NETHOOD (0x0013) A file system directory containing the link objects that may exist in the My Network Places virtual folder. It is not the same as CSIDL_NETWORK, which represents the network namespace root. A typical path is C:\Documents and Settings\username\NetHood. CSIDL_NETWORK (0x0012) A virtual folder representing Network Neighborhood, the root of the network namespace hierarchy. CSIDL_PERSONAL (0x0005) Version 6.0. The virtual folder representing the My Documents desktop item. This is equivalent to CSIDL_MYDOCUMENTS. Previous to Version 6.0. The file system directory used to physically store a user's common repository of documents. A typical path is C:\Documents and Settings\username\My Documents. This should be distinguished from the virtual My Documents folder in the namespace. To access that virtual folder, use SHGetFolderLocation, which returns the ITEMIDLIST for the virtual location, or refer to the technique described in Managing the File System. CSIDL_PRINTERS (0x0004) The virtual folder containing installed printers. CSIDL_PRINTHOOD (0x001b) The file system directory that contains the link objects that can exist in the Printers virtual folder. A typical path is C:\Documents and Settings\username\PrintHood. CSIDL_PROFILE (0x0028) Version 5.0. The user's profile folder. A typical path is C:\Documents and Settings\username. Applications should not create files or folders at this level; they should put their data under the locations referred to by CSIDL_APPDATA or CSIDL_LOCAL_APPDATA. CSIDL_PROFILES (0x003e) Version 6.0. The file system directory containing user profile folders. A typical path is C:\Documents and Settings. CSIDL_PROGRAM_FILES (0x0026) Version 5.0. The Program Files folder. A typical path is C:\Program Files. CSIDL_PROGRAM_FILES_COMMON (0x002b) Version 5.0. A folder for components that are shared across applications. A typical path is C:\Program Files\Common. Valid only for Windows NT, Windows 2000, and Windows XP systems. Not valid for Windows Millennium Edition (Windows Me). CSIDL_PROGRAMS (0x0002) The file system directory that contains the user's program groups (which are themselves file system directories). A typical path is C:\Documents and Settings\username\Start Menu\Programs. CSIDL_RECENT (0x0008) The file system directory that contains shortcuts to the user's most recently used documents. A typical path is C:\Documents and Settings\username\My Recent Documents. To create a shortcut in this folder, use SHAddToRecentDocs. In addition to creating the shortcut, this function updates the Shell's list of recent documents and adds the shortcut to the My Recent Documents submenu of the Start menu. CSIDL_SENDTO (0x0009) The file system directory that contains Send To menu items. A typical path is C:\Documents and Settings\username\SendTo. CSIDL_STARTMENU (0x000b) The file system directory containing Start menu items. A typical path is C:\Documents and Settings\username\Start Menu. CSIDL_STARTUP (0x0007) The file system directory that corresponds to the user's Startup program group. The system starts these programs whenever any user logs onto Windows NT or starts Windows 95. A typical path is C:\Documents and Settings\username\Start Menu\Programs\Startup. CSIDL_SYSTEM (0x0025) Version 5.0. The Windows System folder. A typical path is C:\Windows\System32. CSIDL_TEMPLATES (0x0015) The file system directory that serves as a common repository for document templates. A typical path is C:\Documents and Settings\username\Templates. CSIDL_WINDOWS (0x0024) Version 5.0. The Windows directory or SYSROOT. This corresponds to the %windir% or %SYSTEMROOT% environment variables. A typical path is C:\Windows. } implementation function getWinSpecialFolder(CSIDLFolder : integer) : string; begin SetLength(Result, MAX_PATH); SHGetSpecialFolderPath(0, PChar(Result), CSIDLFolder, false); SetLength(Result, StrLen(PChar(Result))); if (Result <> '') then Result := IncludeTrailingBackslash(Result); end; end. |
AW: Konfigurationsdatei ini
Zitat:
MfG Fabian |
AW: Konfigurationsdatei ini
Zitat:
Ich ging davon aus, dass Microsoft das konsequent umgesetzt hat. Wieder was gelernt. D.h. natürlich nicht, dass man die Daten auf C:\ speichern soll. ;) |
AW: Konfigurationsdatei ini
Zitat:
Du kannst nämlich als eingeloggter Admin auch mit aktivierter UAC auf dem C:-Root rumwerkeln wie du lustig bist und eine Datei erstellen, und das ganze ohne bösen Dialog, aber wenn dein Delphi-Programm nicht als Admin startet (was der standard ist), hat es keine Schreibrechte aufs C:-Root. @t0mmy: Probier mal, ob das Programm über Rechtsklick => Als Administrator ausführen... immer noch den Fehler erzeugt :) Während der Laufzeit hast du keine Möglichkeit, die Rechte deines Programms per Code zu erweitern, das wäre auch gegen den Sinn des Rechte-Systems. Du hast nun aber zwei drei Möglichkeiten, um dein Problem zu lösen: 1) Die grauslige Variante ######################### Du forderst über ein Manifest generell Admin-Rechte beim Programm-Start für dein Programm an. Wie das geht, verrät dir die Suchfunktion. Dann kannst du auch deine INI-Datei auf dem C-Root ablegen. Das halte ich aber für wirklich schlimm und ist nicht zu empfehlen. Stell dir vor, alle Programme würden ihre Konfig-Einstellungen auf dem C:-Root ablegen? Wir leben doch nicht in der Steinzeit! :) 2) Die richtige Variante ######################## Du legst deine INI-Datei da ab, wo sie hingehört: Entweder in (einen Unterordner von) CSIDL_COMMON_APPDATA, oder Benutzer-bezogen in CSIDL_APPDATA. Hierbei sei aber noch erwähnt, dass ein Programm ohne Admin-Rechte erstmal auch da keinen Schreibzugriff hat. Den Schreibzugriff auf einen Unterordner dieser beiden genannten Spezial-Verzeichnisse muss das Installationsprogramm des Programms freigeben, das ja normalerweise mit Admin-Rechten läuft und es somit auch kann. Das erfordert zwar etwas Mehraufwand, aber so ist es von Microsoft vorgesehen. 3) Die "Das ist mir alles zu kompliziert"-Methode (sozusagen Variante 1.1) ################################################## ########################## Du baust kein Manifest ein und nimmst auch keinen Specialfolder, sondern verteufelst Microsoft wegen dem dämlichen Rechtesystem und sagst deinen Benutzern, sie sollen das Programm jedesmal über "Rechtsklick => Als Administrator ausführen..." starten, damit es keine AV gibt. Nunja, was soll ich sagen....wer sowas macht, sollte vielleicht lieber Äpfel auf dem Stadtmarkt verkaufen :D Ich lege dir die Variante zwei ans Herz, jeder User wirds dir danken! :-D |
AW: Konfigurationsdatei ini
Oder Version Evil deluxe: Anwender auffordern Berechtigungen für die gesammte Platte zuzulassen
|
AW: Konfigurationsdatei ini
Hallo, sry das so lange gedauert hat, aber ich hab kurzzeitig kein inet gehabt.
Jetzt gehts aber wieder :) Ja das mit ausführen als Admin geht, nur möchte ich das nicht! Ich will einfach ein SChreibrecht auf C: haben das wär alles :( achja das mit den SpecialFolders wird mir weniger helfen, denn der Ordner in dem ich die Datei schreiben will is auf C:\ |
AW: Konfigurationsdatei ini
Zitat:
Zitat:
Ausser, du nimmst mkinzler's Variante "evil Deluxe" (bitte nicht!) |
AW: Konfigurationsdatei ini
:(
Gibt es denn eine möglichkeit Programmtechnisch das PRogramm als Admin laufen zu lassen? Also nicht links-Klick --> Ausführen als Admin |
Alle Zeitangaben in WEZ +1. Es ist jetzt 19:31 Uhr. |
Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
LinkBacks Enabled by vBSEO © 2011, Crawlability, Inc.
Delphi-PRAXiS (c) 2002 - 2023 by Daniel R. Wolf, 2024-2025 by Thomas Breitkreuz