Using 'net use' through PowerShell exhibits different behaviour when done through cmd on a Windows Server 2012 instance

StackOverflow https://stackoverflow.com//questions/25011727

Question

I have a cloud service with the following line of code in startup.cmd:

net use n: \\<storage-account>.file.core.windows.net\scorm /u:<storage-account> <storage-password>

This successfully creates the mapped drive to point to the Azure File Services share, but it shows in Windows explorer as a disconnected drive and any attempt to remove it using the 'Disconnect' option results in a "This network connection does not exist" although if I double click the folder I am successfully able to access the files.

If I run the same command through a cmd prompt the drive shows as connected with the name of the share and the path displayed. Do I need to do anything different in the PowerShell startup command to render the same results as the cmd line prompt?

Was it helpful?

Solution

The "net use" command only connects to the share in the context you are running. So you will have to run the "net use" in the same context your role will run.

For web roles this will be "NT AUTHORITY\NETWORK SERVICE". To run "net use" in that context, you need a tool like psexec.exe, which you can download from Windows Sysinternals.

Place psexec.exe into your role's bin directory, and set up an elevated startup script with this command:

psexec -accepteula -u "NT AUTHORITY\NETWORK SERVICE" net use n: \\&lt;storage-account&gt;.file.core.windows.net\test /u:&lt;storage-account&gt; &lt;storage-password&gt;

OTHER TIPS

Drives are mapped to your user token, and administrators have two tokens. Limited and elevated. Make sure you are using consistent tokens. I.e. if mapped while Run As Aministrator then only programs running elevated can access that mapping.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top