Note that there are some explanatory texts on larger screens.

plurals
  1. PO.NET Windows App Not displaying Message Box or writing to a Log file
    text
    copied!<p>I have a .NET 4.0 Windows application with no UI. All the code is in the Program class. The application is located on a network share. This is the basics of what it does.</p> <ol> <li>Check the C:\Program Files (x86)\Microsoft Office\ subfolders for<br> MSACCESS.EXE to determine what version of Office is installed. <ol> <li>Updates the registry with the Trusted Location to where an MS Access app will be copied to.</li> <li>Creates a Destination Folder and copies the contents of Master folder to the destination folder.</li> <li>It starts the MS Access application when all done.</li> <li>.NET app closes.</li> </ol></li> </ol> <p>I have message box prompts if things fail, like not creating the destination folder for example or not updating the registry. All users except myself (I wrote it!) do NOT get the Message Box prompts OR are able to write to the log file. However the destination folder gets created and files copies to the destination plus the MS Access application starts at the end.</p> <p>WHY or WHY are all users not able to get the msgbox prompts, update the registry or write to the log?</p> <pre><code> private static void UpdateTrustedLocationForAccessVersion(string startAppFolder) { var officeVersionsFound = new List&lt;String&gt;(); const string officeFolder = @"C:\Program Files (x86)\Microsoft Office\"; //Example of the folder we are looking for //C:\Program Files (x86)\Microsoft Office\Office14 if (Directory.Exists(officeFolder)) { var folders = Directory.GetDirectories(officeFolder, "*.*", SearchOption.TopDirectoryOnly); foreach (var folder in folders) { if (folder.ToString(CultureInfo.InvariantCulture).ToLower().Substring(officeFolder.Length).StartsWith("office1")) { var msAccessFile = Directory.GetFiles(folder, "MSACCESS.EXE", SearchOption.AllDirectories); if (msAccessFile.Length &gt; 0) { officeVersionsFound.Add(folder.Substring(folder.Length-2)); MessageBox.Show(folder.Substring(folder.Length - 2) + " was Found!"); WriteToLogFile(folder.Substring(folder.Length - 2) + " was Found!"); } } } } public static void WriteToLogFile(string logMessage) { string strLogFile = GetLogFile(); StreamWriter swLog; var strLogMessage = string.Format("{0}: {1}", DateTime.Now, "(User " + GetUserName() + " on " + GetMachineName() + ") " + logMessage); if (!File.Exists(strLogFile)) { swLog = new StreamWriter(strLogFile); } else { swLog = File.AppendText(strLogFile); } swLog.WriteLine(strLogMessage); swLog.Close(); } private static string GetLogFile() { var logFileName = DateTime.Today.Year.ToString(CultureInfo.InvariantCulture) + DateTime.Today.Month + DateTime.Today.Day + "_Log" + ".txt"; return _path + logFileName; } private static string GetUserName() { return Environment.UserName; } private static string GetMachineName() { return Environment.MachineName; } </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload