<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0"><channel><title><![CDATA[Dateigröße von Systemdateien?]]></title><description><![CDATA[<p>Hi Leute!</p>
<p>Ich hab ein komisches Problem. Wenn ich eine Dateigrösse ermitteln will, mache ich</p>
<pre><code class="language-cpp">FILE* workingfile = fopen(&quot;C:\\TEST.TXT&quot;, &quot;rb&quot;);

if(!workingfile)
{
   MessageBox(NULL, &quot;Vergiss es...&quot;, &quot;&quot;, 0);
   exit(0);
}
fseek(workingfile, 0L, SEEK_END);

char text [200];
sprintf(text, &quot;%d&quot;, (long) ftell(workingfile));
MessageBox(NULL, text, &quot;&quot;, 0);
fclose(workingfile);
</code></pre>
<p>Funktioniert wunderbar. Aber wenn ich versuche, die Grösse einer Systemdatei, wie z.B. (unter NT) C:\pagefile.sys, zu ermitteln, dann schlägt fopen() fehl. Warum, das? Gibt es eine Möglichkeit, auch die Dateigrösse von Systemdateien herauszufinden???</p>
<p>Ich habs mal versucht mit GetFileSize() aus der WinAPI, aber bekomme das irgendwie net zum laufen, bzw. kapier ich nicht wie die geöffnet werden muss (da steht was von GENERIC_READ, OpenFile kennt aber lt. MSDN nur OF_READ...):</p>
<pre><code class="language-cpp">OFSTRUCT fInfo;
HFILE testfile = OpenFile(&quot;C:\\PAGEFILE.SYS&quot;, &amp;fInfo, GENERIC_READ);
DWORD size;
size = GetFileSize(testfile, NULL); // &lt;- hier nicht kompilierbar.
CloseHandle(testfile);
</code></pre>
<p>Grüsse,<br />
code_pilot <img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f644.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--face_with_rolling_eyes"
      title=":rolling_eyes:"
      alt="🙄"
    /></p>
]]></description><link>https://www.c-plusplus.net/forum/topic/65900/dateigröße-von-systemdateien</link><generator>RSS for Node</generator><lastBuildDate>Tue, 07 Apr 2026 22:41:19 GMT</lastBuildDate><atom:link href="https://www.c-plusplus.net/forum/topic/65900.rss" rel="self" type="application/rss+xml"/><pubDate>Mon, 23 Feb 2004 14:18:24 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to Dateigröße von Systemdateien? on Mon, 23 Feb 2004 14:19:05 GMT]]></title><description><![CDATA[<p>Hi Leute!</p>
<p>Ich hab ein komisches Problem. Wenn ich eine Dateigrösse ermitteln will, mache ich</p>
<pre><code class="language-cpp">FILE* workingfile = fopen(&quot;C:\\TEST.TXT&quot;, &quot;rb&quot;);

if(!workingfile)
{
   MessageBox(NULL, &quot;Vergiss es...&quot;, &quot;&quot;, 0);
   exit(0);
}
fseek(workingfile, 0L, SEEK_END);

