473,395 Members | 1,670 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

CreateProcessAsUser, web form, Access denied error

I'm having a wierd issue trying to launch a robocopy process via a web
form. To cut a long story short, it works fine when I run it from the
server it is hosted on, but when I access the site from my own machine,
I get access denied errors.

Example on server 'wwwdeploy':
http://localhost/Deploy/default.aspx effectively runs this command:
robocopy \\wwwdeploy\wwwroot$\project\subfolder
\\wwwtest\drop\project\subfolder /S /Z

Example on my machine:
http://wwwdeploy/Deploy/default.aspx should run the same command:
robocopy \\wwwdeploy\wwwroot$\project\subfolder
\\wwwtest\drop\project\subfolder /S /Z

I can't figure out what sort of security I'm not getting right to allow
files to be copied to the destination (\\wwwtest). I have no access to
change permissions on this server, which is why I'm trying to
authenticate the robocopy process as myself. Any ideas from all you
clever people out there?

Here's the guts of the code I'm using:
public static string ExecuteRobocopy(string vRoot, CopyType copyType,
bool isImageCopy)
{
string destination;
string source;
MungeResourcePath(copyType, out destination, isImageCopy, out source,
vRoot);

_currentSourcePath = source;
Process proc = new Process();
string robocopyOutPut = string.Empty;
try
{
proc = InitialiseProcess(copyType, out robocopyOutPut, source,
destination);
robocopyOutPut = Regex.Replace(robocopyOutPut, "\t", " ");
}
catch (Exception ex)
{
string ipAddress =
HttpContext.Current.Request.ServerVariables["REMOTE_ADDRESS"];
string strError = String.Format("There was an error copying files
from: {0} to {1}. Error: '{2}'",
source, destination, ex.Message);
Logger.LogError(ipAddress, strError);
robocopyOutPut = strError;
}

return robocopyOutPut;
}

private static Process InitialiseProcess(CopyType copyType,
out string robocopyOutPut, string source, string destination)
{
Process proc = new Process();
robocopyOutPut = "You do not have access to robocopy.exe";

// security information, to launch process as a user
string domain = String.Empty;
string userName = String.Empty;
SecureString ssPassword = new SecureString();
string[] user = HttpContext.Current.User.Identity.Name.Split('\\') ;
domain = user[0];
userName = user[1];
string password = HttpContext.Current.Session["password"] as string;
foreach (char c in password)
{
ssPassword.AppendChar(c);
}

if (domain != String.Empty && userName != String.Empty &&
ssPassword.Length 0)
{
ProcessStartInfo procInfo = new ProcessStartInfo();

// parameters for process
procInfo.UseShellExecute = false;
procInfo.RedirectStandardInput = true;
procInfo.RedirectStandardOutput = true;
procInfo.RedirectStandardError = true;
procInfo.CreateNoWindow = true;
procInfo.FileName = "robocopy.exe"; // has to be in PATH as no
WorkingDirectory set
// security information
procInfo.Domain = domain;
procInfo.UserName = userName;
procInfo.Password = ssPassword;

//Get the arguments for our process
ProcessArgs procArgs = new ProcessArgs(copyType);

string strArgCopy = procArgs.CopyArgs;
string strArgFiles = procArgs.FilesList;
string strArgRetry = procArgs.RetryOptions;
string strArgLog = procArgs.LoggingOptions;

procInfo.Arguments =
String.Format("{0} {1} {2} {3} {4} {5}",
source, destination, strArgCopy, strArgFiles, strArgRetry,
strArgLog);
proc = Process.Start(procInfo);
proc.WaitForExit();

robocopyOutPut = proc.StandardOutput.ReadToEnd();
proc.Close();
}
return proc;
}

Jul 17 '06 #1
0 1686

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: Pete Fong | last post by:
Dear all, I am a beginner with Python. I want to write a program as "runas" in Windows XP. But I have got the following error: File...
3
by: Bo | last post by:
In my asp.net webservice application, I need to launch a DOS process as authorized users. To impersonate users, I use <impersonation = true> in my webconfig. I can't use Diagnostics.Process.Start,...
6
by: Dean R. Henderson | last post by:
I have a DTS Package I am able to execute successfully from a Windows Form application, but I cannot get this to work from an ASP.NET Web Service, although the Web Service impersonates the same...
1
by: Dean R. Henderson | last post by:
I have a Windows library that I bind into a Windows Form application and into an ASP.NET Web Application. I have a procedure in the library that executes a DTS Package. I have also used...
0
by: ASP.Confused | last post by:
The old message looked a little stale, so I am re-posting it here. Anybody have any ideas of what I could do?!? The previous responses to this question are below. If you want to look at the...
1
by: Jay | last post by:
Hey There, I am trying to execute the CreateProcessAsUser function, but when I do, I get this error: "Cannot create a file when that file already exists.". What would cause that error to occur in...
8
by: Jeremy Ames | last post by:
I am trying to move an application from my system to a new test system. I really should have tried an easier program first, but I didn't really have a chance. My application was originally written in...
0
by: EricBlair | last post by:
Hello, I wrote a windows service that is supposed to start an interactive GUI app. I realize a service will not readily do this so I've pieced together the code below to bypass that. However, the...
6
by: Tomino | last post by:
Hi, I am working on a log in form for an Access 2003 db. Because the built-in jet database engine doesn't supply the ability to record every log attempt, failed attempt, validate passwords, user...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.