Reputation: 65
I am trying to develop a Windows service using C# and Visual Studio 2017. I would like to dial up a pre configured VPN connection from within the service.
If I were to place the following line of code in a C# Windows Desktop app it will quickly flash a CMD prompt and dial the VPN: System.Diagnostics.Process.Start("rasdial.exe", "ConnectionName user password");
But it does not work in the service. I have brought it to this point. It does not throw an error, it does not dial a connection. It just seems to do nothing as i step through it.
System.Diagnostics.Process process = new System.Diagnostics.Process();
process.StartInfo = new System.Diagnostics.ProcessStartInfo("rasdial.exe", "ConnectionName user password");
process.StartInfo.CreateNoWindow = true;
process.StartInfo.UseShellExecute = false;
process.StartInfo.ErrorDialog = false;
process.StartInfo.RedirectStandardError = true;
process.StartInfo.RedirectStandardInput = true;
process.StartInfo.RedirectStandardOutput = true;
process.StartInfo.WindowStyle = System.Diagnostics.ProcessWindowStyle.Hidden;
process.Start()
Not sure how to fix this or what the next steps would be. An API would be nice if there was one.
I have done some Googling about this but cannot discover anything so i thought i would take it to the experts.
Thanks.
Stephen Simpson
Upvotes: 1
Views: 1973
Reputation: 65
Ken White pointed out that service accounts don't have the same privileges as normal user accounts. I solved the problem by running the service under a specific user.
Upvotes: 1