0

When I try to start a file using different user privilege on c# it's always failed on "access is denied".

SecureString password = new SecureString();
password.AppendChar('n');
password.AppendChar('o');
password.AppendChar('a');
password.AppendChar('m');
password.AppendChar('p');
Process process = new Process();
process.StartInfo.UseShellExecute = false;
process.StartInfo.LoadUserProfile = true;
process.StartInfo.FileName = @"\\192.1.1.34\Noam\hanal.xlsx";
process.StartInfo.Domain = "dm";
process.StartInfo.UserName = "noamp";
process.StartInfo.Password = password;
process.StartInfo.Verb = "runas";
process.Start();

System.ComponentModel.Win32Exception HResult=0x80004005 Message=Access is denied. Source=System.Diagnostics.Process StackTrace: at System.Diagnostics.Process.StartWithCreateProcess(ProcessStartInfo startInfo) at System.Diagnostics.Process.Start() at DelekLinkV2.DisplayFiles.listView_DoubleClick(Object sender, EventArgs e) in C:\Users\tomerz\Desktop\PROGRAM\DelekLinkV2\DelekLinkV2\DisplayFiles.cs:line 78 at System.Windows.Forms.Control.OnDoubleClick(EventArgs e) at System.Windows.Forms.ListView.WndProc(Message& m) at System.Windows.Forms.NativeWindow.DebuggableCallback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam) at System.Windows.Forms.UnsafeNativeMethods.DispatchMessageW(MSG& msg) at System.Windows.Forms.Application.ComponentManager.System.Windows.Forms.UnsafeNativeMethods.IMsoComponentManager.FPushMessageLoop(IntPtr dwComponentID, Int32 reason, Int32 pvLoopData) at System.Windows.Forms.Application.ThreadContext.RunMessageLoopInner(Int32 reason, ApplicationContext context) at System.Windows.Forms.Application.ThreadContext.RunMessageLoop(Int32 reason, ApplicationContext context) at System.Windows.Forms.Application.Run(Form mainForm) at DelekLinkV2.Program.Main(String[] args) in C:\Users\tomerz\Desktop\PROGRAM\DelekLinkV2\DelekLinkV2\Program.cs:line 58

LarsTech
  • 80,625
  • 14
  • 153
  • 225
Noam
  • 1

0 Answers0