Я работаю над кодом, который будет захватывать имя пользователя с локального компьютера и помещать его в файл журнала и запускать .exe, если имя пользователя не было восстановлено в файл журнала. Я был в состоянии запустить код на моей локальной машине, но когда я положил его на сервер и запустить его, я даюсь ошибку, которая гласит:Необлученное исключение в приложении
«Unhandeled исключение произошло в приложениях»
Детали:
См. Окончание этого сообщения для получения информации о вызове отладки в режиме «точно в срок» (JIT) вместо этого диалогового окна.
** * ** Exception Text ** * **** System.ComponentModel.Win32Exception (0x80004005): Система не может найти указанный файл в системе .Diagnostics.Process.StartWithShellExecuteEx (ProcessStartInfo startInfo) в System.Diagnostics.Process.Start() в System.Diagnostics.Process.Start (ProcessStartInfo startInfo) в System.Diagnostics.Process.Start (String fileName) на User.Form1.Form1_Load (Object отправителя, EventArgs е) в System.Windows.Forms.Form.OnLoad (EventArgs е) в System.Windows.Forms.Form.OnCreateControl() в System.Windows.Forms. Control.CreateControl (Boolean fIgnoreVisible) в System.Windows.Forms.Control.CreateControl() в System.Windows.Forms.Control.WmShowWindow (Message & м) в System.Windows.Forms.Control.WndProc (Message & м) в System.Windows.Forms.ScrollableControl.WndProc (Message & м) в System.Windows.Forms.Form.WmShowWindow (Message & м) в System.Windows.Forms.Form.WndProc (Message & м) в System.Windows.Forms.Control.ControlNativeWindow.OnMessage (Message & м) в System.Windows.Forms.Control.ControlNativeWindow.WndProc (Message & м) на System.Windows.Forms.NativeWindow.Callback (IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)
И вот мой код //////////////////////////// ////////
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.IO;
using System.Diagnostics;
namespace User
{
public partial class Form1 : Form
{
public const string dir = @"C:\Numara";
public const string path = dir + @"\Audit.log";
public const string TrackIT = @"\\tkahd-nti-1\TrackIt\Audit32.exe /Q";
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
//returns user name
//label1.Text = System.Environment.UserName.ToString();
string userName = System.Environment.UserName; //user name
if (!Directory.Exists(dir))
//directory does not exist
//create it
Directory.CreateDirectory(dir); //creates directory
//by this point directory is created
//now check file
if (!File.Exists(path))
//file does not exist, so create it
File.Create(path);
//Read data from the .dat file
string line = System.IO.File.ReadAllText(path);
//if the name of the logged in user
//is the same as the user name of the text file
//then exit program
if (line == userName)
Application.Exit();
else
//clear fields and write new name to file and begin audit
{
//clears fields
using (FileStream stream = new FileStream(@"C:\Numara\Audit.log", FileMode.Create))
{
using (TextWriter writer = new StreamWriter(stream))
{
//writer.Write("");
writer.Write(userName);
}
// writes new name to file
}
//StreamReader textIn =
// new StreamReader(
// new FileStream(path, FileMode.OpenOrCreate, FileAccess.Read));
//begins audit
Process.Start(TrackIT);
Application.Exit();
}
}
}
}
На самом деле не нужно, чтобы увидеть все это. –
@John Saunders - я отредактировал вопрос, чтобы не включать все связанные связанные исключения. Должен очистить нить. – JonH
@JonH: не нужен весь этот нерелевантный код. –