Photo Gallery Member List Search Calendars FAQ Ticket List Log Out


Help needed

 
Logged in as: Guest
arrSession:exec spGetSession 2,2,42976
 Active Users: There are 0 members and 0 guests.
 Users viewing this topic: none
 

 

 
  
  Printable Version
All Forums >> [Scripting] >> WSH & Client Side VBScript >> Help needed
  Do you like VisualBasicScript.com? Link to us and help spread the word about our forum. Thanks!
Page: [1]
Login
Message << Older Topic   Newer Topic >>
 Help needed - 2/7/2007 9:28:11 AM   
  h1t3ch


Posts: 20
Score: 0
Joined: 1/21/2007
From: Nashville, TN.
Status: offline
I have this script below that basically searches remote computer for a specific folder, I am wanting to add the username of that computer also. I am having problems pulling that info with this script, can someone take a look and see what I am doing
wrong? Thanks

On error resume Next
Dim objConnection,objCommand,objRootLDAP,strDNSDomain
Const ADS_SCOPE_SUBTREE = 2

Set objConnection = CreateObject("ADODB.Connection")
Set objCommand =   CreateObject("ADODB.Command")
Set objRootLDAP = GetObject("LDAP://RootDSE")

strDNSDomain = objRootLDAP.Get("DefaultNamingContext")
Wscript.Echo "Searching " & strDNSDomain

objConnection.Provider = "ADsDSOObject"
objConnection.Open "Active Directory Provider"
objConnection.Cursorlocation=3

Set objCommand.ActiveConnection = objConnection
objCommand.CommandText = "<LDAP://" & strDNSDomain & ">;(objectCategory=computer); name ;subtree"

objCommand.Properties("Page Size") = 1000
objCommand.Properties("Searchscope") = ADS_SCOPE_SUBTREE

Set objRecordSet = objCommand.Execute
objRecordSet.Sort = "name"
objRecordSet.MoveFirst

Do Until objRecordSet.Eof
strComputer = objRecordSet.Fields("name")
WScript.Echo strComputer

strUserName = objItem.UserName
WScript.Echo "User Name: " & strUserName

Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")

Set objWMIService = GetObject("winmgmts:\\" & strUserName & "\root\cimv2")

Set colFolders = objWMIService.ExecQuery _
("Select * from Win32_Directory where Name = 'c:\\Winpoint'")

If colFolders.Count = 0 Then
    WScript.Echo "Folder does not exist!"
Else
    WScript.Echo "Folder Exists!"
End If

objRecordSet.Movenext
Loop
objRecordSet.close
objConnection.close
 
 
Post #: 1
 
 RE: Help needed - 2/7/2007 9:53:56 AM   
  dm_4ever


Posts: 2726
Score: 46
Joined: 6/29/2006
From: Orange County, California
Status: offline
You don't need this line: Set objWMIService = GetObject("winmgmts:\\" & strUserName & "\root\cimv2")
If you want the username of the person using the computer you're querying then you need to query another class to get this information.  You can try querying Win32_ComputerSystem and the UserName property or like I saw one of the members here do in another script (which you may want to search for) is to query Win32_Process for the explorer.exe instance and get the owner of it.

_____________________________

dm_4ever

My philosophy: K.I.S.S - Keep It Simple Stupid
Read Me: http://www.visualbasicscript.com/m_24727/tm.htm
Frequently Asked Stuff: http://www.visualbasicscript.com/m_47117/tm.htm

(in reply to h1t3ch)
 
 
Post #: 2
 
 RE: Help needed - 2/7/2007 9:59:17 AM   
  dm_4ever


Posts: 2726
Score: 46
Joined: 6/29/2006
From: Orange County, California
Status: offline
Something like this


      

OR


      

_____________________________

dm_4ever

My philosophy: K.I.S.S - Keep It Simple Stupid
Read Me: http://www.visualbasicscript.com/m_24727/tm.htm
Frequently Asked Stuff: http://www.visualbasicscript.com/m_47117/tm.htm

(in reply to dm_4ever)
 
 
Post #: 3
 
 RE: Help needed - 2/8/2007 12:00:51 AM   
  h1t3ch


Posts: 20
Score: 0
Joined: 1/21/2007
From: Nashville, TN.
Status: offline
Thanks for your reply....

(in reply to dm_4ever)
 
 
Post #: 4
 
 RE: Help needed - 2/8/2007 12:12:54 AM   
  gdewrance


Posts: 587
Score: 3
Joined: 3/16/2006
Status: offline
That script your using (http://www.visualbasicscript.com/m_42275/mpage_1/key_/tm.htm#42613)
was formed from a template that ginolard provided here.
Hope this helps

http://www.visualbasicscript.com/m_40609/mpage_1/key_/tm.htm#40609

(in reply to h1t3ch)
 
 
Post #: 5
 
 RE: Help needed - 2/8/2007 1:23:03 AM   
  h1t3ch


Posts: 20
Score: 0
Joined: 1/21/2007
From: Nashville, TN.
Status: offline
Sweet, the code works but can someone tell me why it is pulling the administrator logon instead of the username and why some usernames aren't listed?


      
Here is my code..

      

(in reply to gdewrance)
 
 
Post #: 6
 
 RE: Help needed - 2/8/2007 1:36:09 AM   
  gdewrance


Posts: 587
Score: 3
Joined: 3/16/2006
Status: offline
You are quering Active Directory for a List of all computers then checking if they have a folder called C:\whatever.

Maybe try a different root of reading a list of computers into the script, pinging them and getting the username.

< Message edited by gdewrance -- 2/8/2007 5:05:37 PM >

(in reply to h1t3ch)
 
 
Post #: 7
 
 
 
  

If you found our site useful please link to us <a href="http://www.visualbasicscript.com">VisualBasicScript.com</a>.
All Forums >> [Scripting] >> WSH & Client Side VBScript >> Help needed Page: [1]
Jump to:





New Messages No New Messages
Hot Topic w/ New Messages Hot Topic w/o New Messages
Locked w/ New Messages Locked w/o New Messages
 Post New Thread
 Reply to Message
 Post New Poll
 Submit Vote
 Delete My Own Post
 Delete My Own Thread
 Rate Posts