Photo Gallery Member List Search Calendars FAQ Ticket List Log Out


Need your help!! Its urgent

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

 

 
  
  Printable Version
All Forums >> [Scripting] >> WSH & Client Side VBScript >> Need your help!! Its urgent
  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 >>
 Need your help!! Its urgent - 7/31/2007 4:52:00 PM   
  swapnil

 

Posts: 3
Score: 0
Joined: 7/31/2007
Status: offline
Hi Friends,
               I am new here and to VB script too. I am working on a VB script and getting stuck. I have to write a script wich will display and log the owner and the group to which it belongs, for the each folder when a path is provided to the script. Here is a script I have written ,

strFileName = wscript.arguments(0)
Set objWMIService = GetObject("winmgmts:")
Set objFileSecuritySettings = _
objWMIService.Get("Win32_LogicalFileSecuritySetting='" & strFileName & "'")
intRetVal = objFileSecuritySettings.GetSecurityDescriptor(objSD)
If intRetVal = 0 Then
  WScript.Echo "Owner: " & objSD.Owner.Domain & "\" & objSD.Owner.Name
Else
  WScript.Echo "Couldn't retrieve security descriptor."
End If

Its working fine when run through command line with file path provided. But I want to modify it to accept user input as path(folder location) and then display its owner for every folder residing at that path.
So please help me with this

thanks in advance.
 
 
Post #: 1
 
 RE: Need your help!! Its urgent - 7/31/2007 7:29:33 PM   
  ginolard


Posts: 1082
Score: 21
Joined: 8/10/2005
Status: offline
Then you are going to be wanting to do recursion.

For this you'll need the FSO object and the GetFolders method.  That returns a collection which you can then iterate through.

You'll need to put your code that gets the owner into a Sub which you will call and pass it the folder name as

Here's some simple code that demonstrates how to iterate subfolders.  This won't do recursion (i.e. going more than one subfolder down).  I'll let you figure that one out ;)


      


_____________________________

Author of ManagePC - http://managepc.net
AD Query Template - http://www.visualbasicscript.com/m_40609/tm.htm
Consolidated Scripting Framework - http://www.visualbasicscript.com/m_59109/tm.htm

(in reply to swapnil)
 
 
Post #: 2
 
 RE: Need your help!! Its urgent - 7/31/2007 11:01:10 PM   
  swapnil

 

Posts: 3
Score: 0
Joined: 7/31/2007
Status: offline
Thanks Ginolard,
But as I mentioned before, I need to process user input in the VB script. In the solution provided by you, you have mentioned folder path as "C:\temp". But I want to get that value from user. I have tried like this
objWMIService.ExecQuery("Select * From Win32_Directory Where Drive = 'C:' and path =
But I want to remove the dependency on Drive i.e. I want my script to work  on  value provided for folder path as "C:\HI" by user.
I have tried that but its giving error. Actually I want to run this script on share. So hopefully waiting for your suggestions/guidelines for this problem also.

Thanks




(in reply to ginolard)
 
 
Post #: 3
 
 RE: Need your help!! Its urgent - 7/31/2007 11:22:17 PM   
  ginolard


Posts: 1082
Score: 21
Joined: 8/10/2005
Status: offline
Then use InputBox

strPath = InputBox ("Please enter a path to be checked")

_____________________________

Author of ManagePC - http://managepc.net
AD Query Template - http://www.visualbasicscript.com/m_40609/tm.htm
Consolidated Scripting Framework - http://www.visualbasicscript.com/m_59109/tm.htm

(in reply to swapnil)
 
 
Post #: 4
 
 RE: Need your help!! Its urgent - 7/31/2007 11:57:23 PM   
  swapnil

 

Posts: 3
Score: 0
Joined: 7/31/2007
Status: offline
I have done that already. What I want to know is how can I process that input in a query. Please have a look at the following script. This will make it clear
strComputer = "."
strFolderPath = InputBox("Enter Folder path:")
Dim objFSO
Set objFSO = CreateObject("Scripting.FileSystemObject")
Dim oOutPut
Set oOutPut = objFSO.CreateTextFile("C:\log.txt")

Set objWMIService = GetObject("winmgmts:")
   '& "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
Set colFolders = _
   objWMIService.ExecQuery("Select * From Win32_Directory Where path = '\\strFolderPath\\'")'Drive = 'C:' and path = '\\HI\\'")
WScript.Echo colFolders.count
For Each objFolder in colFolders
   WScript.Echo objFolder.name
   'WScript.Echo objFolder.Count
   'WScript.Echo objFolder.owner
   'Set objWMIService = GetObject("winmgmts:")
   Set objFileSecuritySetting=_
   objWMIService.get("Win32_LogicalFileSecuritySetting='" & objFolder.name &"'")
   intRetVal = objFileSecuritySetting.GetSecurityDescriptor(objSD)
If intRetVal = 0 Then
  WScript.Echo "Owner: " & objSD.Owner.Domain & "\" & objSD.Owner.Name
Else
  WScript.Echo "Couldn't retrieve security descriptor."
End If
oOutPut.WriteLine ("Folder Name:")& objFolder.name
oOutPut.WriteLine ("Owner:")& objSD.Owner.Domain
Next

Now suppose user enters value in Box as "C:\HI", then I want to display as well as log the owner of the folder in the text file. But I am getting error in the query. So I want to know how to process that value in a query so that it would be independent of drive parameter. One more thing. I want to run this script on share also. Like, if m running script on \\myshare\myfolders, and user inputs value as \\myshare\myfolders\  then I want my script to display owner of all the folders residing at previously mentioned location. So I need your help to run my script on both local machine and share.

Thanks in advance.

(in reply to ginolard)
 
 
Post #: 5
 
 RE: Need your help!! Its urgent - 8/1/2007 12:35:51 AM   
  ginolard


Posts: 1082
Score: 21
Joined: 8/10/2005
Status: offline
Then you are going to have to some parsing of the input.

This will work for local paths but you'll need to find out how to parse UNC paths.  I'm not sure Win32_Directory can handle UNC paths though I might be wrong.


      

_____________________________

Author of ManagePC - http://managepc.net
AD Query Template - http://www.visualbasicscript.com/m_40609/tm.htm
Consolidated Scripting Framework - http://www.visualbasicscript.com/m_59109/tm.htm

(in reply to swapnil)
 
 
Post #: 6
 
 
 
  

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 >> Need your help!! Its urgent 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