How does one map network drive from windows servic

2019-07-05 04:27发布

I'm trying to map network drive from windows service, I use batch file for executing the following command

NET USE U: \\192.168.55.6\folder password

While executing batch file either in service constructor or in onstart event, drive is not mapped?

        Process process = new Process();
        process.StartInfo.FileName = System.IO.Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().Location) + "\\MAP.BAT";
        process.StartInfo.CreateNoWindow = false;
        process.Start();

How does one map network drive from windows service?

7条回答
SAY GOODBYE
2楼-- · 2019-07-05 04:55

It might be better to just call the right API function, instead of calling a batch file to call another executable. The function you're looking for is DefineDosDevice()

查看更多
登录 后发表回答