该服务的代码如下System.Diagnostics.Process proc = new System.Diagnostics.Process(); // Declare New Processvar arguments =String.Format(--ip {0} --user {1} --passwd {2} --guest {3} --gpasswd {4} --ac...

该服务的代码如下
System.Diagnostics.Process proc = new System.Diagnostics.Process(); // Declare New Process
var arguments =
String.Format("--ip {0} --user {1} --passwd {2} --guest {3} --gpasswd {4} --action {5}",
controllerIPAddress, controllerUsername, controllerPassword, username, password, action);
proc.StartInfo.Arguments = arguments;
proc.StartInfo.FileName = "C:\\Program Files\\Netspot\\ControllerInterfaceService\\batchfile.bat";
proc.StartInfo.RedirectStandardError = true;
proc.StartInfo.RedirectStandardOutput = true;
proc.StartInfo.UseShellExecute = false;
proc.StartInfo.CreateNoWindow = true;
proc.Start();
proc.WaitForExit();
我有一个Windows服务,该服务运行一个可以调用WGET命令的dos脚本,一切都很好,但是我需要使用批处理脚本创建和删除临时文件夹.
我的问题是服务正在将路径映射到
c:\windows\system32
代替
C:\\Program Files\\Netspot\\ControllerInterfaceService\
在测试工具中可以正常工作.
关于该服务为何使用system32文件夹而不是映射到本地文件夹的任何想法
解决方法:
默认情况下,Windows服务的当前目录为System32.
这个link可能会有所帮助:
System.IO.Directory.SetCurrentDirectory(System.AppDomain.CurrentDomain.BaseDirectory);
Use the above line of code to set the current directory to the same
directory as your windows service.
本文标题为:C#-.NET Windows服务从system32文件夹而非安装文件夹执行批处理文件


基础教程推荐
- C# 字符串的连接(实例讲解) 2022-12-04
- c#-Windows时间戳格式(MOUSEMOVEPOINT返回值的类型) 2023-11-12
- 使用C#编写自己的区块链挖矿算法 2023-01-27
- 利用WPF窗口程序设计简单计算器 2023-03-14
- c#如何利用定时器自动备份数据库详解 2023-05-05
- C# 修改文件的创建、修改和访问时间的示例 2023-04-14
- C#实现打字游戏 2023-02-16
- C# CM框架实现多页面管理的实例代码 2023-05-25
- 基于WPF实现筛选下拉多选控件 2023-07-19
- C#单独启动进程的几种方式及使用特点(使用不当导致端口无法释放) 2023-11-13