char text [200];
sprintf(text, &quot;%d&quot;, (long) ftell(workingfile));
MessageBox(NULL, text, &quot;&quot;, 0);
fclose(workingfile);
</code></pre>
<p>Funktioniert wunderbar. Aber wenn ich versuche, die Grösse einer Systemdatei, wie z.B. (unter NT) C:\pagefile.sys, zu ermitteln, dann schlägt fopen() fehl. Warum, das? Gibt es eine Möglichkeit, auch die Dateigrösse von Systemdateien herauszufinden???</p>
<p>Ich habs mal versucht mit GetFileSize() aus der WinAPI, aber bekomme das irgendwie net zum laufen, bzw. kapier ich nicht wie die geöffnet werden muss (da steht was von GENERIC_READ, OpenFile kennt aber lt. MSDN nur OF_READ...):</p>
<pre><code class="language-cpp">OFSTRUCT fInfo;
HFILE testfile = OpenFile(&quot;C:\\PAGEFILE.SYS&quot;, &amp;fInfo, GENERIC_READ);
DWORD size;
size = GetFileSize(testfile, NULL); // &lt;- hier nicht kompilierbar.
CloseHandle(testfile);
</code></pre>
<p>Grüsse,<br />
code_pilot <img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f644.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--face_with_rolling_eyes"
      title=":rolling_eyes:"
      alt="🙄"
    /></p>
]]></description><link>https://www.c-plusplus.net/forum/post/465942</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/465942</guid><dc:creator><![CDATA[code_pilot]]></dc:creator><pubDate>Mon, 23 Feb 2004 14:19:05 GMT</pubDate></item><item><title><![CDATA[Reply to Dateigröße von Systemdateien? on Mon, 23 Feb 2004 14:44:47 GMT]]></title><description><![CDATA[<p>Du mußt die Datei mit <strong>CreateFile</strong> mit den Flags FILE_SHARE_READ und OPEN_EXISTING öffnen...</p>
<p>Das HANDLE, was Du davon bekommst, kannst Du bei GetFileSize angeben...<br />
Hinterher das schließen mit CloseHandle nicht vergessen!</p>
<p>Ob das bei der Auslagerungsdatei klappt (das öffnen), weiß ich nicht, da das Betriebssystem die Datei sicherlich geöffnet hat (weshalb fopen() sicherlich auch scheitert)...</p>
]]></description><link>https://www.c-plusplus.net/forum/post/465951</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/465951</guid><dc:creator><![CDATA[Hepi]]></dc:creator><pubDate>Mon, 23 Feb 2004 14:44:47 GMT</pubDate></item><item><title><![CDATA[Reply to Dateigröße von Systemdateien? on Mon, 23 Feb 2004 14:34:53 GMT]]></title><description><![CDATA[<p>hmmm ...</p>
<p>danke erstmal. So geht es zwar mit anderen Dateien, aber bei PAGEFILE.SYS gibt die Funktion -1 zurück (kann wohl net geöffnet werden).</p>
<pre><code class="language-cpp">OFSTRUCT fInfo;
HFILE testfile = OpenFile(&quot;C:\\PAGEFILE.SYS&quot;, &amp;fInfo, FILE_SHARE_READ | OPEN_EXISTING );
DWORD size;
size = GetFileSize((HANDLE)testfile, NULL);
CloseHandle((HANDLE)testfile);
</code></pre>
]]></description><link>https://www.c-plusplus.net/forum/post/465963</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/465963</guid><dc:creator><![CDATA[code_pilot]]></dc:creator><pubDate>Mon, 23 Feb 2004 14:34:53 GMT</pubDate></item><item><title><![CDATA[Reply to Dateigröße von Systemdateien? on Mon, 23 Feb 2004 14:46:38 GMT]]></title><description><![CDATA[<p>code_pilot schrieb:</p>
<blockquote>
<pre><code class="language-cpp">HFILE testfile = OpenFile(&quot;C:\\PAGEFILE.SYS&quot;, &amp;fInfo, FILE_SHARE_READ | OPEN_EXISTING );
</code></pre>
</blockquote>
<p>Du sollst nicht OpenFile benutzen und den Rückgabewert casten, sondern <strong>CreateFile</strong> benutzen...</p>
<p>Wer weiß was FILE_SHARE_READ | OPEN_EXISTING bei OpenFile anrichtet...</p>
]]></description><link>https://www.c-plusplus.net/forum/post/465977</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/465977</guid><dc:creator><![CDATA[Hepi]]></dc:creator><pubDate>Mon, 23 Feb 2004 14:46:38 GMT</pubDate></item><item><title><![CDATA[Reply to Dateigröße von Systemdateien? on Mon, 23 Feb 2004 14:54:15 GMT]]></title><description><![CDATA[<p>Schonmal stat versucht?<br />
(ist natürlich nicht WinAPI)</p>
<p><a href="http://wwwcgi.rdg.ac.uk:8081/cgi-bin/cgiwrap/wsi14/poplog/man/2/stat" rel="nofollow">http://wwwcgi.rdg.ac.uk:8081/cgi-bin/cgiwrap/wsi14/poplog/man/2/stat</a></p>
]]></description><link>https://www.c-plusplus.net/forum/post/465986</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/465986</guid><dc:creator><![CDATA[Geo]]></dc:creator><pubDate>Mon, 23 Feb 2004 14:54:15 GMT</pubDate></item><item><title><![CDATA[Reply to Dateigröße von Systemdateien? on Mon, 23 Feb 2004 15:07:02 GMT]]></title><description><![CDATA[<p>Hepi schrieb:</p>
<blockquote>
<p>Du sollst nicht OpenFile benutzen und den Rückgabewert casten, sondern <strong>CreateFile</strong> benutzen...</p>
<p>Wer weiß was FILE_SHARE_READ | OPEN_EXISTING bei OpenFile anrichtet...</p>
</blockquote>
<p>Upps da hab ich mich verlesen. Wie mach ich denn das? Bei dem hier kommt auch nur -1 bei rum. Was sind diese verschiedenen Parameter?</p>
<pre><code class="language-cpp">HANDLE testfile = CreateFile (&quot;C:\\PAGEFILE.SYS&quot;, GENERIC_READ,
     FILE_SHARE_READ, 0, OPEN_EXISTING,
           FILE_FLAG_SEQUENTIAL_SCAN, 0);
