Windows Server Summit 2024
Mar 26 2024 08:00 AM - Mar 28 2024 04:30 PM (PDT)
Microsoft Tech Community
LIVE
SOLVED

net use in system context and global SMB mount option cannot be removed

Copper Contributor

Hi folks,

I am using the current psexec.exe on my Windows Server 2022 to run Powershell in system context.

Then I mount a drive like this:

 

 

net use X: \\192.168.2.2\X /USER:user password /GLOBAL

 

 

The mapping works fine and the share is accessable from user context. But removing the mapping with net use is not possible anymore:

 

 

net use X: /delete

 

 

 I will receive the following error message:

 

 

The network connection could not be found.

More help is available by typing NET HELPMSG 2250.

 

 

To remove I have to call the Powershell function:

 

 

 Remove-SmbGlobalMapping X: \\192.168.2.2\X

 

 

It seems that there is lack of functionality of net use?

8 Replies
And you also run the net use X: /delete using psexec.exe? Never users/had the need to map a drive using system context, I just map drives using loginscript of Group Policy

@Harm_Veenstra

Yes, the delete was execute in the same context.

 

The need is forced by the /GLOBAL parameter, since only the system context is allowed to map a drive to all users. Of course, a group policy would be a solution but differs a little bit to my boundary conditions:
A service running in the system context sould map the drive for all users and also should delete the mapping after a well defined amount of time / operations.

Ok, you have very specific needs regarding the amount of time or operations... It's like the drive should only be available during business hours and should be made unavailable for backup operations or something like that? I guess that net.exe wasn't build for these kind of operations, new-smbglobalmapping and remove-smbglobalmapping cmdlets are much more recent ;) You could run those commands using Scheduled Tasks running as NT AUTHORITY\SYSTEM on system startup for connecting and disconnection on a schedule?
You are totally right. Also your purposed solution would fit.
With Powershell it will work fine, my question was regarding the aspect that I can use net.exe to create (seems to be up-to-date) but not to delete (missing feature?) the GLOBAL mapping.
best response confirmed by ondeso666 (Copper Contributor)
Solution
C:\WINDOWS\system32>net use x: \\localhost\admin$ /global
The command completed successfully.


C:\WINDOWS\system32>net use x: /global /delete
x: was deleted successfully.

That does work?
to delete a global mapped drive one has to add the global parameter again, thanks for your help
No problem, didn't use the "Net use" commands like that before so learned something myself too ;)

Hi!

 

Does the "/GLOBAL" switch map the drive to the users in the local Administrators group or also to other local users? This is regarding the statement "... since only the system context is allowed to map a drive to all users.".

 

rgds Christian

1 best response

Accepted Solutions
best response confirmed by ondeso666 (Copper Contributor)
Solution
C:\WINDOWS\system32>net use x: \\localhost\admin$ /global
The command completed successfully.


C:\WINDOWS\system32>net use x: /global /delete
x: was deleted successfully.

That does work?

View solution in original post