Results 1 to 5 of 5

Thread: After create Install my software can't create files in Program Files folder ?

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Jan 2014
    Posts
    117

    After create Install my software can't create files in Program Files folder ?

    I create Setup for my app with InstallCreator, and when my software is installed all files be copied in C:ProgramFiles/MySoftware
    For create, delete or copy any file or folder in ProgramFiles system need administrator permission (click on button "Continue")

    My software need to create .txt files in folder but always if user click on button to create files I get this error from windows:

    HTML Code:
    Unhandled exception has occurred in your application. If you click Continue, the application will ignore this error and attempt to contionu. If you click Quit, the application will close immediately. 
    Access to the path C:/Program Files/MySoftware/file.txt' is denied
    What should I do?
    Sorry for bad English.
    Thanks a lot.

  2. #2
    Hyperactive Member Frabulator's Avatar
    Join Date
    Jan 2015
    Location
    USA
    Posts
    393

    Re: After create Install my software can't create files in Program Files folder ?

    My workaround for this was to create a folder in the 'My Documents' of the user account and save all editing files in there. The thing is that on windows vista and on you need administrative permission in order to edit or change any documents in the program files folder.

    For example, this code will open an excel doc in the 'My Documents' location.

    Code:
    
                Dim xlAppP As Microsoft.Office.Interop.Excel.Application
                Dim xlWorkBookP As Microsoft.Office.Interop.Excel.Workbook
                Dim xlWorkSheetP As Microsoft.Office.Interop.Excel.Worksheet
                Dim excelType As Type = System.Type.GetTypeFromProgID("Excel.Application")
    
    
                xlAppP = CType(System.Activator.CreateInstance(excelType), Microsoft.Office.Interop.Excel.Application)
                xlAppP.Application.DisplayAlerts = False
    
                xlWorkBookP = xlAppP.Workbooks.Open("" + My.Computer.FileSystem.SpecialDirectories.MyDocuments + "\FOLDER1\FOLDER 2\ExcelDoc.xlsx", Notify:=False) 
                xlWorkSheetP = CType(xlWorkBookP.Worksheets(1), Microsoft.Office.Interop.Excel.Worksheet)
    
    
                xlAppP.Visible = False
    
                Dim xlapprange As Microsoft.Office.Interop.Excel.Range = xlWorkSheetP.Range("D2")
                Dim valueofappprange As String = CStr(xlapprange.Value)
    
                TextBox19.Text = valueofappprange
                ReleaseCOM(xlapprange)
                releaseObject(xlapprange)
    You can use this and modify it in order to create a folder, file, or copy and paste your files from your Programs folder into the My Documents. Since the Programs folder can not be edited I use them as an untouched 'original' of the document and then when needed, copy that original into the My Documents location and edit that file.

    I hope that helps

    Frab~

    ---____--- EDIT ----____----

    I also have found that this program, Inno Setup Compiler, has a much easier installer than on Visual Studio. Save your program as an EXE and then use the Inno to setup the files and folders to go inside the Program Files.

    Inno Setup Compiler
    Last edited by Frabulator; May 27th, 2015 at 10:45 AM.
    Oops, There it goes. Yep... my brain stopped...
    _________________________________

    Useful Things:

    How to link your VB.Net application to Excel

  3. #3

    Thread Starter
    Lively Member
    Join Date
    Jan 2014
    Posts
    117

    Re: After create Install my software can't create files in Program Files folder ?

    Thanks for answer and help but I must save my files in app folder.
    If I run my software as administrator then all works fine, I try to change in my software to run administrator.
    When I try to open "View window setting" and I get error:

    The parameter is incorrect.(Exception from HRESULT: 0x80070057 (E_INVALIDARG))



    Thanks

  4. #4
    Bad man! ident's Avatar
    Join Date
    Mar 2009
    Location
    Cambridge
    Posts
    5,398

    Re: After create Install my software can't create files in Program Files folder ?

    You should not be writing to program files. Thats where applications live. Not Data. Application Data is created for such reasons.

  5. #5
    eXtreme Programmer .paul.'s Avatar
    Join Date
    May 2007
    Location
    Chelmsford UK
    Posts
    25,479

    Re: After create Install my software can't create files in Program Files folder ?

    As ident said Program Files is for your Program's exe and any DLL files, etc.
    Any documents your app writes should be written in a folder in your Documents folder which is intended for that purpose and doesn't have restricted write access.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width