I am trying simple windows service it works fine till there is no connection with database.once I establish connection my service get installed and start successfully but does not work correctly and does not get stop.It throws an Error as :"Windows Could not Stop service on local computer".
Following is Code :
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Diagnostics;
using System.Linq;
using System.ServiceProcess;
using System.Text;
using System.Threading.Tasks;
using System.IO;
using System.Timers;
using System.Data;
using System.Data.SqlClient;
namespace tgfservice4
{
public partial class tgfservice4 : ServiceBase
{
private static string con = "Data Source=ABC;Initial Catalog=ABC;User Id=ABC;Password=ABC";//ConfigurationManager.ConnectionStrings["ABCD"].ToString();
private SqlConnection sn = new SqlConnection(con);
private SqlCommand sm;
Timer timer = new Timer();
public tgfservice4()
{
InitializeComponent();
}
protected override void OnStart(string[] args)
{
//add this line to text file during start of service
TraceService("start service");
//handle Elapsed event
timer.Elapsed += new ElapsedEventHandler(OnElapsedTime);
//This statement is used to set interval to 1 minute (= 60,000 milliseconds)
timer.Interval = 60000;
//enabling the timer
timer.Enabled = true;
}
protected override void OnStop()
{
timer.Enabled = false;
TraceService("stopping service");
}
private void OnElapsedTime(object source, ElapsedEventArgs e)
{
TraceService("Another entry at " + DateTime.Now);
}
private void TraceService(string content)
{
sn.Open();
// sm = new SqlCommand("Update_Table", sn);
// sm.CommandType = CommandType.StoredProcedure;
try
{
// sm.Parameters.AddWithValue("#value", "0");
// sm.ExecuteNonQuery();
}
catch
{
throw;
}
finally
{
sm.Dispose();
sn.Close();
sn.Dispose();
}
//set up a filestream
FileStream fs = new FileStream(#"d:\MeghaService.txt", FileMode.OpenOrCreate, FileAccess.Write);
//set up a streamwriter for adding text
StreamWriter sw = new StreamWriter(fs);
//find the end of the underlying filestream
sw.BaseStream.Seek(0, SeekOrigin.End);
//add the text
sw.WriteLine(content);
//add the text to the underlying filestream
sw.Flush();
//close the writer
sw.Close();
}
}
}
I think your OnStop method is taking long time to connect to database and opearting on that connection.
Generally you are supposed to do heavy operation in another thread in background.
Usually the OnStart as well as OnStop events within the windows service are used to initiate a process and the time consuming process will carryout it's execution within a child thread
If there is any error on startup then also service may behave like this. To debut you can do something like following.
protected override void OnStart(string[] args)
{
System.Diagnostics.Debugger.Launch();
...
}
and then attach visual studio to the process and debug the issue.
also you can look into the Event viewer for system and application logs.
computer/server manager -> Event Viewer -> Windows Logs -> Application
If an exception is thrown in OnStop, the Service Control Manager will not unload your service. As such, in case you have a problem connecting to the database, just log this in the event log without throwing further errors. Also, do not attempt to close the connection if it is not already opened. Add a try catch upon closing the connection. Bottom line, make sure nothing blows up in the OnClose.
Related
Im trying to build a cmd.exe wrapper but i cant figure out how to wait for a process inside the cmd process to finish.
When im run ping.exe in my program, my "inputline" (the path) will output to the console before the ping-command is finished.
I cant use: .WaitForInputIdle(); because I don't have a GUI. "This could be because the process does not have a graphical interface."
Is it even possible to solve or is there any better way to do it?
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
namespace ObjectTest
{
class cmd
{
Process cmdProcess;
StreamWriter cmdStreamWriter;
public cmd()
{
//WinAPI.ShowConsoleWindow();
Process();
//WinAPI.HideConsoleWindow();
}
private void Process()
{
StartCmd();
string command = "";
while (command != "exit")
{
Thread.Sleep(100);
cmdProcess.WaitForInputIdle();
Console.Write(Environment.NewLine + Directory.GetCurrentDirectory() + "> ");
command = Console.ReadLine();
SendCommand(command);
}
}
private void StartCmd()
{
cmdProcess = new Process();
cmdProcess.StartInfo.FileName = "cmd.exe";
cmdProcess.StartInfo.UseShellExecute = false;
cmdProcess.StartInfo.CreateNoWindow = true;
cmdProcess.StartInfo.RedirectStandardOutput = true;
cmdProcess.OutputDataReceived += new DataReceivedEventHandler(SortOutputHandler);
cmdProcess.ErrorDataReceived += new DataReceivedEventHandler(SortOutputHandler);
cmdProcess.StartInfo.RedirectStandardInput = true;
cmdProcess.Start();
cmdStreamWriter = cmdProcess.StandardInput;
cmdProcess.BeginOutputReadLine();
}
private void SendCommand(string command)
{
cmdStreamWriter.WriteLine(command);
}
private void btnQuit_Click(object sender, EventArgs e)
{
cmdStreamWriter.Close();
cmdProcess.WaitForExit();
cmdProcess.Close();
}
private static void SortOutputHandler(object sendingProcess, DataReceivedEventArgs outLine)
{
if (!string.IsNullOrEmpty(outLine.Data))
{
Console.WriteLine(outLine.Data);
}
}
}
}
If it's only actual processes you want to catch you can use polling methods as such:
Before running the command, collect all existing processes of, for example, ping (.exe), using Process.GetProcessesByName, and store their PIDs.
Run the command
In order to wait for exit, Again scan for all ping processes, and wait on all processes that did not previously exist.
Note that this will fail, or at least not be accurate, if another process will launch another ping between steps 1 and 3.
You should also keep in mind that CMD does not wait on all type of processes, only those which are defined as console applications (see this question).
When starting a process, you can specify that you want to wait:
var process = Process.Start(...);
process.WaitForExit();
Here's a link to MSDN explaining it: http://msdn.microsoft.com/en-us/library/fb4aw7b8(v=vs.110).aspx
I think this is wat you need.
I have been following an old tutorial for making a chat program and I have been dissecting it to fit into a new form, although I have gotten it to work as it was intended it runs into the error: "Unable to read data from the transport connection: A blocking operation was interrupted by a call to WSACancelBlockingCall."
that points to this part of the code.
while (Connected)
{
// Show the messages in the log TextBox
this.Invoke(new UpdateLogCallback(this.UpdateLog), new object[] { srReceiver.ReadLine() });
}
I only get the error upon closing the client, or disconnecting.
this is the majority of the client code.
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Net;
using System.Net.Sockets;
using System.Threading;
using System.IO;
namespace Table_Top_RPG
{
public partial class Connect : Form
{
// Will hold the user name
private string UserName = "Unknown";
public static StreamWriter swSender;
private StreamReader srReceiver;
private TcpClient tcpServer;
// Needed to update the form with messages from another thread
private delegate void UpdateLogCallback(string strMessage);
// Needed to set the form to a "disconnected" state from another thread
private delegate void CloseConnectionCallback(string strReason);
private Thread thrMessaging;
private IPAddress ipAddr;
private bool Connected;
public Connect()
{
// On application exit, don't forget to disconnect first
Application.ApplicationExit += new EventHandler(OnApplicationExit);
InitializeComponent();
}
private void BtnConnect_Click(object sender, EventArgs e)
{
// If we are not currently connected but awaiting to connect
if (Connected == false)
{
InitializeConnection();
}
else // We are connected, thus disconnect
{
CloseConnection("Disconnected at user's request.");
}
}
// The event handler for application exit
public void OnApplicationExit(object sender, EventArgs e)
{
if (Connected == true)
{
// Closes the connections, streams, etc.
Connected = false;
swSender.Close();
srReceiver.Close();
tcpServer.Close();
}
}
private void InitializeConnection()
{
// Parse the IP address from the TextBox into an IPAddress object
ipAddr = IPAddress.Parse(Connect.IpBox.Text);
// Start a new TCP connections to the chat server
tcpServer = new TcpClient();
tcpServer.Connect(ipAddr, int.Parse(Connect.PortBox.Text));
// Helps us track whether we're connected or not
Connected = true;
// Prepare the form
UserName = Connect.NameBox.Text;
// Disable and enable the appropriate fields
IpBox.Enabled = false;
NameBox.Enabled = false;
Main.TxtMsg.Enabled = true;
Connect.BtnConnect.Text = "Disconnect";
// Send the desired username to the server
swSender = new StreamWriter(tcpServer.GetStream());
swSender.WriteLine(UserName);
swSender.Flush();
// Start the thread for receiving messages and further communication
thrMessaging = new Thread(new ThreadStart(ReceiveMessages));
thrMessaging.Start();
}
private void ReceiveMessages()
{
// Receive the response from the server
srReceiver = new StreamReader(tcpServer.GetStream());
// If the first character of the response is 1, connection was successful
string ConResponse = srReceiver.ReadLine();
// If the first character is a 1, connection was successful
if (ConResponse[0] == '1')
{
// Update the form to tell it we are now connected
this.Invoke(new UpdateLogCallback(this.UpdateLog), new object[] { "Connected Successfully!" });
}
else // If the first character is not a 1 (probably a 0), the connection was unsuccessful
{
string Reason = "Not Connected: ";
// Extract the reason out of the response message. The reason starts at the 3rd character
Reason += ConResponse.Substring(2, ConResponse.Length - 2);
// Update the form with the reason why we couldn't connect
this.Invoke(new CloseConnectionCallback(this.CloseConnection), new object[] { Reason });
// Exit the method
return;
}
// While we are successfully connected, read incoming lines from the server
while (Connected)
{
// Show the messages in the log TextBox
this.Invoke(new UpdateLogCallback(this.UpdateLog), new object[] { srReceiver.ReadLine() });
}
}
internal void CloseConnection(string Reason)
{
// Show the reason why the connection is ending
Main.ChatLog.AppendText(Reason + "\r\n");
// Enable and disable the appropriate controls on the form
IpBox.Enabled = true;
NameBox.Enabled = true;
Main.TxtMsg.Enabled = false;
BtnConnect.Text = "Connect";
// Close the objects
Connected = false;
swSender.Close();
srReceiver.Close();
tcpServer.Close();
}
// This method is called from a different thread in order to update the log TextBox
private void UpdateLog(string strMessage)
{
// Append text also scrolls the TextBox to the bottom each time
Main.ChatLog.AppendText(strMessage + "\r\n");
}
}
}
there is another form called Main where all the chat dialog is sent, but the majority of its code is not relevant.
if anyone knows a better way to handle this or knows of a good chat program tutorial i can go through for better examples of how clients connect and disconnect is handled properly without crashing I would be much appreciative.
You should probably think about using Asynchronous programming, where there are no blocking calls.
The problem is, as you surely know, that you close your client while there is an active call.
I'm pretty sure NetworkStream and StreamReader/Writer does have some asynchronous methods. Try to look at some here:
http://msdn.microsoft.com/en-us/library/system.io.streamreader.readasync.aspx
I believe you need to close and dispose each stream per use in your case because you are performing them synchronously. Consider using the using statement for writing...and do something similar for reading. Plus don't forget to remove them from the CloseConnection...
using (NetworkStream ns=tcpServer.GetStream())
{
swSender = new StreamWriter(ns);
swSender.WriteLine(UserName);
swSender.Flush();
ns.Close();
ns.Dispose();
swSender = null;
}
When I use F11 debug, NetStatus value is true, but when I use F5 debug, NetStatus value is false. Why? How do I fix it?
I don't know what time the _connect value changes.
Is this a multi-threading synchronization issue?
namespace conn
{
using System;
using System.Collections.Generic;
using System.Text;
using System.Net;
using System.Net.Sockets;
using System.Threading;
class Program
{
static void Main(string[] args)
{
wait_conn();
}
private static void wait_conn()
{
bool NetStatus = false;
string DataS = "127.0.0.1";
CheckIpConn conn = new CheckIpConn();
conn.CheckIp(DataS);
//Thread.Sleep(3000);
NetStatus = conn.Connected;
if (!NetStatus)
Console.WriteLine(conn.Connected.ToString());
Console.Read();
}
}
public class CheckIpConn
{
private int _port = 135;
private volatile bool _connect;
private IPEndPoint _iPEndPoint;
private TcpClient _client;
private TimerCallback _timerCallBack;
private System.Threading.Timer _timer;
public bool Connected
{
get { return _connect; }
}
public void CheckIp(string Ip)
{
_iPEndPoint = new IPEndPoint(IPAddress.Parse(Ip), _port);
_timerCallBack = new TimerCallback(CheckConnect);
_timer = new System.Threading.Timer(_timerCallBack, null, 10, 1000);
_timer.Dispose();
}
public void CheckConnect(object o)
{
try
{
_client = new TcpClient();
_client.Connect(_iPEndPoint);
_connect = true;
_client.Close();
}
catch
{
_connect = false;
}
}
}
}
Your code is extremely unclear - it looks like you're trying to do things asynchronously, but doing so badly. For example, you're creating a Timer and then immediately disposing of it.
When stepping line by line in the debugger, that may work - because the timer may get to fire before the Dispose call... but when you just run the code, you're disposing of the timer before it gets a chance to fire. Additionally, you're using the value of conn.Connected immediately after calling CheckIp - so if the timer did fire, it would probably be after you'd checked the value anyway.
I would strongly advise you to just do the check synchronously. Get that working and then consider an asynchronous approach.
You create a timer which executes a function on the threadpool - so you don't really have much of a gurantee that when CheckIP returns the timer callback has been exececuted.
Furthermore: Why do you dispose of the timer as soon as you created it? While MSDN states that a callback can occur after dispose because the callback is queued this is certainly a bad style. Also this means that you are only checking once - so you might as well do it synchroneously - especially wait_conn indicates that it should wait until a connection has been established.
Also: TcpClient is disposable so you should do:
using (var client = new TcpClient())
{
client.Connect(_iPEndPoint);
_connect = true;
client.Close();
}
There is no point having a member variable in the class if you do not do anything with it anyway.
I am fairly new to all this but I have looked through questions and can't find anything that answers my question.
I am writing a simple service that checks whether it can reach one of our servers whenever there is a change to it's network settings.
I am using the two events under the NetworkChange class, NetworkAddressChanged and NetworkAvailabiltyChanged.
When either fire the service tries to ping the server and depending on the result changes the ProxyEnable setting.
The Code:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Diagnostics;
using System.Linq;
using System.ServiceProcess;
using System.Text;
using System.Net.NetworkInformation;
using Microsoft.Win32;
namespace ProxyManager
{
public partial class ProxyManager : ServiceBase
{
static RegistryKey rk = Registry.CurrentUser.OpenSubKey(#"Software\Microsoft\Windows\CurrentVersion\Internet Settings",true);
static string currentProxy = rk.GetValue("ProxyEnable").ToString();
static string newProxy;
public ProxyManager()
{
InitializeComponent();
NetworkChange.NetworkAddressChanged += new NetworkAddressChangedEventHandler(NetworkChange_NetworkAddressChanged);
NetworkChange.NetworkAvailabilityChanged += new NetworkAvailabilityChangedEventHandler(NetworkChange_NetworkAvailabilityChanged);
newProxy = "0";
}
protected override void OnStart(string[] args)
{
}
void NetworkChange_NetworkAvailabilityChanged(object sender, NetworkAvailabilityEventArgs e)
{
ProxySwitcher();
EventLog evt = new EventLog("ProxyManager");
string message = "Proxy Manager, Newtwork availabilty changed. Proxy switched to " + newProxy.ToString();
evt.Source = "Proxy Manager";
evt.WriteEntry(message,EventLogEntryType.Information);
}
void NetworkChange_NetworkAddressChanged(object sender, EventArgs e)
{
ProxySwitcher();
EventLog evt = new EventLog("ProxyManager");
string message = "Proxy Manager, Newtwork address changed. Proxy switched to " + newProxy.ToString();
evt.Source = "Proxy Manager";
evt.WriteEntry(message,EventLogEntryType.Information);
}
void ProxySwitcher()
{
if (currentProxy == "0")
{
newProxy = "1";
}
else
{
newProxy = "0";
}
try
{
Ping myPing = new Ping();
string host = "FILE SERVER";
byte[] buffer = new byte[32];
int timeout = 1000;
PingOptions pingOptions = new PingOptions();
PingReply reply = myPing.Send(host, timeout, buffer, pingOptions);
if (reply.Status == IPStatus.Success)
{
if (currentProxy == "0")
{
rk.SetValue("ProxyEnable", newProxy);
}
}
else
{
if (currentProxy == "1")
{
rk.SetValue("ProxyEnable", newProxy);
}
}
}
catch (PingException pingEx)
{
rk.SetValue("ProxyEnable", 0);
}
}
protected override void OnStop()
{
}
}
}
My problem is that when the service is installed and running, the events are either not being triggered or not being picked up. There related events are not being logged and the proxy is not switching.
I tried the code, minus the event handlers in a console app that I could run at will and that worked fine, depending on the network availability.
I am running Windows 7 x86, but am coding in .NET 3.5.
Any help will be gratefully received.
I wrote a rather large WMI application and this is the one feature that I could never get to work well with WMI. Sorry to disagree with Ted but .NET WMI support is terrible, particularly with dealing with exceptions properly and when dealing with pre-Vista operating systems.
Two caveats when dealing with these events. First, they only work if subscribed on the main thread. However, since your log file gets created then you appear to have verified that the event is being triggered. The second problem is in the assumption your code makes about the current state of the network.
From the look of your code you are starting with Proxy = 0, so no proxy. Then when you receive a network change event you toggle the proxy. Consider what happens when your service starts and the network is "down" already, which might very well happen during bootup depending on when your service starts in relation to the network stack initialization. You will be setting "no proxy" when the NIC is down, then setting "Proxy" when the NIC is up. This seems to be inverted to what you were trying to accomplish.
The fix is simple, in the event you need to check the state of the network to know why the change event was fired. So, in your NetworkAvailabilityChanged event you are going to want to check NetworkInterface.GetIsNetworkAvailable() which returns true as long as there is one network interface that isn't loopback or ms-tunnel.
For the NetworkAddressChanged event presumably you are going to want to check the address to see if it's valid or not to determine if your proxy needs to be invoked. You can do this by grabbing the
UnicastIPAddressInformationCollection like this...
NetworkInterface[] niList = NetworkInterface.GetAllNetworkInterfaces();
foreach (NetworkInterface ni in niList)
{
switch (ni.NetworkInterfaceType)
{
case NetworkInterfaceType.Ethernet: // 10baseT
case NetworkInterfaceType.FastEthernetT: // 100baseT
case NetworkInterfaceType.GigabitEthernet:
GatewayIPAddressInformationCollection gwIPColl = ni.GetIPProperties().GatewayAddresses;
UnicastIPAddressInformation uniIPInfo = null;
UnicastIPAddressInformationCollection IPcoll = ni.GetIPProperties().UnicastAddresses;
if (IPcoll.Count <= 0)
{
LogFile.LogMe("No valid unicast IP address");
broken = true;
break; // Cannot continue if we don't have an IP in the colletion
}
.
.
.
or something similar depending on how complicated your want to make it. When I check for network address validity I check the Unicast address, Netmask (.IPv4Mask) and the defined gateway from GatewayIPAddressInformationCollection (.GetIPProperties().GatewayAddresses)
Hopefully that helps you out a little bit.
You may try logging to a file instead of the event log. There are permission issues with the event log and when you are running the service, the security model may be preventing you from writing to the log.
Consider using WMI.
Some sample VBScripts on http://msdn.microsoft.com/en-us/library/aa394595(v=vs.85).aspx
I know from experience that WMI works, but never tried it with "NetworkChange" object.
I'm calling Process.Start, but it blocks the current thread.
pInfo = new ProcessStartInfo("C:\\Windows\\notepad.exe");
// Start process
mProcess = new Process();
mProcess.StartInfo = pInfo;
if (mProcess.Start() == false) {
Trace.TraceError("Unable to run process {0}.");
}
Even when the process is closed, the code doesn't respond anymore.
But Process.Start is really supposed to block? What's going on?
(The process start correctly)
using System;
using System.Diagnostics;
using System.Threading;
using System.Windows.Forms;
namespace Test
{
class Test
{
[STAThread]
public static void Main()
{
Thread ServerThread = new Thread(AccepterThread);
ServerThread.Start();
Console.WriteLine (" --- Press ENTER to stop service ---");
while (Console.Read() < 0) { Application.DoEvents(); }
Console.WriteLine("Done.");
}
public static void AccepterThread(object data)
{
bool accepted = false;
while (true) {
if (accepted == false) {
Thread hThread = new Thread(HandlerThread);
accepted = true;
hThread.Start();
} else
Thread.Sleep(100);
}
}
public static void HandlerThread(object data)
{
ProcessStartInfo pInfo = new ProcessStartInfo("C:\\Windows\\notepad.exe");
Console.WriteLine("Starting process.");
// Start process
Process mProcess = new Process();
mProcess.StartInfo = pInfo;
if (mProcess.Start() == false) {
Console.WriteLine("Unable to run process.");
}
Console.WriteLine("Still living...");
}
}
}
Console output is:
--- Press ENTER to stop service ---
Starting process.
Found it:
[STAThread]
Makes the Process.Start blocking. I read STAThread and Multithreading, but I cannot link the concepts with Process.Start behavior.
AFAIK, STAThread is required by Windows.Form. How to workaround this problem when using Windows.Form?
News for the hell:
If I rebuild my application, the first time I run application work correctly, but if I stop debugging and restart iy again, the problem araise.
The problem is not raised when application is executed without the debugger.
No, Process.Start doesn't wait for the child process to complete... otherwise you wouldn't be able to use features like redirected I/O.
Sample console app:
using System;
using System.Diagnostics;
public class Test
{
static void Main()
{
Process p = new Process {
StartInfo = new ProcessStartInfo("C:\\Windows\\notepad.exe")
};
p.Start();
Console.WriteLine("See, I'm still running");
}
}
This prints "See, I'm still running" with no problems on my box - what's it doing on your box?
Create a ProcessStartInfo and set UseShellExecute to false (default value is true). Your code should read:
pInfo = new ProcessStartInfo("C:\\Windows\\notepad.exe");
pInfo.UseShellExecute = false;
// Start process
mProcess = new Process();
mProcess.StartInfo = pInfo;
if (mProcess.Start() == false) {
Trace.TraceError("Unable to run process {0}.");
}
I had the same issue and starting the executable creating the process directly from the executable file solved the issue.
I was experiencing the same blocking behavior as the original poster in a WinForms app, so I created the console app below to simplify testing this behavior.
Jon Skeet's example uses Notepad, which only takes a few milliseconds to load normally, so a thread block may go unnoticed. I was trying to launch Excel which usually takes a lot longer.
using System;
using System.Diagnostics;
using static System.Console;
using System.Threading;
class Program {
static void Main(string[] args) {
WriteLine("About to start process...");
//Toggle which method is commented out:
//StartWithPath(); //Blocking
//StartWithInfo(); //Blocking
StartInNewThread(); //Not blocking
WriteLine("Process started!");
Read();
}
static void StartWithPath() {
Process.Start(TestPath);
}
static void StartWithInfo() {
var p = new Process { StartInfo = new ProcessStartInfo(TestPath) };
p.Start();
}
static void StartInNewThread() {
var t = new Thread(() => StartWithPath());
t.Start();
}
static string TestPath =
Environment.GetFolderPath(Environment.SpecialFolder.Desktop) +
"\\test.xlsx";
}
Calls to both StartWithPath and StartWithInfo block my thread in a console app. My console does not display "Process Started" until after the Excel splash screen closes and the main window is open.
StartInNewThread will display both messages on the console immediately, while the splash screen for Excel is still open.
We had this problem when launching a .bat script that was on a network drive on a different domain (we have dual trusted domains). I ran a remote C# debugger and sure enough Process.Start() was blocking indefinitely.
When repeating this task interactively in power shell, a security dialog was popping up:
As far as a solution, this was the direction we went. The person that did the work modified domain GPO to accomplish the trust.
Start server via command prompt:
"C:\Program Files (x86)\IIS Express\iisexpress" /path:\Publish /port:8080
This take access to sub-threads of the tree process of OS.
If you want to launch process and then make the process independent on the "launcher" / the originating call:
//Calling process
using (System.Diagnostics.Process ps = new System.Diagnostics.Process())
{
try
{
ps.StartInfo.WorkingDirectory = #"C:\Apps";
ps.StartInfo.FileName = #"C:\Program Files\Microsoft Office\Office14\MSACCESS.EXE"; //command
ps.StartInfo.Arguments = #"C:\Apps\xyz.accdb"; //argument
ps.StartInfo.UseShellExecute = false;
ps.StartInfo.RedirectStandardOutput = false;
ps.StartInfo.WindowStyle = System.Diagnostics.ProcessWindowStyle.Maximized;
ps.StartInfo.CreateNoWindow = false; //display a windows
ps.Start();
}
catch (Exception ex)
{
MessageBox.Show(string.Format("==> Process error <=={0}" + ex.ToString(), Environment.NewLine));
}
}