Solved

using WScript.shell and "cacls" through vba

Posted on 2011-02-24
3
1,653 Views
Last Modified: 2012-05-11
Hi folks

I'm trying to use VB6 to run the "Cacls" command to get the permissions of a folder. My code is below. Am i missing something?

Public Function getPermissions()     
    Dim stdOut, objScriptExec, strResults, objShell
    Set objShell = CreateObject("WScript.Shell")
    On Error Resume Next
     objShell.exec ("cacls \\PCNAME\FILENAME")
     strResults = LCase(objScriptExec.stdOut.ReadAll)
     Set stdOut = Nothing
     Set objScriptExec = Nothing
     
     MsgBox strResults
End Function

Open in new window

0
Comment
Question by:ITUCIRL
3 Comments
 

Author Comment

by:ITUCIRL
ID: 34971628
Should have mentioned that I have the correct reference set, and when i step through the code, the line
strResults = LCase(objScriptExec.stdOut.ReadAll)

Open in new window

is empty.
0
 
LVL 3

Expert Comment

by:sam0x01
ID: 34972046
Try changing
objShell.exec ("cacls \\PCNAME\FILENAME")

to

objScriptExec=objShell.exec ("cacls \\PCNAME\FILENAME")

not sure if VB can access WScript object, be worth commenting out the On Error Resume Next
 with an apostrophe
0
 
LVL 1

Accepted Solution

by:
MARCOSALVES earned 500 total points
ID: 34972394
Hi!
Try this:

Set objShell = CreateObject("WScript.Shell")
Set objWshScriptExec = objShell.Exec("cacls \\PCNAME\FILENAME")
Set objStdOut = objWshScriptExec.StdOut
strOutput = objStdOut.ReadAll
WScript.Echo strOutput

Must work.
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

In a multiple monitor setup, if you don't want to use AutoCenter to position your popup forms, you have a problem: where will they appear?  Sometimes you may have an additional problem: where the devil did they go?  If you last had a popup form open…
Overview: This article:       (a) explains one principle method to cross-reference invoice items in Quickbooks®       (b) explores the reasons one might need to cross-reference invoice items       (c) provides a sample process for creating a M…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

862 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

22 Experts available now in Live!

Get 1:1 Help Now