![]() |
![]() | ![]() | ![]() | ![]() | ![]() | ![]() | ![]() |
| Welcome to Windows Vista Forums. Our forum is dedicated to helping you find solutions with any problems, errors or issues you are experiencing with Windows Vista. The Vista forum also covers news and updates and has an extensive Windows Vista tutorial section that covers a wide range of tips and tricks. |
| |||||||
![]() |
| |
| | #1 (permalink) |
| | StdOut.ReadAll() in VBScript I am writing a script to read user names from a txt file then run the calcs command on their application data folder in their home dir to check their permissions. If they dont have them set correctly, I take ownership, removed whatever rights they have on the home dir and reapply. It works fine with reading the txt file and running the last three commands for reapplying rights, but when I added to read the output from the initial cacls command, I get an error. Object Required: '2' on line... strText = cmdCacls.StdOut.ReadAll() I can even add oFiletxt.WriteLine(cmdCacls) to test and the output is 2. Here is the complete code. Thanks! ------------------------------- Dim cmdCacls Set objFSO = CreateObject("Scripting.FileSystemObject") Set objTextFile = objFSO.OpenTextFile("C:\users.txt") Set oFiletxt = objFSO.CreateTextFile("C:\results.txt") Set objShell = CreateObject("Wscript.Shell") Do Until objTextFile.AtEndOfStream strUserLine = objTextFile.Readline strHomeFolder = "<main user share>" & strUserLine cmdCacls = objShell.Run("%COMSPEC% /c Echo Y| cacls " & strHomeFolder & "\applic~1", 0, True) strText = cmdCacls.StdOut.ReadAll() If Instr(strText, strUserLine) > 0 Then cmdOwn = objShell.Run("%COMSPEC% /c Echo Y| takeown /f " & strHomeFolder & " /r /a", 0, True) cmdTake = objShell.Run("%COMSPEC% /c Echo Y| cacls " & strHomeFolder & " /t /e /c /r <domain>\" & strUserLine, 0, True) cmdPerm = objShell.Run("%COMSPEC% /c Echo Y| cacls " & strHomeFolder & " /t /e /c /g <domain>\" & strUserLine & ":F ", 0, True) oFiletxt.WriteLine("Done for user " & strUserLine) Else oFiletxt.WriteLine("Error assigning permissions to user " & strUserLine & " on " & strHomeFolder) End If Loop |
My System Specs![]() |
| | #2 (permalink) |
| | Re: StdOut.ReadAll() in VBScript tpreitano@xxxxxx schrieb: Quote: > I am writing a script to read user names from a txt file then run the > calcs command on their application data folder in their home dir to > check their permissions. If they dont have them set correctly, I take > ownership, removed whatever rights they have on the home dir and > reapply. > > It works fine with reading the txt file and running the last three > commands for reapplying rights, but when I added to read the output > from the initial cacls command, I get an error. Object Required: '2' > on line... strText = cmdCacls.StdOut.ReadAll() > > I can even add oFiletxt.WriteLine(cmdCacls) to test and the output is > 2. > > Here is the complete code. Thanks! > ------------------------------- > > Dim cmdCacls > > Set objFSO = CreateObject("Scripting.FileSystemObject") > Set objTextFile = objFSO.OpenTextFile("C:\users.txt") > Set oFiletxt = objFSO.CreateTextFile("C:\results.txt") > Set objShell = CreateObject("Wscript.Shell") > > Do Until objTextFile.AtEndOfStream > strUserLine = objTextFile.Readline > strHomeFolder = "<main user share>" & strUserLine > > cmdCacls = objShell.Run("%COMSPEC% /c Echo Y| cacls " & strHomeFolder > & "\applic~1", 0, True) Probably you meant to call .Exec: Set cmdCacls = objShell.Exec( _ "%COMSPEC% /c Echo Y| cacls " & strHomeFolder & "\applic~1" ) Quote: > strText = cmdCacls.StdOut.ReadAll() > If Instr(strText, strUserLine) > 0 Then > > cmdOwn = objShell.Run("%COMSPEC% /c Echo Y| takeown /f " & > strHomeFolder & " /r /a", 0, True) > cmdTake = objShell.Run("%COMSPEC% /c Echo Y| cacls " & strHomeFolder > & " /t /e /c /r <domain>\" & strUserLine, 0, True) > cmdPerm = objShell.Run("%COMSPEC% /c Echo Y| cacls " & strHomeFolder > & " /t /e /c /g <domain>\" & strUserLine & ":F ", 0, True) > oFiletxt.WriteLine("Done for user " & strUserLine) > Else > > oFiletxt.WriteLine("Error assigning permissions to user " & > strUserLine & " on " & strHomeFolder) > > End If > > Loop |
My System Specs![]() |
| | #3 (permalink) |
| | Re: StdOut.ReadAll() in VBScript <tpreitano@xxxxxx> wrote in message news:4191b193-50db-495b-9e14-f49268b19acf@xxxxxx Quote: >I am writing a script to read user names from a txt file then run the > calcs command on their application data folder in their home dir to > check their permissions. If they dont have them set correctly, I take > ownership, removed whatever rights they have on the home dir and > reapply. > > It works fine with reading the txt file and running the last three > commands for reapplying rights, but when I added to read the output > from the initial cacls command, I get an error. Object Required: '2' > on line... strText = cmdCacls.StdOut.ReadAll() > > I can even add oFiletxt.WriteLine(cmdCacls) to test and the output is > 2. > > Here is the complete code. Thanks! > ------------------------------- > > Dim cmdCacls > > Set objFSO = CreateObject("Scripting.FileSystemObject") > Set objTextFile = objFSO.OpenTextFile("C:\users.txt") > Set oFiletxt = objFSO.CreateTextFile("C:\results.txt") > Set objShell = CreateObject("Wscript.Shell") > > Do Until objTextFile.AtEndOfStream > strUserLine = objTextFile.Readline > strHomeFolder = "<main user share>" & strUserLine > > cmdCacls = objShell.Run("%COMSPEC% /c Echo Y| cacls " & strHomeFolder > & "\applic~1", 0, True) > strText = cmdCacls.StdOut.ReadAll() > If Instr(strText, strUserLine) > 0 Then > > cmdOwn = objShell.Run("%COMSPEC% /c Echo Y| takeown /f " & > strHomeFolder & " /r /a", 0, True) > cmdTake = objShell.Run("%COMSPEC% /c Echo Y| cacls " & strHomeFolder > & " /t /e /c /r <domain>\" & strUserLine, 0, True) > cmdPerm = objShell.Run("%COMSPEC% /c Echo Y| cacls " & strHomeFolder > & " /t /e /c /g <domain>\" & strUserLine & ":F ", 0, True) > oFiletxt.WriteLine("Done for user " & strUserLine) > Else > > oFiletxt.WriteLine("Error assigning permissions to user " & > strUserLine & " on " & strHomeFolder) > > End If > > Loop ======== Set objCacls = objShell.Exec("<your command.") Do Until objCacls.StdOut.AtEndOfStream strText = objCalcs.StdOut.ReadAll() Loop ========== The main thing is to use the Exec method rather than the Run method and use a Set statement to create the object reference. Note this requires WSH 5.6. Since you use ReadAll(), perhaps the Do Until Loop is not necessary. -- Richard Mueller MVP Directory Services Hilltop Lab - http://www.rlmueller.net -- |
My System Specs![]() |
| | #4 (permalink) |
| | Re: StdOut.ReadAll() in VBScript <tpreitano@xxxxxx> wrote in message news:4191b193-50db-495b-9e14-f49268b19acf@xxxxxx Quote: >I am writing a script to read user names from a txt file then run the > calcs command on their application data folder in their home dir to > check their permissions. If they dont have them set correctly, I take > ownership, removed whatever rights they have on the home dir and > reapply. > > It works fine with reading the txt file and running the last three > commands for reapplying rights, but when I added to read the output > from the initial cacls command, I get an error. Object Required: '2' > on line... strText = cmdCacls.StdOut.ReadAll() > > I can even add oFiletxt.WriteLine(cmdCacls) to test and the output is > 2. > > Here is the complete code. Thanks! > ------------------------------- > > Dim cmdCacls > > Set objFSO = CreateObject("Scripting.FileSystemObject") > Set objTextFile = objFSO.OpenTextFile("C:\users.txt") > Set oFiletxt = objFSO.CreateTextFile("C:\results.txt") > Set objShell = CreateObject("Wscript.Shell") > > Do Until objTextFile.AtEndOfStream > strUserLine = objTextFile.Readline > strHomeFolder = "<main user share>" & strUserLine > > cmdCacls = objShell.Run("%COMSPEC% /c Echo Y| cacls " & strHomeFolder > & "\applic~1", 0, True) > strText = cmdCacls.StdOut.ReadAll() > If Instr(strText, strUserLine) > 0 Then > > cmdOwn = objShell.Run("%COMSPEC% /c Echo Y| takeown /f " & > strHomeFolder & " /r /a", 0, True) > cmdTake = objShell.Run("%COMSPEC% /c Echo Y| cacls " & strHomeFolder > & " /t /e /c /r <domain>\" & strUserLine, 0, True) > cmdPerm = objShell.Run("%COMSPEC% /c Echo Y| cacls " & strHomeFolder > & " /t /e /c /g <domain>\" & strUserLine & ":F ", 0, True) > oFiletxt.WriteLine("Done for user " & strUserLine) > Else > > oFiletxt.WriteLine("Error assigning permissions to user " & > strUserLine & " on " & strHomeFolder) > > End If > > Loop [cmdCacls = objShell.Run("%COMSPEC% /c Echo Y| . . .] cmdCacls is not an object, yet a little further down you try to use it as an object: strText = cmdCacls.StdOut.ReadAll() Try this instead: Set cmdCacls = objShell.Exec("%COMSPEC% /c Echo Y| . . . strText = cmdCacls.StdOut.ReadAll() From an overall point of view I note that you're executing these four commands: - cacls.exe - takeown.exe - cacls.exe - cacls.exe Instead of repeatedly shelling out to a Command Line environment, you could simplify the task by running the whole job in that environment, e.g. like so: @echo off set UserNames=c:\Users.txt set Results=c:\Results.txt echo Job run on %date% at %time% > %Results% for %%a in (%UserNames%) do ( cacls \\server\shares\%%a | find /i "%%a" if %ErrorLevel% EQU 0 ( takeown.exe /.. cacls /.. cacls /.. echo Done for User %%a ) ) IMHO, scripts that run wholly in one or the other environment are simpler to code and more robust than hybrid scripts. |
My System Specs![]() |
| | #5 (permalink) |
| | Re: StdOut.ReadAll() in VBScript On Feb 25, 4:51*pm, "Pegasus \(MVP\)" <I....@xxxxxx> wrote: Quote: > <tpreit...@xxxxxx> wrote in message > > news:4191b193-50db-495b-9e14-f49268b19acf@xxxxxx > > > > > Quote: > >I am writing a script to read user names from a txt file then run the > > calcs command on their application data folder in their home dir to > > check their permissions. If they dont have them set correctly, I take > > ownership, removed whatever rights they have on the home dir and > > reapply. Quote: > > It works fine with reading the txt file and running the last three > > commands for reapplying rights, but when I added to read the output > > from the initial cacls command, I get an error. Object Required: '2' > > on line... * * *strText = cmdCacls.StdOut.ReadAll() Quote: > > I can even add oFiletxt.WriteLine(cmdCacls) to test and the output is > > 2. Quote: > > Here is the complete code. Thanks! > > ------------------------------- Quote: > > Dim cmdCacls Quote: > > Set objFSO = CreateObject("Scripting.FileSystemObject") > > Set objTextFile = objFSO.OpenTextFile("C:\users.txt") > > Set oFiletxt = objFSO.CreateTextFile("C:\results.txt") > > Set objShell = CreateObject("Wscript.Shell") Quote: > > Do Until objTextFile.AtEndOfStream > > * *strUserLine = objTextFile.Readline > > * *strHomeFolder = "<main user share>" & strUserLine Quote: > > cmdCacls = objShell.Run("%COMSPEC% /c Echo Y| cacls " & strHomeFolder > > & "\applic~1", 0, True) > > strText = cmdCacls.StdOut.ReadAll() > > * *If Instr(strText, strUserLine) > 0 Then Quote: > > cmdOwn = objShell.Run("%COMSPEC% /c Echo Y| takeown /f " & > > strHomeFolder & " /r /a", 0, True) > > cmdTake = objShell.Run("%COMSPEC% /c Echo Y| cacls " & strHomeFolder > > & " /t /e /c /r <domain>\" & strUserLine, 0, True) > > cmdPerm = objShell.Run("%COMSPEC% /c Echo Y| cacls " & strHomeFolder > > & " /t /e /c /g <domain>\" & strUserLine & ":F ", 0, True) > > oFiletxt.WriteLine("Done for user " & strUserLine) > > Else Quote: > > oFiletxt.WriteLine("Error assigning permissions to user " & > > strUserLine & " on " & strHomeFolder) Quote: > > End If Quote: > > Loop > In your code > [cmdCacls = objShell.Run("%COMSPEC% /c Echo Y| *. . .] > cmdCacls is not an object, yet a little further down you try to use it > as an object: > strText = cmdCacls.StdOut.ReadAll() > > Try this instead: > Set cmdCacls = objShell.Exec("%COMSPEC% /c Echo Y| *. . . > strText = cmdCacls.StdOut.ReadAll() > > From an overall point of view I note that you're executing these four > commands: > - cacls.exe > - takeown.exe > - cacls.exe > - cacls.exe > > Instead of repeatedly shelling out to a Command Line environment, you could > simplify the task by running the whole job in that environment, e.g. like > so: > @echo off > set UserNames=c:\Users.txt > set Results=c:\Results.txt > echo Job run on %date% at %time% > %Results% > for %%a in (%UserNames%) do ( > * cacls \\server\shares\%%a | find /i "%%a" > * if %ErrorLevel% EQU 0 ( > * * *takeown.exe /.. > * * *cacls /.. > * * *cacls /.. > * * *echo Done for User %%a > * ) > ) > IMHO, scripts that run wholly in one or the other environment are simplerto > code and more robust than hybrid scripts.- Hide quoted text - > > - Show quoted text - to take out ,0 , True) That is when I gave up. I should have read the error closer. Seeing your responses and the error, I realized, wow... it's usually the little things. Also, thanks for the advice also pegasus |
My System Specs![]() |
![]() |
| Thread Tools | |
| |
Similar Threads | ||||
| Thread | Forum | |||
| redirecting stdin and stdout | PowerShell | |||
| StdOut.ReadAll blocking? | VB Script | |||
| redirect powershell stdout to objShell.Exec.Stdout.ReadAll()( | PowerShell | |||
| stdout redirection | PowerShell | |||
| Using convertto-html with stdout | PowerShell | |||