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?
I just noticed you use a shared location...
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.
ASKER
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.SecureStri ng()
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\Easysy sUsageLog. exe"
End With
WriteLog.Start()
End Using
Catch ex As Exception
'error log failed to write
End Try
'write log file and add to user favorites
Try
Using SecurePassword As New System.Security.SecureStri
For Each c As Char In strAccountPassword
SecurePassword.AppendChar(
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\Easysy
End With
WriteLog.Start()
End Using
Catch ex As Exception
'error log failed to write
End Try
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
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.
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