I have been trying to resolve this really weird issue for a while!
We have a stored procedure that performs the below (all executed via xp_cmdshell
which is run using the proxy account that is set to the service account)
exec xp_cmdshell 'net use /delete X:'
exec xp_cmdshell 'net use X: \\<server_ip>\FOLDER
exec xp_cmdshell 'X:\SomeExeFile.exe'
However, when running step 3, I am getting a 'The system cannot find the drive specified'. Running exec xp_cmdshell 'whoami'
between steps 2 and 3 gives me the service account user, but running exec xp_cmdshell 'net use'
between steps 2 and 3 states that X: is 'Unavailable' !
Moreover, at this point, running 'net use
' from a cmd window (which is run as the service account user) also gives 'Unavailable' but when I execute all the above steps 1-3 again from the cmd window, everything works fine.
(And to further add, running exec xp_cmdshell 'net use'
from SSMS after doing the above via cmd then gives 'Disconnected X:' )
I cannot seem to understand what is happening since I am under the impression that net use executed on cmd and net use executed via xp_cmdshell should be the same. Can anyone help me understand why running 'net use
' via xp_cmdshell just after creating it using same user is giving 'Unavailable' please?
Thanks in advance!
PS: what's weird is that when I run the above from SSMS connected with a sysadmin account, this issue is not present!