DWORD size = GetFileSize(testfile, NULL);
CloseHandle(testfile);
</code></pre>
<p>Gruss,<br />
code_pilot</p>
]]></description><link>https://www.c-plusplus.net/forum/post/465988</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/465988</guid><dc:creator><![CDATA[code_pilot]]></dc:creator><pubDate>Mon, 23 Feb 2004 15:07:02 GMT</pubDate></item><item><title><![CDATA[Reply to Dateigröße von Systemdateien? on Mon, 23 Feb 2004 15:21:16 GMT]]></title><description><![CDATA[<p><a href="http://msdn.microsoft.com/library/en-us/fileio/base/createfile.asp" rel="nofollow">http://msdn.microsoft.com/library/en-us/fileio/base/createfile.asp</a></p>
]]></description><link>https://www.c-plusplus.net/forum/post/466021</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/466021</guid><dc:creator><![CDATA[flenders]]></dc:creator><pubDate>Mon, 23 Feb 2004 15:21:16 GMT</pubDate></item><item><title><![CDATA[Reply to Dateigröße von Systemdateien? on Mon, 23 Feb 2004 15:28:20 GMT]]></title><description><![CDATA[<p>ja ach nee ... da hab ich auch schon geguckt aber keine brauchbare Antwort gefunden.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/466033</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/466033</guid><dc:creator><![CDATA[code_pilot]]></dc:creator><pubDate>Mon, 23 Feb 2004 15:28:20 GMT</pubDate></item><item><title><![CDATA[Reply to Dateigröße von Systemdateien? on Mon, 23 Feb 2004 15:39:42 GMT]]></title><description><![CDATA[<p>Sorry, aber du hattest eben gefragt was die verschiedenen Parameter sind - und das wird doch dort eigentlich erklärt. Um welche geht es denn genau bzw. was verstehst du nicht.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/466051</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/466051</guid><dc:creator><![CDATA[flenders]]></dc:creator><pubDate>Mon, 23 Feb 2004 15:39:42 GMT</pubDate></item><item><title><![CDATA[Reply to Dateigröße von Systemdateien? on Mon, 23 Feb 2004 17:22:51 GMT]]></title><description><![CDATA[<p>code_pilot schrieb:</p>
<blockquote>
<p>Upps da hab ich mich verlesen. Wie mach ich denn das? Bei dem hier kommt auch nur -1 bei rum. Was sind diese verschiedenen Parameter?</p>
</blockquote>
<p>Sowas passiert schonmal... <img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f609.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--winking_face"
      title=";)"
      alt="😉"
    /></p>
<pre><code class="language-cpp">HANDLE testfile = CreateFile(&quot;C:\\PAGEFILE.SYS&quot;, GENERIC_READ, NULL, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL);
</code></pre>
<p>So würde ich eine Datei öffnen...<br />
Die Parameter sind ja in der MSDN recht exakt erklärt...</p>
<p>Das &quot;-1&quot; bedeutet INVALID_HANDLE_VALUE</p>
<p>MSDN schrieb:</p>
<blockquote>
<p>If the function fails, the return value is INVALID_HANDLE_VALUE. To get extended error information, call GetLastError.</p>
</blockquote>
<p>Was sagt denn GetLastError()?</p>
<p><strong>Vermutung:</strong><br />
Wie bereits oben beschrieben, öffnet das Betriebssystem solche Dateien offenbar <strong>ohne</strong> FILE_SHARE_READ (also <strong>exklusiv</strong>), somit schlägt wahrscheinlich <strong>jeder Versuch</strong>, eine solche Datei ein zweites Mal zu öffnen, fehl...</p>
]]></description><link>https://www.c-plusplus.net/forum/post/466148</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/466148</guid><dc:creator><![CDATA[Hepi]]></dc:creator><pubDate>Mon, 23 Feb 2004 17:22:51 GMT</pubDate></item><item><title><![CDATA[Reply to Dateigröße von Systemdateien? on Mon, 23 Feb 2004 18:46:27 GMT]]></title><description><![CDATA[<p>Probier's doch mal mit FindFirst!</p>
<p>Da wird auch die Groesse mit ausgelesen, ohne die Datei oeffnen zu muessen!</p>
]]></description><link>https://www.c-plusplus.net/forum/post/466221</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/466221</guid><dc:creator><![CDATA[DerAltenburger]]></dc:creator><pubDate>Mon, 23 Feb 2004 18:46:27 GMT</pubDate></item></channel></rss>