web-dev-qa-db-ja.com

ユーザーがマップしたネットワークドライブを確認するにはどうすればよいですか?

ドメイン内のすべてのデスクトップにログインしているすべてのユーザーに設定されているドライブマッピングを見つけるためにスキャンする最良の方法は何ですか?これは、環境で使用されているドライブ文字を判別するために使用されます。

これは、Active Directory2003ドメイン内の企業環境にあります。私は現在、「NetUse」を実行してログファイルにパイプするSMS 2003広告を使用しています。すべてのデスクトップにアクセスするのに非常に長い時間がかかります。より良い方法はありますか?

5
spoulson

これらの答えはすべて、私を動かすための非常に良い手がかりでした。ありがとうございました。

私は偶然に遭遇しました このVBScriptの例 それは私が探していたものを正確に実行し、うまく機能します。

その投稿のコードスニペットは次のとおりです。

'Define variables, constants and objects

strComputer="REMOTE MACHINE HERE"
Const HKEY_USERS = &H80000003
Set objWbem = GetObject("winmgmts:")
Set objRegistry = GetObject("winmgmts://" & strComputer & "/root/default:StdRegProv")
Set objWMIService = GetObject("winmgmts:"  & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")

'Go and get the currently logged on user by checking the owner of the Explorer.exe process.  

Set colProc = objWmiService.ExecQuery("Select Name from Win32_Process" & " Where Name='Explorer.exe' and SessionID=0")

If colProc.Count > 0 Then
   For Each oProcess In colProc
       oProcess.GetOwner sUser, sDomain
   Next
End If

'Loop through the HKEY_USERS Hive until (ignoring the .DEFAULT and _CLASSES trees) until we find the tree that 
'corresponds to the currently logged on user.
lngRtn = objRegistry.EnumKey(HKEY_USERS, "", arrRegKeys)    

For Each strKey In arrRegKeys
   If UCase(strKey) = ".DEFAULT" Or UCase(Right(strKey, 8)) = "_CLASSES" Then
   Else

       Set objSID = objWbem.Get("Win32_SID.SID='" & strKey & "'")

'If the account name of the current sid we're checking matches the accountname we're looking for Then
'enumerate the Network subtree
       If objSID.accountname = sUser Then 
           regpath2enumerate = strkey & "\Network" 'strkey is the SID
           objRegistry.enumkey hkey_users, regpath2enumerate, arrkeynames

'If the array has elements, go and get the drives info from the registry
           If Not (IsEmpty(arrkeynames)) Then
               For Each subkey In arrkeynames
                   regpath = strkey & "\Network\" & subkey
                   regentry = "RemotePath"
                   objRegistry.getstringvalue hkey_users, regpath, regentry, dapath
                   wscript.echo subkey & ":" & vbTab & dapath
               Next
           End If
       End If
   End If
Next
1
spoulson

最速の方法は [〜#〜] wmi [〜#〜] を使用することです。 Perlに精通している場合は、 Win32 モジュールを使用することもできます。このあたりのどこかに、その情報のほとんどを提供するスクリプトがあります。

1
Glen Solsberry

もっと良い方法があるかもしれませんが、あなたが今それをしている方法は実際にはとても良いです、そしてそれは遅いように感じますが、速度は問題ではないはずです。

ユーザーはマッピングを毎日変更していません。たとえユーザーが変更している場合でも、おそらく比較的永続的なマッピングのみを気にします。

Net Useアドバタイズメントの実行には時間がかかりますが、ドライブマッピングを把握するには、月に数回実行するだけで済みます。

-アダム

0
Adam Davis

私は実際に、ログインスクリプトの一部として実行され、その情報を収集して、それをWebサイトのデータベースに公開するプログラムを作成しました。これはあなたが走りたいと思うものでしょうか?古いコードをほこりを払って、必要に応じて渡すことができます。

0
Steven Behnke