Laden...

Prozess.Start mag nicht

Erstellt von AlfameisterT vor 18 Jahren Letzter Beitrag vor 18 Jahren 2.252 Views
A
AlfameisterT Themenstarter:in
154 Beiträge seit 2005
vor 18 Jahren
Prozess.Start mag nicht

Hallo,

ich möchte ein File (.txt und .doc) öffnen. Das ganz in einem neuen Prozess.
Bei Prozess.Start() öffnet sich das Dokument. Nur dann habe ich kein Zugriff mehr.
D.h. die meisten Eigenschaften von Prozess bringen eine InvalidOperationException, genauso das Handle. Aber warum X(


System.Diagnostics.ProcessStartInfo pInfo = new System.Diagnostics.ProcessStartInfo("z.B.XYZ.doc");	
pInfo.UseShellExecute = true;

Process p = new Process();
p.StartInfo = pInfo;	
p.Start();

Thread.Sleep(500);

if(! p.HasExited )
{
	p.CloseMainWindow();
	p.Close();
}

.

49.485 Beiträge seit 2005
vor 18 Jahren

Hallo AlfameisterT,

vermutlich wegen UseShellExecute = true. Dann wird nämlich eine Shell gestartet und die startet erst das eigentliche Programm. Du kannst aber das Programm der Wahl auch direkt starten.

Process.Start ("notepad.exe", "x.txt");

statt

Process.Start ("x.txt");

herbivore

A
AlfameisterT Themenstarter:in
154 Beiträge seit 2005
vor 18 Jahren

Hallo,

danke für die Antwort.
Das Problem gestaltet sich doch etwas schwieriger. Mit normalen Files funktionert das mit dem neuen Prozess.
Ich möchte aber .lnk Files öffnen.

Das Programm soll Ziel-Objekte von Windowslinks (.lnk) kopieren.
Wenn sich eine Datei verschoben hat wird sie nicht mehr gefunden. Um die Links aufzulösen benutze ich eine fertige Klasse welche ein COM Object wrappt.
Nu lößt das Teil aber nicht alle fehlerhaften Links auf.

Ich habe bemerkt wenn man die .lnk Files trotzdem öffnet, findet Windows oft das Ziel und repariert die Links.

Deshalb soll das Programm zur Not diesen weg gehen und die .lnk Files direkt öffnen und wieder schließen.

Ich muss mal kucken ob ich den Prozess anhand des Filenames irgendwie im System finde. Ansonsten bleibt das File ja von dem Prozess belegt.

.

49.485 Beiträge seit 2005
vor 18 Jahren

Hallo AlfameisterT,

das klingt mir danach, als dass du shortcut.exe aus dem Server Resource Kit gebrauchen könntest.

shortcut: [-? -h -f -c -r -s] [[-t] target [[-n] name]] [-d working directory]
        [-a Arguments] [-i Iconfile] [-x Icon index] [-u {all|[natdix]}]
        [-l logfile]

  -? -h        This help
  -f           Force overwrite of an existing short cut
  -c           Change existing shortcut
  -s           Make shortcut non tracking (Stupid)
  -r           Resolve broken shortcut <==============
  -t target    Specifies the target of the shortcut
  -n name      Specifies the file name of the shortcut file
  -d directory Specifies the directory name to start the application in
  -a arguments Specifies the arguments passed when the shortcut is used
  -i iconfile  Specifiles the file the icon is in
  -x index     Specifies the index into the icon file
  -u [spec]    Dumps the contents of a shortcut. 'all' is the same as 'natdix'
               but the letters of 'natdix' can be specified to display specific
               fields in the shortcut (repeats allowed, and order followed)
  -l logfile   record error messages in specified file

herbivore

A
AlfameisterT Themenstarter:in
154 Beiträge seit 2005
vor 18 Jahren

Hallo,

danke für die Info.
Ich glaube das dieses Tool das gleiche COM-Object verwendet.

Denn es ist genauso fehlerhaft. " unable to find ..."
Klicke ich aber den Link, so findet Windows das File.


Muss mich korrigieren, das Tool funktioniert schon, nur ist die genaue Anwendung bisla umständlich.