VB Search Domain User for File
I am putting together an old post here with this new one. My main goal is to combi开发者_高级运维ne these two portions so that the search does not need to be ran on each and every computer.
'Searching for all computers in the domain
Dim de As New DirectoryEntry()
de.Path = "WinNT://domain.name"
For Each d As DirectoryEntry In de.Children()
Console.WriteLine(d.Name)
Next
I can set the path as WinNT://domain.name/username...and I get a list of something, are they files? i am not sure?
Second portion of code searches the computer for the java.exe to display its version, as well as searching for any indication of a java file on that computer.
'Searching individual computer for Java Information
Dim sdkCommand As String
sdkCommand = "C:\Windows\System32\Java.exe -version 2> C:\Users\Desktop\JavaSDKInfo.txt && C:\Windows\System32\tasklist.exe /FI ""IMAGENAME eq java.exe"" >> C:\Users\Desktop\JavaSDKInfo.txt"
Shell("cmd.exe /c" & sdkCommand)
I am crazy confizzled when it comes to have each domain user run this(or to have me remotely execute it on each machine??). I have been given hints regarding dlls, etc. Any advice regarding how to go about this or what to do would be awesome!
I know its been a while so I will go ahead and list what I did as the answer.
Using replacement in the shell I am able to pull up the list of users that was written using a streamwriter. The command is then performed on each entry in that list.
Sub WriteUserFile()
Dim de As New DirectoryEntry()
de.Path = "WinNT://domain.name"
Using sw as New StreamWriter(File.Open(UserFile, FileMOde.OpenorCreate))
For Each d As DirectoryEntry In de.Children()
sw.WriteLine(d.Name)
Next
End Sub
In order to combine it I then used this next sub and the replacement command to sub in the user names. Push d allowed me to change the directory to each user (pending admin status)
Sub DoWork()
Dim sdkCommand as string = "pushd \\*\C$ && java.exe -version2>> $$$"
For each strUserName as String in strLines
Dim ReplaceCommand as String = sdkCommand.Replace("*", strUserName).Replace("$$$", "C:\InfoReadout.txt")
Shell("cmd.exe /c" & ReplaceCommand, True, -1)
End Sub
精彩评论