c# - How does one map network drive from windows service? -
I'm trying to map the network drive from windows, I use the batch file to execute the following command
is?
process process = new process (); Process.StartInfo.FileName = System.IO.Path.GetDirectoryName (System.Reflection.Assembly.GetExecutingAssembly (.pstation) + "\\ MAP.BAT"; Process.start.info.CreateNoWindow = false; Process.start (); How does a map network drive from the Windows service?
It can be obtained by reference to the Windows Script Host Object Model. Add a COM reference to
Windows Script Host Object Model that adds entry IWshRuntimeLibrary to the reference section Now you can use the following code to map the drive.
using IWshRuntimeLibrary; IWshNetwork_Class Network = New IWshNetwork_Class (); Network.MapNetworkDrive ("k:", @ "\\ 192.168.20.35 \ MyShare", type Missing, "user1", "password1"); You can use the following code to remove mapping or mapping.
network.RemoveNetworkDrive ("k:"); I've documented detailed steps
Comments
Post a Comment