Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

using WScript.shell and "cacls" through vba

Posted on 2011-02-24
3
Medium Priority
?
1,704 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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 2000 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

Nothing ever in the clear!

This technical paper will help you implement VMware’s VM encryption as well as implement Veeam encryption which together will achieve the nothing ever in the clear goal. If a bad guy steals VMs, backups or traffic they get nothing.

Question has a verified solution.

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

Microsoft Access is a place to store data within tables and represent this stored data using multiple database objects such as in form of macros, forms, reports, etc. After a MS Access database is created there is need to improve the performance and…
We live in a world of interfaces like the one in the title picture. VBA also allows to use interfaces which offers a lot of possibilities. This article describes how to use interfaces in VBA and how to work around their bugs.
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …
Suggested Courses

721 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