Solved

using WScript.shell and "cacls" through vba

Posted on 2011-02-24
3
1,647 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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

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…
I see at least one EE question a week that pertains to using temporary tables in MS Access.  But surprisingly, I was unable to find a single article devoted solely to this topic. I don’t intend to describe all of the uses of temporary tables in t…
Familiarize people with the process of retrieving data from SQL Server using an Access pass-thru query. Microsoft Access is a very powerful client/server development tool. One of the ways that you can retrieve data from a SQL Server is by using a pa…
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

762 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

19 Experts available now in Live!

Get 1:1 Help Now