Reputation: 2191
I'm compacting a lot of MDB files on the command line by scripting with msaccess.exe, e.g.:
> msaccess.exe example.mdb /compact
When this runs, the Access UI appears for a moment. I'd like to prevent the UI from appearing at all.
I'm using Access 2013, in case it might matter.
I've searched for an exhaustive command line parameter reference and only found this MS Support KB article among several similar pages, all with essentially the same info and none mentioning any version of Access newer than 2003.
Of the parameters listed at the above-linked article, I tried /nostartup
and /runtime
, but neither did the trick.
How can the Access UI be suppressed when running msaccess.exe on the command line?
Upvotes: 0
Views: 1061
Reputation: 2191
With the .NET Framework, setting ProcessStartInfo.WindowStyle
to ProcessWindowStyle.Hidden
does the trick.
Here's a simple class I wrote to encapsulate what I want. It also incorporates the splash image trick mentioned in the comments to this question (another source), since I couldn't find any other way to actually eliminate the splash image.
public class MsaccessCompactor
{
const string DefaultPathToMsaccess =
@"C:\Program Files\Microsoft Office\Office15\MSACCESS.EXE";
static readonly Bitmap BlackPixel;
static MsaccessCompactor()
{
BlackPixel = new Bitmap(1, 1);
BlackPixel.SetPixel(0, 0, Color.Black);
}
readonly string PathToMsaccess;
public MsaccessCompactor(string pathToMsaccess = DefaultPathToMsaccess)
{
PathToMsaccess = pathToMsaccess;
}
public void Compact(string pathToDatabase)
{
var arguments = string.Format("\"{0}\" /compact", pathToDatabase);
var startInfo = new ProcessStartInfo(PathToMsaccess, arguments);
startInfo.WindowStyle = ProcessWindowStyle.Hidden;
var pathToBmp = Path.ChangeExtension(pathToDatabase, "bmp");
BlackPixel.Save(pathToBmp, ImageFormat.Bmp);
using (var process = Process.Start(startInfo))
{
process.WaitForExit();
}
File.Delete(pathToBmp);
}
}
Note that there will still be a very short focus-defocus due to the seemingly unavoidable splash image appearance. Fortunately, it doesn't seem to markedly affect desktop usability in my very brief, very informal, self-performed acceptance testing. (And most thankfully, there is no Access UI window at all. Yay!)
Upvotes: 1