I want to design a small program in C# to monitor if a net drive is present, if not…
- User
I want to design a small program in C# to monitor if a net drive is present, if not present, it runs net use command like
net use v: \\server\eng /u:serverusr\test abc123to mound the net drive.To monitor, it checks the net drive presence once per minute, if fails, then run net use command mentioned above.
Give me demo C# code.
- Assistant
- User
Does net use command have to be run with administrator privilege?
- Assistant
No, the
net usecommand does not always have to be run with administrator privileges. You can map network drives without administrative rights as a standard user. However, whether or not you need administrative privileges can depend on the network policies and the specific configuration of the systems involved.For example, if you're just connecting to a share for which you have the appropriate permissions, you should not need to run the command with elevated privileges. If the share or the network policy has specific security settings that require administrative credentials, you would then need to run it as an administrator.
If you find that your program does not require administrative rights to map the network drive, you can modify the C# code provided earlier to exclude the line that runs the command prompt as an administrator:
processInfo.Verb = "runas"; // Remove this line if admin rights are not neededAs mentioned before, keep in mind the risks of storing plain-text credentials in your source code and consider more secure alternatives for storing credentials.