Wednesday, May 5, 2021

Info: Find my system's network folder access' user (wmic, gwmi)

 I am wrote a tool to move objects from one server to another. To do this, I use network folders. This is a web tool so I created a local user on each machine that I need access to then created a share folder giving access to my local user.


While troubleshooting on my development system, my current login user sometimes is used to access the network folder instead of the userid that I wish to use. This occurs sometimes if I use Windows Explorer to check for files before I launch my tool. If my domain account has access to the network folder, this sets my current user account to the network folder. If it does not, then none is set. This was confusing because I was able to access certain folders but not others.

My Solution

I needed a way to see what user account is used to access the network folders. The following are a couple commands that I found that were useful to me.

1. wmic netuse get remotename,username

2. gwmi -Query 'Select LocalName, RemoteName, UserName from Win32_NetworkConnection'

#2 requires powershell to execute

Additional Info

Here are a couple other commands from the page that I didn't need but may be useful to others or my future self.

1. wmic netuse where LocalName="Z:" get UserName /value

2. gwmi -Query 'Select * from Win32_NetworkConnection' | Select-Object LocalName, RemoteName, UserName, ConnectionState | Sort-Object LocalName | ft -auto

3. rundll32.exe keymgr.dll, KRShowKeyMgr


No comments:

Post a Comment