i've written a c# application to check if a repository should be dumper or not (using some paramenters)
I've compiled this application on my computer (Winsows 8) where it works as intended.
When i try to use it on two different windows server (2003 and 2008) with .net 4.5 installed, there is something wrong..
before that i talk about the problems i get i'll show you part of the code i made to make this app work:
output[2] = exec("svnadmin dump " + dir + " > " + dir + ".dump");
where dir is the actual name of the repository, the exec function is as follow:
public string exec(object command)
{
try
{
System.Diagnostics.ProcessStartInfo procStartInfo =
new System.Diagnostics.ProcessStartInfo("cmd", "/c " + command);
procStartInfo.RedirectStandardOutput = true;
procStartInfo.UseShellExecute = false;
procStartInfo.CreateNoWindow = true;
System.Diagnostics.Process proc = new System.Diagnostics.Process();
proc.StartInfo = procStartInfo;
proc.Start();
return proc.StandardOutput.ReadToEnd();
}
catch (Exception objException)
{
return "Error: " + objException;
}
}
what i get is that, when i run this on Windows 8, it works as intended
when i run this on Server 2003 it dumps only revision 0
when i run this on Server 2008 it returns an error (it is not a repository!)
Windows 8 svn version: 1.7.8 (sliksvn)
Windows server 2003 svn verion: 1.5.8
Windows server 2008 svn version: 1.7.9
any help is appreaciated,
thanks in advance
I had a similar problem with the "it is not a repository!" problem. To fix this, I used svnserve.
svnserve -r .\ -d
This fixed my problem.
Related
I am trying to check if windows server 2012 has IIS installed.
I am using following program in C#. It is working fine in windows 7 / 10 but giving error in windows server 2012.
public static String ExecutePoswershellScript(String filepath)
{
log.Info(filepath);
ProcessStartInfo startInfo = new ProcessStartInfo();
startInfo.FileName = "powershell.exe";
startInfo.Arguments = filepath;
startInfo.RedirectStandardOutput = true;
startInfo.RedirectStandardError = true;
startInfo.UseShellExecute = false;
startInfo.CreateNoWindow = true;
Process process = new Process();
process.StartInfo = startInfo;
process.Start();
string output = process.StandardOutput.ReadToEnd();
log.Info(output);
string err = process.StandardError.ReadToEnd();
if (err.Length>0)
{
log.Error(err);
}
// log.Info(output + "");
process.WaitForExit();
process.Close();
return output;
}
Error is as follows
Get-WindowsOptionalFeature : An attempt was made to load a program with an incorrect format.
At line:1 char:64
+ ... ocess; Import-Module Dism; Get-WindowsOptionalFeature -Online | where ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : NotSpecified: (:) [Get-WindowsOptionalFeature], CO
MException
+ FullyQualifiedErrorId : Microsoft.Dism.Commands.GetWindowsOptionalFeatureC
ommand
when I execute the command from powershell in windows server 2012 it works , only when I execute uing C# it fails
PowershellCommand
PowerShell version
Name Value
---- -----
PSVersion 5.0.10586.117
PSCompatibleVersions {1.0, 2.0, 3.0, 4.0...}
BuildVersion 10.0.10586.117
CLRVersion 4.0.30319.42000
WSManStackVersion 3.0
PSRemotingProtocolVersion 2.3
SerializationVersion 1.1.0.1
Please let me know if needs to be changed
On Desktops OSs use
Get-WindowsOptionalFeature -Online
On Servers OSs use
Get-WindowsFeature *IIS*
Open the IIS, right click on the applications application pool and go to "advanced settings" and change "Enable 32-Bit Applications" to "TRUE". Restart your website and it should work.
Or In Visual Studio, Right Click your project -> On the left pane click the Build tab, under Platform Target select x86.
I have integrated Sav32Cli.exe in my asp.net c# application & its working fine in my local machine but when we move it on the testing server I am getting the following error "Code 2 - If some error preventing further execution is discover "
The scenario is If only 1 person performs the activity it works fine but concurrent connection performs the same activity then I am getting this error for some connections.
Actual scenario : We have the page where users upload the pdf file & as soon as the file is uploaded on the server we perform the scanning via sop-hos and when multiple users perform the same activity I am getting the following error : Code 2 - If some error preventing further execution is discover. So I would like to know from you guys what should I do to bypass this error & implement the scanning successfully into my application.
Below is the code I have written to integrate the scanning into my application :
System.Diagnostics.Process process = new System.Diagnostics.Process();
System.Diagnostics.ProcessStartInfo startInfo = new System.Diagnostics.ProcessStartInfo();
try
{
string filePath = sFileDetails.DirectoryName + "\\" + sFileName;
startInfo.WindowStyle = System.Diagnostics.ProcessWindowStyle.Hidden;
startInfo.FileName = "C:\\Program Files (x86)\\Sophos\\Sophos Anti-Virus\\sav32cli.exe";
startInfo.Arguments = String.Format(#" -ss ""{0}""", filePath);
process.StartInfo = startInfo;
process.StartInfo.Verb = "runas";
process.StartInfo.RedirectStandardOutput = true;
process.StartInfo.UseShellExecute = false;
process.Start();
string output = process.StandardOutput.ReadToEnd();
StringBuilder objStrBuilder = new StringBuilder();
objStrBuilder.AppendLine("Status " + output.ToString());
int i = process.ExitCode;
objStrBuilder.AppendLine("Code " + i.ToString());
File.WriteAllText(sFileDetails.DirectoryName + "\\" + Convert.ToString(System.Guid.NewGuid()) + ".txt", Convert.ToString(objStrBuilder));
if (i > 0)
{
return false;
}
return true;
}
catch (Exception ex)
{
return false;
}
finally
{
process.Close();
process.Dispose();
}
Have you considered using SAVIDI for this - https://www.sophos.com/medialibrary/PDFs/partners/sophossavdidsna.ashx
SAV32CLI will take long time to load all the virus data into memory, I would expect around 5 seconds. This is fine when you're scanning your hard disk but per file it would be rather slow. If you're launching multiple instances then it would be quite a memory drain also.
If your throughput needs improving, I would suggest looking at SAVIDI. In this scenario there is service which loads the virus data once at startup and you can then ask it to scan a file/directory.
This post and attachment in the thread could help you:
https://community.sophos.com/products/endpoint-security-control/f/sophos-endpoint-software/9420/sophos-sav-di-icap-code-sample
Regards.
Sav32Cli.exe requires more permission to execute in web app. So impersonation technique helped me to solve this issue.
This link helped me to solve this issue : Click Here
I work on Setup application to install all requirement for my WPF product, one of the requirement is SQL Server 2012 Express, the code below is to install it after I generate the configuration file for silent installation :
private void SetupSQLServer()
{
string result = "";
string commandLine = "";
if (os64)
commandLine = string.Format(#"{0}\SQLServer\sql64\setup.exe PCUSOURCE={0}\SQLServer\sql64 /SAPWD=""p#ssw0rd"" /CONFIGURATIONFILE={0}\SQLServer\ConfigurationFile64.ini /HIDECONSOLE", setupFolder);
else
commandLine = string.Format(#"{0}\SQLServer\sql86\setup.exe PCUSOURCE={0}\SQLServer\sql86 /SAPWD=""p#ssw0rd"" /CONFIGURATIONFILE={0}\SQLServer\ConfigurationFile32.ini /HIDECONSOLE", setupFolder);
startInfo.WorkingDirectory = setupFolder;
startInfo.Arguments = "/c " + commandLine;
startInfo.RedirectStandardOutput = true;
startInfo.UseShellExecute = false;
process.StartInfo = startInfo;
try
{
process.Start();
}
catch (Exception e)
{
result = e.Message;
}
result = result + "\n" + process.StandardOutput.ReadToEnd();
UpdateStepResult(result);
}
There's no error in the code but it does not work .. when I run the code the command window appear and disappear and nothing happen.
UPDATE:
When I used:
fileName = string.Format(#"{0}\SQLServer\sql64\setup.exe", setupFolder);
The installation is run but without configuration file, when I used:
fileName = string.Format(#"{0}\SQLServer\sql64\setup.exe /CONFIGURATIONFILE={0}\SQLServer\sql64\ConfigurationFile64.ini", setupFolder);
It gives me this error "The system cannot find the file specified" !!!
The file is exist in the same folder !!
Please can you help me to discover the mistake.
Thanks in advance.
The ProcessStartInfo requires the FileName property to be valid. Your code above doesn't set it but pass everything as Arguments.
Probably you need to separate the command line in two parts. The Executable to run and the arguments to pass
if (os64)
{
fileName = string.Format("{0}\SQLServer\sql64\setup.exe", setupFolder);
commandLine = string.Format(#"PCUSOURCE={0}\SQLServer\sql64 /SAPWD=""p#ssw0rd"" /CONFIGURATIONFILE={0}\SQLServer\ConfigurationFile64.ini /HIDECONSOLE", setupFolder);
}
else
{
// Same for 32 bit
.....
}
....
startInfo.FileName = fileName;
....
So I am trying to automate the output from DxDiag in C# and I have run into a problem. The program runs but doesn't produce any output file. It might be that I am not passing parameters correctly or that I am misunderstanding something.
When running DxDiag in the normal command line I do this and it works as expected:
dxdiag -64bit -x C:\dxFromCode.xml
And this is how I am trying to do it in code:
//Create process
System.Diagnostics.Process pProcess = new System.Diagnostics.Process();
pProcess.StartInfo.FileName = "dxdiag";
pProcess.StartInfo.Arguments = #"64bit x C:\dxFromCode.xml";
pProcess.StartInfo.UseShellExecute = false;
//Set output of program to be written to process output stream
pProcess.StartInfo.RedirectStandardOutput = false;
//Start the process
pProcess.Start();
//Wait for process to finish
pProcess.WaitForExit();
EDIT:
Ok, so I changed my code to build for x64. This makes dxdiag automatically start the as the 64-bit version. Then I could just take away the 64bit switch and suddenly everything works as I would expect.
DxDiag is quite cranky on a 64-bit OS. The 32-bit version and the 64-bit version accept different command line switches and it doesn't give a peep when you use the wrong one. The /x option simply does not work when you try to use the /64bit option on the 32-bit version. And the 64-bit version does not accept /64bit. You'll have to start the 64-bit version explicitly when you run on a 64-bit OS and your program runs in 32-bit mode.
This worked well on my Win81 x64 machine:
private string RunDxDiag() {
var psi = new ProcessStartInfo();
if (IntPtr.Size == 4 && Environment.Is64BitOperatingSystem) {
// Need to run the 64-bit version
psi.FileName = System.IO.Path.Combine(
Environment.GetFolderPath(Environment.SpecialFolder.Windows),
"sysnative\\dxdiag.exe");
}
else {
// Okay with the native version
psi.FileName = System.IO.Path.Combine(
Environment.SystemDirectory,
"dxdiag.exe");
}
string path = System.IO.Path.GetTempFileName();
try {
psi.Arguments = "/x " + path;
using (var prc = Process.Start(psi)) {
prc.WaitForExit();
if (prc.ExitCode != 0) {
throw new Exception("DXDIAG failed with exit code " + prc.ExitCode.ToString());
}
}
return System.IO.File.ReadAllText(path);
}
finally {
System.IO.File.Delete(path);
}
}
Try adding /user:Administrator cmd /K to the arguments statement. Like this:
Arguments = "/user:Administrator \"cmd /K " + command + "\""
Command being 64bit x C:\dxFromCode.xml. I think your problem might be that you need to run cmd as Administrator.
Weirdly, Hans's code didn't work for me. I found that the WaitForExit() call would return before the file could be read. As a workaround, I added this:
int nTries = 0;
do
{
string szText = System.IO.File.ReadAllText(path);
if (szText.Length != 0)
{
return szText;
}
else
{
System.Threading.Thread.Sleep(1000);
}
} while (nTries++ < 10);
return "";
I'm trying to do a Drupal site install using Drush in C# as part of a full Windows Server site installation using MSI.
The Drush commmand I am using is the following one.
C:\ProgramData\Drush\Drush.bat -y si application_name --db-url=sqlsrv://admin_name:password(local)\SQLEXPRESS:/database_name --account-name=admin --account-mail=name#test.com --account-pass=Password1234 --site-mail="admin#company.com" --site-name="Site Name" install_configure_form.site_default_country=GB install_configure_form.date_default_timezone="Europe/London"
And this works perfectly when run from cmd.exe when in the working directory (inetpub\application_name).
The issue arises when the above is put into code and executed during an installation and always results in the following error (with a different file name each time).
Unable to decompress C:\ProgramData\Drush\lib\druFD63.tmp.gz
The C# code being used to execute the command is as follows:
public static ActionResult Drush_Configuration(Session session)
{
string strArgs = "-y si application_name --db-url=sqlsrv://admin_name:password(local)\SQLEXPRESS:/database_name --account-name=admin --account-mail=name#test.com --account-pass=Password1234 --site-mail="admin#company.com" --site-name="Site Name" install_configure_form.site_default_country=GB install_configure_form.date_default_timezone="Europe/London";
string strExeCmd = #"C:\ProgramData\Drush\Drush.bat ";
strExeCmd = strExeCmd + strArgs;
string strLocation = #"C:\inetpub\application_name";
session.Log("Starting Drush Configuration");
session.Log("Command line is: " + strExeCmd + " " + strArgs);
int exitCode;
ProcessStartInfo processInfo;
Process process;
try
{
processInfo = new ProcessStartInfo("cmd.exe", "/c " + strExeCmd);
processInfo.WorkingDirectory = strLocation;
processInfo.WindowStyle = ProcessWindowStyle.Normal;
processInfo.CreateNoWindow = true;
processInfo.UseShellExecute = false;
// *** Redirect the output ***
processInfo.RedirectStandardError = true;
processInfo.RedirectStandardOutput = true;
process = Process.Start(processInfo);
process.WaitForExit();
// *** Read the streams ***
string output = process.StandardOutput.ReadToEnd();
string error = process.StandardError.ReadToEnd();
exitCode = process.ExitCode;
session.Log("output>>" + (String.IsNullOrEmpty(output) ? "(none)" : output));
session.Log("error>>" + (String.IsNullOrEmpty(error) ? "(none)" : error));
session.Log("ExitCode: " + exitCode.ToString(), "ExecuteCommand");
process.Close();
}
catch (Exception e)
{
session.Log("Error: " + e);
return ActionResult.Failure;
}
session.Log("Drush Configuration completed successfully");
return ActionResult.Success;
}
And as stated above, this always results in the "unable to decompress" error.
Has anyone ever used c# to run Site-Install in Drush? Does anyone know why this might fail when executed in this way?
Any thoughts or advice would be greatly appreciated.
I am using Drush-5.8-2012-12-10-Installer-v1.0.20, Drupal 7, and Windows Server 2008 R2 x64.
The cause of this issue was the Environment Variables. The Drush MSI installer sets up User Path Environment Variables which are not recognized in an MSI machine context.
So, by adding System Path Variables for Drush, GnuWin32 and PHP to the site-install MSI the site can be programmatically installed.