Go Back  Xtreme Visual Basic Talk > Legacy Visual Basic (VB 4/5/6) > API > Set Folder Permissions


Reply
 
Thread Tools Display Modes
  #1  
Old 04-22-2012, 08:23 AM
Code A's Avatar
Code A Code A is offline
Junior Contributor
 
Join Date: Jul 2002
Location: Area 51 A
Posts: 366
Default Set Folder Permissions


I need my VB6 app to modify the permissions of the root folder (most likely Program Files (x86)) on Windows 7 to full control for the current user. I seem to be able to accomplish this using the code below when running the source inside the VB6 environment, however when I package it up and install it on the system it doesn't seem to work. Any ideas why this happening?

Modify User Permissions on App Load
Code:
SetUserPermissions
Function to Modify the User Permissions
Code:
Private Function SetUserPermissions()

Dim strHomeFolder, strHome, strUser
Dim intRunError, objShell, objFSO
    
strHomeFolder = App.Path
strUser = CurrentUser
    
Set objShell = CreateObject("Wscript.Shell")
Set objFSO = CreateObject("Scripting.FileSystemObject")
    
If objFSO.FolderExists(strHomeFolder) Then
    intRunError = objShell.Run("%COMSPEC% /c Echo Y| cacls """ & strHomeFolder & """ /e /c /g " & strUser & ":F ", 2, True)
    'Wscript.Echo "The File " & strHomeFolder & ". Permissions changed to Every One."
    
    If intRunError <> 0 Then
        MsgBox "Error assigning permissions for user " & strUser & " to " & strHomeFolder, vbCritical + vbOKOnly, "User Permissions"
    End If
End If


End Function
Function to Get Current User
Code:
Public Function CurrentUser() As String
    Dim strBuff As String * 255
    Dim X As Long
    CurrentUser = ""
    X = GetUserName(strBuff, Len(strBuff) - 1)
    If X > 0 Then
        'Look for Null Character, usually included
        X = InStr(strBuff, vbNullChar)
        'Trim off buffered spaces too
        If X > 0 Then
            CurrentUser = UCase(Left$(strBuff, X - 1)) 'UCase is optional ;)
        Else
            CurrentUser = UCase(Left$(strBuff, X))
        End If
    End If
End Function
__________________
www.kptechnologies.com
Reply With Quote
  #2  
Old 04-22-2012, 08:37 AM
PlausiblyDamp's Avatar
PlausiblyDamp PlausiblyDamp is offline
Ultimate Contributor

Forum Leader
* Expert *
 
Join Date: Nov 2003
Location: Wigan, UK
Posts: 1,692
Default

I imagine the application would need to be run with elevated permissions to work, however I would really question the reason you are attempting this.

Windows has deliberately restrictive permissions on the Programs folder for several very good reasons, any application that attempts to change these should have a very, very good reason to do so.
__________________
Intellectuals solve problems; geniuses prevent them.
-- Albert Einstein

Posting Guidelines Forum Rules Use the code tags
Reply With Quote
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Forum Jump

Advertisement:





Free Publications
The ASP.NET 2.0 Anthology
101 Essential Tips, Tricks & Hacks - Free 156 Page Preview. Learn the most practical features and best approaches for ASP.NET.
subscribe
Programmers Heaven C# School Book -Free 338 Page eBook
The Programmers Heaven C# School book covers the .NET framework and the C# language.
subscribe
Build Your Own ASP.NET 3.5 Web Site Using C# & VB, 3rd Edition - Free 219 Page Preview!
This comprehensive step-by-step guide will help get your database-driven ASP.NET web site up and running in no time..
subscribe
 
 
-->