该服务的代码如下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#8.0新语法using declaration 2023-06-21
- 详解C#中普通缓存的使用 2023-04-15
- 记一次.Net Core通过GDI+在CentOS 7(Docker)环境中绘图报错The type initializer for 'Gdip' threw an excepti 2023-09-27
- c# DataDirectory的用法 2023-03-09
- 探索 .NET Core 依赖注入的 IServiceCollection 2023-09-27
- 将日期时间从C#保存到MongoDB 2023-11-13
- C#实现工厂方法模式 2023-06-21
- 对C#中public、private、protect的区别说明 2023-04-14
- c#-Windows Mobile 6.1-.NET CF StatusBar控件-嵌入图标 2023-11-17
- 如何在C#中使用指针 2023-02-17