Trying to run a bat file from a windows service. Here is the code:
try
{
SecureString securePwd = new SecureString();
foreach (char c in pwd)
{
securePwd.AppendChar(c);
}
Process process = new Process();
process.StartInfo.UseShellExecute = false;
process.StartInfo.FileName = @"CMD.exe"; //The file in that DIR.
process.StartInfo.WorkingDirectory = @"C:\";
process.StartInfo.Arguments = @"/C " + filePath;
process.StartInfo.Verb = "runas";
process.StartInfo.UserName = user;
process.StartInfo.Password = securePwd;
process.Start();
}
catch (Exception ex)
{
EventLog myEventLog = new EventLog { Source = "MoC LaneUpdate" };
myEventLog.WriteEntry(ex.ToString(), EventLogEntryType.Error);
}
I have verified that this same code works when running in a non-service. I am also not getting an error message, however the .bat file does not run, at least it does not appear to in my current user session. Is my file running in a background session? How can I run a batch file in the user specified in the startinfo?