Link to home
Start Free TrialLog in
Avatar of chadmanvb
chadmanvb

asked on

write file with alternate credentials with visual basic .net

I need to write log files, but the normal user does not have rights to this share.  Currently I call a console program under admin credentials to write the log files.  Is there a way I can just do that within my application?
Avatar of Ioannis Paraskevopoulos
Ioannis Paraskevopoulos
Flag of Greece image

Hi

Do you use a setup for installing your application?
You could use one if you don't and have it change permissions to a specific folder where you are writing your logs. After all the setup will take place by an administrator who may run the installation as an administrator.

Giannis
I just noticed you use a shared location...
Avatar of chadmanvb
chadmanvb

ASKER

Yep, it uses a file share on NAS.  My current console program is doing this fine, but I would prefer to not have to call another application to write the logs.
Here is how I call the console app, I was just hopping I could just write files within my appliction with the other user id.  It would also let me test that the log really got written to.  
  'write log file and add to user favorites
        Try


            Using SecurePassword As New System.Security.SecureString()

                For Each c As Char In strAccountPassword
                    SecurePassword.AppendChar(c)
                Next
                Dim WriteLog As New Process
                With WriteLog.StartInfo
                    .UseShellExecute = True
                    .UserName = "testid"
                    .Domain = "mydomain"
                    .Password = SecurePassword
                    .CreateNoWindow = True
                    .UseShellExecute = False
                    .Arguments = strAppUser & " " & strCommand
                    .FileName = "C:\Program Files\RemoteDeskTop\EasysysUsageLog.exe"
                End With

                WriteLog.Start()

            End Using



        Catch ex As Exception

            'error log failed to write
        End Try
ASKER CERTIFIED SOLUTION
Avatar of Nasir Razzaq
Nasir Razzaq
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Well, if this is Windows 7 and the issue it getting to write in "Admin" mode, you might consider a Windows service--I suppose. In that service it would have the rights or the user could set the service to run as administrator.