I’m trying to make a C# app that will connect to a file share, write to a file, then disconnect.
NetUseCmd = "net use t: \\Hostname\Vol /user:UserName SomePass"
System.Diagnostics.Process.Start(NetUseCmd);
Directory.CreateDirectory(DriveLetter + ":/" + DirName);
StreamWriter file = new StreamWriter(DriveLetter + ":/" + FileName);
file.Write(logdata);
file.Close();
System.Diagnostics.Process.Start("net use " + DriveLetter + ": /del");
On the second line of this, I’m seeing the error:
System.ComponentModel.Win32Exception was unhandled
Message="The system cannot find the file specified"
Source="System"
ErrorCode=-2147467259
NativeErrorCode=2
StackTrace:
at System.Diagnostics.Process.StartWithShellExecuteEx(ProcessStartInfo startInfo)
at System.Diagnostics.Process.Start()
at System.Diagnostics.Process.Start(ProcessStartInfo startInfo)
at System.Diagnostics.Process.Start(String fileName)
[...]
at System.AppDomain._nExecuteAssembly(Assembly assembly, String[] args)
at System.AppDomain.ExecuteAssembly(String assemblyFile, Evidence assemblySecurity, String[] args)
at Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()
at System.Threading.ThreadHelper.ThreadStart_Context(Object state)
at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
at System.Threading.ThreadHelper.ThreadStart()
InnerException:
I know the error message means it’s not finding the net command, but I don’t get why it isn’t finding it.
If you want to pass some parameter to net.exe you should use another overload version of
Process.Start():Please check your source code for the double back-slash too (without @ it’s an escape sequence).