Results 1 to 12 of 12

Thread: can't write to network path ini file

  1. #1

    Thread Starter
    New Member
    Join Date
    Sep 2022
    Posts
    4

    Angry can't write to network path ini file

    hello im trying to make a prog dat wil use a network drive on de drive is a ini file that has to be updated bij every user.

    i have a network folder maped to m:\ or \\media-pc\media both way's to acces.

    i have granted only user 'EVERYONE' full access

    my local file has the network path and contains:

    Code:
    [General]
    Name=Media Center
    Vers=3.1
    WorkPath=M:\
    WorkDir=MEDIA
    my vb6 project uses for ini the following:

    Code:
    Option Explicit
    'program parameters
    Public AppName As String            'Program name
    Public AppVer As String             'Program version
    Public WorkPath As String           'work Path
    Public WorkDir As String            'work directory
    
    'ini parameters
    Private Declare Function GetPrivateProfileString Lib "Kernel32" Alias "GetPrivateProfileStringA" (ByVal lpApplicationname As String, ByVal lpKeyname As String, ByVal lpDefault As String, ByVal lpReturnedString As String, ByVal nSize As Long, ByVal lpFileName As String) As Long
    Private Declare Function writeprivateprofilestring Lib "Kernel32" Alias "WritePrivateProfileStringA" (ByVal lpApplicationname As String, ByVal lpKeyname As String, ByVal lpString As Any, ByVal lpFileName As String) As Long
    
    
    
    Public Function ReadINI(FileName, Section, KeyName) As String
        Dim sRet As String
        sRet = String(2048, Chr(0))
        ReadINI = Left(sRet, GetPrivateProfileString(Section, ByVal KeyName, "", sRet, Len(sRet), FileName))
    End Function
    
    Public Function WriteINI(sFileName, sSection, sKeyName, ByVal sData As String) As String
        Dim R
        R = writeprivateprofilestring(sSection, sKeyName, sData, sFileName)
    End Function
    when i use the line below to write to the ini file nothing is in the file after running the code.

    Code:
       
    
     Call WriteINI(WorkPath & WorkDir & "\MediaFiles.ini", "general", "max", "0")
    what can be a reason that there is nothing in my file, i have looked around but found no sullution maybey you guys/girls can help me

    thnx

  2. #2
    Banned
    Join Date
    Aug 2022
    Posts
    97

    Re: can't write to network path ini file

    Code:
    Public Function WriteINI(sFileName, sSection, sKeyName, ByVal sData As String) As String
        Dim R
      
    Open App.Path & "\MediaFiles.ini" For Output As #1
    Print #1, sSection & " " & sKeyName  &  " "  &  sData & " " & sFileName
    Close #1
    
    End Function

  3. #3
    PowerPoster jdc2000's Avatar
    Join Date
    Oct 2001
    Location
    Idaho Falls, Idaho USA
    Posts
    2,159

    Re: can't write to network path ini file

    Can you read from the .ini file on the network drive? If yes, then it is likely a permissions issue, even though you have granted "Everyone" full access. Post the actual full path that you are using. Also, try granting access to the actual user that you are running the test under.

  4. #4
    PowerPoster
    Join Date
    Nov 2017
    Posts
    2,152

    Re: can't write to network path ini file

    There are permissions on the share, and then there are local file/folder level permissions. Most restrictive wins. So, if Everyone has full control on the share, but "Users" have only Read & Execute at the file/folder level, then they can't write to a file.

    Also, the concept of "Everyone" can be confusing. Assuming you are not part of an Active Directory domain, and just relying on local user credentials, if PC1 has an account with username "Bob" and some password, and PC2 has an account with username "Larry" and some password, "Larry" from PC2 still can't access content shared to "Everyone" on PC1 because PC1 has no knowledge of a user named "Larry". Even if they are both "Bob", but have different passwords, they still can't access the share.

    In this scenario, the easiest solution would be to create a new user on PC1 called "Larry" and assign the same password as is used by "Larry" on PC2, and then the remote connection from PC2 to PC1 by "Larry" will be allowed since it will come from a now recognized user account.

    At least, that is how it all used to work in previous versions of Windows. It is entirely possible that Microsoft has made changes in Windows 10/11 that make this all "easier" to do.

    Good luck.

  5. #5
    PowerPoster
    Join Date
    Nov 2017
    Posts
    2,152

    Re: can't write to network path ini file

    I forgot to add one thing. In a situation like this, always take a step back and remove any and all code from the equation.

    From the PC that you are running this code from, browse to the UNC Path or mapped drive in question, browse to the target folder, right-click inside the folder and try to create a new text file. If you get an error, then the code you are using is irrelevant, because there is an underlying permissions issue somewhere (see my post above). If you are allowed to create a new text file this way, then this would point to a potential issue with your code.

    Good luck.

  6. #6
    Hyperactive Member
    Join Date
    Nov 2011
    Posts
    345

    Re: can't write to network path ini file

    Quote Originally Posted by Jamie_vb6 View Post
    hello im trying to make a prog dat wil use a network drive on de drive is a ini file that has to be updated bij every user.

    i have a network folder maped to m:\ or \\media-pc\media both way's to acces.

    i have granted only user 'EVERYONE' full access

    my local file has the network path and contains:

    Code:
    [General]
    Name=Media Center
    Vers=3.1
    WorkPath=M:\
    WorkDir=MEDIA
    my vb6 project uses for ini the following:

    Code:
    Option Explicit
    'program parameters
    Public AppName As String            'Program name
    Public AppVer As String             'Program version
    Public WorkPath As String           'work Path
    Public WorkDir As String            'work directory
    
    'ini parameters
    Private Declare Function GetPrivateProfileString Lib "Kernel32" Alias "GetPrivateProfileStringA" (ByVal lpApplicationname As String, ByVal lpKeyname As String, ByVal lpDefault As String, ByVal lpReturnedString As String, ByVal nSize As Long, ByVal lpFileName As String) As Long
    Private Declare Function writeprivateprofilestring Lib "Kernel32" Alias "WritePrivateProfileStringA" (ByVal lpApplicationname As String, ByVal lpKeyname As String, ByVal lpString As Any, ByVal lpFileName As String) As Long
    
    
    
    Public Function ReadINI(FileName, Section, KeyName) As String
        Dim sRet As String
        sRet = String(2048, Chr(0))
        ReadINI = Left(sRet, GetPrivateProfileString(Section, ByVal KeyName, "", sRet, Len(sRet), FileName))
    End Function
    
    Public Function WriteINI(sFileName, sSection, sKeyName, ByVal sData As String) As String
        Dim R
        R = writeprivateprofilestring(sSection, sKeyName, sData, sFileName)
    End Function
    when i use the line below to write to the ini file nothing is in the file after running the code.

    Code:
       
    
     Call WriteINI(WorkPath & WorkDir & "\MediaFiles.ini", "general", "max", "0")
    what can be a reason that there is nothing in my file, i have looked around but found no sullution maybey you guys/girls can help me

    thnx
    just to check , what is in WorkPath and Workdir.. do they have '\' between them otherwise you might get C:\Folder1Folder2\MediaFiles.ini but should be C:\Folder1\Folder2\MediaFiles.ini

  7. #7
    Addicted Member
    Join Date
    Jan 2018
    Posts
    219

    Re: can't write to network path ini file

    When you say "nothing is in the file" do you mean that the old contents have been emptied out, or just that nothing changed? What if you delete the network file, does it get created?

  8. #8

    Thread Starter
    New Member
    Join Date
    Sep 2022
    Posts
    4

    Re: can't write to network path ini file

    hi tuffan thnx for this code,

    Code:
    Public Function WriteINI(sFileName, sSection, sKeyName, ByVal sData As String) As String
        Dim R
      
    Open sFileName For Output As #1
    Print #1, sSection & " " & sKeyName & " " & sData & " " & sFileName
    Close #1
    
    End Function
    i have tryed it and vb6 response with: Run-time errror 76

    PATH NOT FOUND.

    if i use with youre code the networking path \\media-pc\media\mediafiles.ini than i get:

    run-time error 52
    bad file name or number

    if have made a network connection to m: in my computer window and alawd reconnect always.

    what seems to be the problem, hope you can help me
    Last edited by Jamie_vb6; Sep 21st, 2022 at 12:28 PM.

  9. #9
    PowerPoster Arnoutdv's Avatar
    Join Date
    Oct 2013
    Posts
    5,420

    Re: can't write to network path ini file

    Start Notepad, enter some text and save it to \\media-pc\media\mediafiles.ini
    Does this work?

    If you also get access errors or whatever then there is nothing wrong with your code, but with the either an incorrect pathname or access rights on the share.
    Follow the steps provided by OptionBase1

  10. #10

    Thread Starter
    New Member
    Join Date
    Sep 2022
    Posts
    4

    Re: can't write to network path ini file

    Quote Originally Posted by Arnoutdv View Post
    Start Notepad, enter some text and save it to \\media-pc\media\mediafiles.ini
    Does this work?

    If you also get access errors or whatever then there is nothing wrong with your code, but with the either an incorrect pathname or access rights on the share.
    Follow the steps provided by OptionBase1
    i can save and change with notepad

  11. #11

    Thread Starter
    New Member
    Join Date
    Sep 2022
    Posts
    4

    Re: can't write to network path ini file

    Quote Originally Posted by OptionBase1 View Post
    There are permissions on the share, and then there are local file/folder level permissions. Most restrictive wins. So, if Everyone has full control on the share, but "Users" have only Read & Execute at the file/folder level, then they can't write to a file.

    Also, the concept of "Everyone" can be confusing. Assuming you are not part of an Active Directory domain, and just relying on local user credentials, if PC1 has an account with username "Bob" and some password, and PC2 has an account with username "Larry" and some password, "Larry" from PC2 still can't access content shared to "Everyone" on PC1 because PC1 has no knowledge of a user named "Larry". Even if they are both "Bob", but have different passwords, they still can't access the share.

    In this scenario, the easiest solution would be to create a new user on PC1 called "Larry" and assign the same password as is used by "Larry" on PC2, and then the remote connection from PC2 to PC1 by "Larry" will be allowed since it will come from a now recognized user account.

    At least, that is how it all used to work in previous versions of Windows. It is entirely possible that Microsoft has made changes in Windows 10/11 that make this all "easier" to do.

    Good luck.
    all users and system have full access i made sure of this

  12. #12
    PowerPoster
    Join Date
    Jun 2013
    Posts
    6,240

    Re: can't write to network path ini file

    Quote Originally Posted by Jamie_vb6 View Post
    i can save and change with notepad
    Then the same will be possible from your App ... when it is compiled!

    If - on the other hand - you still run your App from the IDE,
    then the IDEs process is working (usually) "elevated in Admin-Mode".

    And when in Admin-Mode, your "M:\" Network-Path-Drive-Mapping,
    is "not known" (did not happen yet).

    To make it work also in the IDE, you could ensure an explicite mapping via Code-Line -
    from within the Admin-elevated IDE-Process: (first line in Sub Main, or in Form_Load)
    Code:
      If App.LogMode = 0 Then 'we run in the IDE (the 2 lines below arer not executed when compiled)
          Shell "net use M: \\DEVICE-NAME-OR-IP\YOUR-SHARED-FOLDER"
          Sleep 1000 'give it some time to establish the NW-Drive-mapping
      End If
    
      '... before you proceed normally with your other, already existing Startup-Code
    HTH

    Olaf

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