Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Scan dir based on pc suffix, find file and run other script 1

Status
Not open for further replies.

19780308

Technical User
Nov 21, 2001
13
0
0
NO
Hi,
I am trying to start in VBS and can't get the hang on one problem - any ideas, please? :)
I need to make a script that gets info of pc suffix and then according to the one found scans for files in specific directory according to different names found.
e.g.
if pc name is pc6-rrr,
scan directory \\uni\pe\be
if pc name is pc7-rrr,
scan directory \\yni\pe\be
Based on file found in directory runs other VBS script
like if you have file
$test$ you run a VBS test.vbs
- After you run VBS you delte the file.
Please help!!!
Cheers,
ML
 
A little more info required!!

Are you running this VBS file on each computer or are you looking at reading Active Directory and locating computer names.

Are you looking at running the second VBs file on a remote computer.


Regards
Steve Friday
 
Hi Steve,

Ideally this would be a vbs file that would read active directory according to pc name it has been run on.
E.G.
If you are running it on pc7-rr,
It scans the active directory for \\yni.st.it.net\files\db\out
and then according to file found in it, runs another vbs that is sitting on the same pc7-rr

If
If you are running it on pc6-rr,
It scans the active directory for \\zni.st.it.net\files\db\out
and then according to file found in it, runs another vbs that is sitting on the same pc6-rr

Would you have any idea, please?
I was going through forum and saw that you have managed to help a lot of others :) Fareplay to you!
/R
 
Hopefully I have grasped what you want, I am presuming you know the name of the file that you are looking for and that the logged on user has rights to get to it.

the code below will identify the computer name and then check for the existence of a specified file, if it exists then it runs test.vbs.

Dim objname, objfso, objwsh
Set objwsh = Wscript.CreateObject("Wscript.Shell")
Set objfso = Wscript.CreateObject("Scripting.FileSystemObject")
strComputer = "."
Set objname = GetObject("winmgmts:{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
Set cname = objname.ExecQuery _
("Select * from Win32_ComputerSystem")
For Each item in cname
If item.Name = "pc7-rr" Then
If objfso.FileExists("\\yni.st.it.net\files\db\out\nameoffile") = True Then
objwsh.run "c:\test.vbs"
End If
End If
If item.Name = "pc6-rr" Then
If objfso.FileExists("\\zni.st.it.net\files\db\out\nameoffile") = True Then
objwsh.run "c:\test.vbs"
End If
End If
Next Regards
Steve Friday
 
This one will enumerate through the files in the folder, you can therefore do multiple checks against files.

If you put in msgbox file.name within the For Each file in Files, you will see the results that are returned.

Dim objname, objfso, objwsh, locfile
Set objwsh = Wscript.CreateObject("Wscript.Shell")
Set objfso = Wscript.CreateObject("Scripting.FileSystemObject")
strComputer = "."
Set objname = GetObject("winmgmts:{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
Set cname = objname.ExecQuery _
("Select * from Win32_ComputerSystem")
For Each item in cname
If item.Name = "pc7-rr" Then
Set locfile = objfso.GetFolder("\\yni.st.it.net\files\db\out\")
Set files = locfile.Files
For Each file in Files
If file.name = "test.txt Then
wsh.run "C:\test.vbs"
End If
next
End If
If item.Name = "pc6-rr" Then
Set locfile = objfso.GetFolder("\\zni.st.it.net\files\db\out\")
Set files = locfile.Files
For Each file in Files
If file.name = "test22.txt Then
wsh.run "C:\test.vbs"
End If
next
End If
Next

hope it helps Regards
Steve Friday
 
Thanks a lot for this :)
A star from me - your blood is worth a bottle!
I still did not get exactly what
Set objname = GetObject("winmgmts:{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
Set cname = objname.ExecQuery _
("Select * from Win32_ComputerSystem")

is used for.
Thanks a lot!
Martins
 
I am presuming that you do not know the name of the computer, therefor this process will go and retrieve the name, you can therefor check which machine you are running the VBS file on, when it retrieves it, it is exposed by the line For Each item in cname, therefor item.name becomes the name of the computer pc7-rr or whatever. Regards
Steve Friday
 
Yes, I don't know what machine is it gonna be so this is exactly what I needed - I just was not sure about what it was.
I had a tip to always use deactivation at the end of process - Set ob = Nothing - would you? Heard that otherwise it grabs resources until terminater.
Also to use CASE instead of IF.
Thanks a lot for your help!
Best Regards,
Martins
 
Yes it probably is a good idea to to set them to Nothing at the end, and Case can be used instead of IF, Case is usually used to avoid complex nesting of IF statements.

Regards
Steve Friday
 
Thanks a lot man!
Very much appreciated!
/R
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top